@arcjet/stable-hash 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +138 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
<!-- trunk-ignore-all(markdownlint/MD024) -->
|
|
2
|
+
<!-- trunk-ignore-all(markdownlint/MD001) -->
|
|
3
|
+
|
|
1
4
|
<a href="https://arcjet.com" target="_arcjet-home">
|
|
2
5
|
<picture>
|
|
3
6
|
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/logo/arcjet-dark-lockup-voyage-horizontal.svg">
|
|
@@ -42,7 +45,7 @@ Install with npm in Node.js:
|
|
|
42
45
|
npm install @arcjet/stable-hash
|
|
43
46
|
```
|
|
44
47
|
|
|
45
|
-
##
|
|
48
|
+
## Use
|
|
46
49
|
|
|
47
50
|
```ts
|
|
48
51
|
import * as hasher from "@arcjet/stable-hash";
|
|
@@ -59,6 +62,131 @@ console.log(id);
|
|
|
59
62
|
// => 49573b7df8d854c2cd5d8a755a4c03aff4014493a41b963490861a279ad675b2
|
|
60
63
|
```
|
|
61
64
|
|
|
65
|
+
## API
|
|
66
|
+
|
|
67
|
+
This package exports the identifiers
|
|
68
|
+
[`bool`][api-bool],
|
|
69
|
+
[`hash`][api-hash],
|
|
70
|
+
[`makeHasher`][api-make-hasher],
|
|
71
|
+
[`stringSliceOrdered`][api-string-slice-ordered],
|
|
72
|
+
[`string`][api-string], and
|
|
73
|
+
[`uint32`][api-uint32].
|
|
74
|
+
There is no default export.
|
|
75
|
+
|
|
76
|
+
This package exports the [TypeScript][] types
|
|
77
|
+
[`FieldHasher`][api-field-hasher] and
|
|
78
|
+
[`StringWriter`][api-string-writer].
|
|
79
|
+
|
|
80
|
+
### `FieldHasher`
|
|
81
|
+
|
|
82
|
+
This type represents a function that hashes a single field. You get one of
|
|
83
|
+
these back from `bool`, `string`, `stringSliceOrdered`, and `uint32`.
|
|
84
|
+
|
|
85
|
+
###### Type
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
type FieldHasher = (data: StringWriter) => void;
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### `StringWriter`
|
|
92
|
+
|
|
93
|
+
This type represents a writer that the hasher writes data into.
|
|
94
|
+
|
|
95
|
+
###### Fields
|
|
96
|
+
|
|
97
|
+
- `writeString(data: string): void`
|
|
98
|
+
— writes data to the hash
|
|
99
|
+
|
|
100
|
+
### `bool(key, value)`
|
|
101
|
+
|
|
102
|
+
Creates a field hasher for a boolean value.
|
|
103
|
+
|
|
104
|
+
###### Parameters
|
|
105
|
+
|
|
106
|
+
- `key` (`string`)
|
|
107
|
+
— the field name
|
|
108
|
+
- `value` (`boolean`)
|
|
109
|
+
— the boolean value to hash
|
|
110
|
+
|
|
111
|
+
###### Returns
|
|
112
|
+
|
|
113
|
+
A field hasher ([`FieldHasher`][api-field-hasher]).
|
|
114
|
+
|
|
115
|
+
### `hash(…hashers)`
|
|
116
|
+
|
|
117
|
+
Hashes multiple fields together and returns a stable hash string. You pass
|
|
118
|
+
in the field hashers created by `bool`, `string`, `stringSliceOrdered`, and
|
|
119
|
+
`uint32`.
|
|
120
|
+
|
|
121
|
+
###### Parameters
|
|
122
|
+
|
|
123
|
+
- `hashers` ([`Array<FieldHasher>`][api-field-hasher])
|
|
124
|
+
— the field hashers to combine
|
|
125
|
+
|
|
126
|
+
###### Returns
|
|
127
|
+
|
|
128
|
+
A `Promise` that resolves to the hash (`Promise<string>`).
|
|
129
|
+
|
|
130
|
+
### `makeHasher(subtle)`
|
|
131
|
+
|
|
132
|
+
Creates a new hash function using the provided `SubtleCrypto`
|
|
133
|
+
implementation. We use this internally to support different crypto
|
|
134
|
+
implementations across runtimes.
|
|
135
|
+
|
|
136
|
+
###### Parameters
|
|
137
|
+
|
|
138
|
+
- `subtle` (`SubtleCryptoLike`)
|
|
139
|
+
— a `SubtleCrypto`-like implementation
|
|
140
|
+
|
|
141
|
+
###### Returns
|
|
142
|
+
|
|
143
|
+
A hash function ([`hash`][api-hash]).
|
|
144
|
+
|
|
145
|
+
### `stringSliceOrdered(key, values)`
|
|
146
|
+
|
|
147
|
+
Creates a field hasher for an ordered array of strings.
|
|
148
|
+
|
|
149
|
+
###### Parameters
|
|
150
|
+
|
|
151
|
+
- `key` (`string`)
|
|
152
|
+
— the field name
|
|
153
|
+
- `values` (`ReadonlyArray<string>`)
|
|
154
|
+
— the string array to hash
|
|
155
|
+
|
|
156
|
+
###### Returns
|
|
157
|
+
|
|
158
|
+
A field hasher ([`FieldHasher`][api-field-hasher]).
|
|
159
|
+
|
|
160
|
+
### `string(key, value)`
|
|
161
|
+
|
|
162
|
+
Creates a field hasher for a string value.
|
|
163
|
+
|
|
164
|
+
###### Parameters
|
|
165
|
+
|
|
166
|
+
- `key` (`string`)
|
|
167
|
+
— the field name
|
|
168
|
+
- `value` (`string`)
|
|
169
|
+
— the string value to hash
|
|
170
|
+
|
|
171
|
+
###### Returns
|
|
172
|
+
|
|
173
|
+
A field hasher ([`FieldHasher`][api-field-hasher]).
|
|
174
|
+
|
|
175
|
+
### `uint32(key, value)`
|
|
176
|
+
|
|
177
|
+
Creates a field hasher for an unsigned 32-bit integer.
|
|
178
|
+
|
|
179
|
+
###### Parameters
|
|
180
|
+
|
|
181
|
+
- `key` (`string`)
|
|
182
|
+
— the field name
|
|
183
|
+
- `value` (`number`)
|
|
184
|
+
— the integer value to hash
|
|
185
|
+
|
|
186
|
+
###### Returns
|
|
187
|
+
|
|
188
|
+
A field hasher ([`FieldHasher`][api-field-hasher]).
|
|
189
|
+
|
|
62
190
|
## License
|
|
63
191
|
|
|
64
192
|
[Apache License, Version 2.0][apache-license] © [Arcjet Labs, Inc.][arcjet]
|
|
@@ -68,7 +196,16 @@ Derivative work based on [`feross/buffer`][github-buffer] licensed under
|
|
|
68
196
|
Our work picks its internal hex encoding logic adjusted for our use.
|
|
69
197
|
|
|
70
198
|
[apache-license]: http://www.apache.org/licenses/LICENSE-2.0
|
|
199
|
+
[api-bool]: #boolkey-value
|
|
200
|
+
[api-field-hasher]: #fieldhasher
|
|
201
|
+
[api-hash]: #hashhashers
|
|
202
|
+
[api-make-hasher]: #makehashersubtle
|
|
203
|
+
[api-string-slice-ordered]: #stringsliceorderedkey-value
|
|
204
|
+
[api-string-writer]: #stringwriter
|
|
205
|
+
[api-string]: #stringkey-value
|
|
206
|
+
[api-uint32]: #uint32key-value
|
|
71
207
|
[arcjet]: https://arcjet.com
|
|
72
208
|
[arcjet-get-started]: https://docs.arcjet.com/get-started
|
|
73
209
|
[github-buffer-license]: https://github.com/feross/buffer/blob/5857e295f4d37e3ad02c3abcbf7e8e5ef51f3be6/LICENSE
|
|
74
210
|
[github-buffer]: https://github.com/feross/buffer/tree/5857e295f4d37e3ad02c3abcbf7e8e5ef51f3be6
|
|
211
|
+
[typescript]: https://www.typescriptlang.org/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcjet/stable-hash",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Arcjet stable hashing utility",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"arcjet",
|
|
@@ -54,11 +54,11 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@arcjet/eslint-config": "1.
|
|
58
|
-
"@arcjet/rollup-config": "1.
|
|
59
|
-
"@rollup/wasm-node": "4.
|
|
57
|
+
"@arcjet/eslint-config": "1.3.1",
|
|
58
|
+
"@arcjet/rollup-config": "1.3.1",
|
|
59
|
+
"@rollup/wasm-node": "4.59.0",
|
|
60
60
|
"@types/node": "24.11.0",
|
|
61
|
-
"eslint": "9.39.
|
|
61
|
+
"eslint": "9.39.3",
|
|
62
62
|
"typescript": "5.9.3"
|
|
63
63
|
},
|
|
64
64
|
"publishConfig": {
|