From d6b294817095388489e97c3af311a3fe483572d0 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 16 Nov 2023 18:51:56 +0700 Subject: [PATCH] Minor tweaks --- .github/funding.yml | 4 ---- .github/workflows/main.yml | 6 ++++-- index.d.ts | 15 +++++++++++---- package.json | 2 ++ readme.md | 15 +++++++++++---- 5 files changed, 28 insertions(+), 14 deletions(-) delete mode 100644 .github/funding.yml diff --git a/.github/funding.yml b/.github/funding.yml deleted file mode 100644 index e202902..0000000 --- a/.github/funding.yml +++ /dev/null @@ -1,4 +0,0 @@ -github: sindresorhus -open_collective: sindresorhus -tidelift: npm/@sindresorhus/fnv1a -custom: https://sindresorhus.com/donate diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 441975c..a023591 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,10 +10,12 @@ jobs: fail-fast: false matrix: node-version: + - 20 + - 18 - 16 steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/index.d.ts b/index.d.ts index 13a0028..4d9397d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -14,6 +14,16 @@ export interface Options { The size of the array does not have to be large enugh to hold the entire string, but performance will be improved if it is. This option is only used when `value` is a string. + + @example + ``` + import fnv1a from '@sindresorhus/fnv1a'; + + const utf8Buffer = new Uint8Array(100); + + fnv1a('🦄🌈', {size: 32, utf8Buffer}); + //=> 2868248295n + ``` */ readonly utf8Buffer?: Uint8Array; } @@ -21,6 +31,7 @@ export interface Options { /** [FNV-1a](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function) non-cryptographic hash function. +@param value - A string or UTF-8 bytes. @returns The hash as a positive `BigInt`. @example @@ -36,10 +47,6 @@ fnv1a('🦄🌈', {size: 128}); Number(fnv1a('🦄🌈', {size: 32})); //=> 2868248295 -const utf8Buffer = new Uint8Array(100); -fnv1a('🦄🌈', {size: 32, utf8Buffer}); -//=> 2868248295n - const bytes = new Uint8Array([240, 159, 166, 132, 240, 159, 140, 136]); fnv1a(bytes, {size: 32}); //=> 2868248295n diff --git a/package.json b/package.json index 9bc6104..8c091b3 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,8 @@ }, "type": "module", "exports": "./index.js", + "types": "./index.d.ts", + "sideEffects": false, "engines": { "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, diff --git a/readme.md b/readme.md index ac47a6c..337ff8b 100644 --- a/readme.md +++ b/readme.md @@ -26,10 +26,6 @@ fnv1a('🦄🌈', {size: 128}); Number(fnv1a('🦄🌈', {size: 32})); //=> 2868248295 -const utf8Buffer = new Uint8Array(100); -fnv1a('🦄🌈', {size: 32, utf8Buffer}); -//=> 2868248295n - const bytes = new Uint8Array([240, 159, 166, 132, 240, 159, 140, 136]); fnv1a(bytes, {size: 32}); //=> 2868248295n @@ -47,6 +43,8 @@ If you need it as a `number`, use `32` as `size` and wrap the return value in `N Type: `string | Uint8Array` +A string or UTF-8 bytes. + #### options Type: `object` @@ -71,6 +69,15 @@ The size of the array does not have to be large enugh to hold the entire string, This option is only used when `value` is a string. +```js +import fnv1a from '@sindresorhus/fnv1a'; + +const utf8Buffer = new Uint8Array(100); + +fnv1a('🦄🌈', {size: 32, utf8Buffer}); +//=> 2868248295n +``` + ## Related - [djb2a](https://github.com/sindresorhus/djb2a) - DJB2a non-cryptographic hash function