Skip to content

Instantly share code, notes, and snippets.

@kettanaito
kettanaito / README.md
Last active March 30, 2026 19:32
Publishing to npm in 2026

Prerequisites

  • Use Node.js v24. Trusted Publishing does not work on earlier versions of Node.js.

Steps

  1. Go to "Account > Access Tokens" and click "Generate Access Token".
  2. Give the new token "read and write" persmissions to "All packages".
  3. If you have 2FA enabled on npm (which you should), check the "Bypass 2FA" checkbox neatly hidden in the UI. Otherwise, npm will fail with an error demanding an OTP during automatic publishing.
  4. Create the token.
@JacobWeisenburger
JacobWeisenburger / zustandCustomPersistStorageTemplate.ts
Created March 31, 2023 16:16
Zustand custom persist storage template
import { createStore } from 'zustand'
import { persist, StorageValue } from 'zustand/middleware'
const store = createStore(
persist(
() => ( {} ),
{
name: 'store-state',
storage: {
async getItem ( name: string ): StorageValue<unknown> {
@sonnylazuardi
sonnylazuardi / CounterReact.jsx
Created August 13, 2021 06:52
Astro React Vue. Global State Management: Zustand
import React from "react";
import { useStore } from "./store";
export default function CounterReact({ demo }) {
const state = useStore((state) => state);
let add = () => {
state.inc();
};
@sindresorhus
sindresorhus / esm-package.md
Last active March 30, 2026 18:10
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@adinan-cenci
adinan-cenci / _fetch-form.md
Last active August 7, 2025 08:18
How to follow upload progress with fetch()

How can we follow the upload progress with fetch() ?

Simple: We can't.
Not right now anyway, fetch() does not support that, but good old XMLHttpRequest does though.

The function below behaves much like fetch(), it will return a Promise that will resolve into a Response object.

Just pass a progress function in the options parameter.

@Talento90
Talento90 / thumbnail-generator.js
Created August 7, 2019 16:49
Generate Thumbnail from video using Node.js
"use strict";
const
ffmpegPath = require("@ffmpeg-installer/ffmpeg").path,
ffprobePath = require("@ffprobe-installer/ffprobe").path,
ffmpeg = require("fluent-ffmpeg");
ffmpeg.setFfprobePath(ffprobePath);
ffmpeg.setFfmpegPath(ffmpegPath);
@mofesolapaul
mofesolapaul / nigeria-states-and-local-govts.json
Last active October 29, 2025 22:17
Json array containing objects of each Nigerian state, and their local governments
[
{
"state": "Abia",
"lgas": [
"Aba North",
"Aba South",
"Arochukwu",
"Bende",
"Ikawuno",
"Ikwuano",