Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 16, 2023
1 parent edb1546 commit d6b2948
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
4 changes: 0 additions & 4 deletions .github/funding.yml

This file was deleted.

6 changes: 4 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@ 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;
}

/**
[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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
15 changes: 11 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`
Expand All @@ -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
Expand Down

0 comments on commit d6b2948

Please sign in to comment.