smolcanon 0.1.0
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/CHANGELOG.md +13 -0
- package/LICENSE.md +9 -0
- package/README.md +38 -0
- package/index.cjs +25 -0
- package/index.d.cts +11 -0
- package/index.d.ts +11 -0
- package/index.js +22 -0
- package/package.json +59 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
This project adheres to [Semantic Versioning].
|
|
5
|
+
|
|
6
|
+
This change log follows the format documented in [Keep a CHANGELOG].
|
|
7
|
+
|
|
8
|
+
[semantic versioning]: http://semver.org/
|
|
9
|
+
[keep a changelog]: http://keepachangelog.com/
|
|
10
|
+
|
|
11
|
+
## v0.1.0 - 2025-08-17
|
|
12
|
+
|
|
13
|
+
Initial version
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright © 2025 Sasha Koss
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Smol xxHash
|
|
2
|
+
|
|
3
|
+
Tiny [xxHash](https://xxhash.com/) JS implementation.
|
|
4
|
+
|
|
5
|
+
It is a modern, faster and smaller alternative to [xxhashjs](https://www.npmjs.com/package/xxhashjs) package. It is 3.8x faster and fits in just `381B`.
|
|
6
|
+
|
|
7
|
+
It is just 1.8x slower than [xxhash-wasm](https://www.npmjs.com/package/xxhash-wasm) package.
|
|
8
|
+
|
|
9
|
+
It features dual CJS/ESM support and built-in TypeScript definitions.
|
|
10
|
+
|
|
11
|
+
It is based on [a reference C implementation](https://github.com/easyaspi314/xxhash-clean/blob/86a04ab3f01277049a23f6c9e2c4a6c174ff50c4/xxhash32-ref.c)
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
The package is available on npm:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install smolxxh
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
Pass `Buffer` or `Uint8Array` to `xxh32` function to get the hash of the content:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { xxh32 } from "smolxxh";
|
|
27
|
+
|
|
28
|
+
xxh32(Buffer.from("hello world", "utf8")).toString(16);
|
|
29
|
+
// => 0x31b7405d
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Changelog
|
|
33
|
+
|
|
34
|
+
See [the changelog](./CHANGELOG.md).
|
|
35
|
+
|
|
36
|
+
## License
|
|
37
|
+
|
|
38
|
+
[MIT © Sasha Koss](https://koss.nocorp.me/mit/)
|
package/index.cjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.canonize = canonize;
|
|
4
|
+
/**
|
|
5
|
+
* Canonicalizes the input value as a string to use for hashing. It sorts keys,
|
|
6
|
+
* making sure deeply equal objects produce the same string.
|
|
7
|
+
*
|
|
8
|
+
* This version doesn't handle any instance types, such as custom classes, Date,
|
|
9
|
+
* Map, Set, etc.
|
|
10
|
+
*
|
|
11
|
+
* @param input - The value to canonicalize.
|
|
12
|
+
* @returns The canonicalized string representation of the input.
|
|
13
|
+
*/
|
|
14
|
+
function canonize(input) {
|
|
15
|
+
if (typeof input !== "object" || !input) {
|
|
16
|
+
if (Object.is(input, -0)) return "-0";
|
|
17
|
+
if (typeof input === "string") return JSON.stringify(input);
|
|
18
|
+
return String(input);
|
|
19
|
+
}
|
|
20
|
+
let canon = "";
|
|
21
|
+
for (const key of Object.keys(input).sort()) {
|
|
22
|
+
canon += `${key}:${canonize(input[key])};`;
|
|
23
|
+
}
|
|
24
|
+
return Array.isArray(input) ? `[${canon}]` : `{${canon}}`;
|
|
25
|
+
}
|
package/index.d.cts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonicalizes the input value as a string to use for hashing. It sorts keys,
|
|
3
|
+
* making sure deeply equal objects produce the same string.
|
|
4
|
+
*
|
|
5
|
+
* This version doesn't handle any instance types, such as custom classes, Date,
|
|
6
|
+
* Map, Set, etc.
|
|
7
|
+
*
|
|
8
|
+
* @param input - The value to canonicalize.
|
|
9
|
+
* @returns The canonicalized string representation of the input.
|
|
10
|
+
*/
|
|
11
|
+
export declare function canonize(input: unknown): string;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonicalizes the input value as a string to use for hashing. It sorts keys,
|
|
3
|
+
* making sure deeply equal objects produce the same string.
|
|
4
|
+
*
|
|
5
|
+
* This version doesn't handle any instance types, such as custom classes, Date,
|
|
6
|
+
* Map, Set, etc.
|
|
7
|
+
*
|
|
8
|
+
* @param input - The value to canonicalize.
|
|
9
|
+
* @returns The canonicalized string representation of the input.
|
|
10
|
+
*/
|
|
11
|
+
export declare function canonize(input: unknown): string;
|
package/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonicalizes the input value as a string to use for hashing. It sorts keys,
|
|
3
|
+
* making sure deeply equal objects produce the same string.
|
|
4
|
+
*
|
|
5
|
+
* This version doesn't handle any instance types, such as custom classes, Date,
|
|
6
|
+
* Map, Set, etc.
|
|
7
|
+
*
|
|
8
|
+
* @param input - The value to canonicalize.
|
|
9
|
+
* @returns The canonicalized string representation of the input.
|
|
10
|
+
*/
|
|
11
|
+
export function canonize(input) {
|
|
12
|
+
if (typeof input !== "object" || !input) {
|
|
13
|
+
if (Object.is(input, -0)) return "-0";
|
|
14
|
+
if (typeof input === "string") return JSON.stringify(input);
|
|
15
|
+
return String(input);
|
|
16
|
+
}
|
|
17
|
+
let canon = "";
|
|
18
|
+
for (const key of Object.keys(input).sort()) {
|
|
19
|
+
canon += `${key}:${canonize(input[key])};`;
|
|
20
|
+
}
|
|
21
|
+
return Array.isArray(input) ? `[${canon}]` : `{${canon}}`;
|
|
22
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "smolcanon",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Tiny JS objects canonicalization for hashing",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.cjs",
|
|
7
|
+
"module": "index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./package.json": "./package.json",
|
|
10
|
+
".": {
|
|
11
|
+
"require": {
|
|
12
|
+
"types": "./index.d.cts",
|
|
13
|
+
"default": "./index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./index.d.ts",
|
|
17
|
+
"default": "./index.js"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/kossnocorp/smolcanon.git"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"tiny",
|
|
27
|
+
"hashing",
|
|
28
|
+
"canonicalization",
|
|
29
|
+
"serialization"
|
|
30
|
+
],
|
|
31
|
+
"author": "Sasha Koss <koss@nocorp.me>",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/kossnocorp/smolcanon/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/kossnocorp/smolcanon#readme",
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@arethetypeswrong/cli": "^0.16.4",
|
|
39
|
+
"@babel/cli": "^7.28.3",
|
|
40
|
+
"@babel/core": "^7.28.3",
|
|
41
|
+
"@babel/plugin-transform-modules-commonjs": "^7.27.1",
|
|
42
|
+
"@babel/preset-env": "^7.28.3",
|
|
43
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
44
|
+
"@parcel/watcher": "^2.5.1",
|
|
45
|
+
"@swc/core": "^1.13.3",
|
|
46
|
+
"@types/xxhashjs": "^0.2.4",
|
|
47
|
+
"babel-plugin-replace-import-extension": "^1.1.5",
|
|
48
|
+
"bytes-iec": "^3.1.1",
|
|
49
|
+
"glob": "^10.4.5",
|
|
50
|
+
"minimatch": "^10.0.3",
|
|
51
|
+
"picocolors": "^1.1.1",
|
|
52
|
+
"tsx": "^4.20.4",
|
|
53
|
+
"typescript": "^5.9.2",
|
|
54
|
+
"vitest": "^1.6.1"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"test": "vitest run"
|
|
58
|
+
}
|
|
59
|
+
}
|