@mochi-css/core 3.0.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/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # 🧁 Mochi-CSS/core
2
+
3
+ This package is part of the [Mochi-CSS project](https://github.com/Niikelion/mochi-css).
4
+ It provides shared low-level utilities used across Mochi-CSS packages.
5
+
6
+ > **Note:** This is an internal package. You do not need to install it directly — it is a transitive dependency of `@mochi-css/vanilla` and `@mochi-css/builder`.
7
+
8
+ ---
9
+
10
+ ## API
11
+
12
+ ### `shortHash(input: string): string`
13
+
14
+ Returns a short URL-safe base-62 hash of the input string. Used internally for generating stable class name suffixes and file hashes.
15
+
16
+ ### `numberToBase62(n: number): string`
17
+
18
+ Converts a non-negative integer to a base-62 string (`[0-9A-Za-z]`).
@@ -0,0 +1,5 @@
1
+ //#region src/hash.d.ts
2
+ declare function numberToBase62(num: number, maxLength?: number): string;
3
+ declare function shortHash(input: string, length?: number): string;
4
+ //#endregion
5
+ export { numberToBase62, shortHash };
@@ -0,0 +1,5 @@
1
+ //#region src/hash.d.ts
2
+ declare function numberToBase62(num: number, maxLength?: number): string;
3
+ declare function shortHash(input: string, length?: number): string;
4
+ //#endregion
5
+ export { numberToBase62, shortHash };
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+
2
+ //#region src/hash.ts
3
+ const hashBase = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_";
4
+ const base = 64;
5
+ function numberToBase62(num, maxLength) {
6
+ let out = "";
7
+ while (num > 0 && out.length < (maxLength ?? Infinity)) {
8
+ out = hashBase[num % base] + out;
9
+ num = Math.floor(num / base);
10
+ }
11
+ return out.length > 0 ? out : "0";
12
+ }
13
+ function shortHash(input, length = 8) {
14
+ let h = 5381;
15
+ for (let i = 0; i < input.length; i++) h = h * 33 ^ input.charCodeAt(i);
16
+ h >>>= 0;
17
+ return numberToBase62(h, length);
18
+ }
19
+
20
+ //#endregion
21
+ exports.numberToBase62 = numberToBase62;
22
+ exports.shortHash = shortHash;
package/dist/index.mjs ADDED
@@ -0,0 +1,20 @@
1
+ //#region src/hash.ts
2
+ const hashBase = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_";
3
+ const base = 64;
4
+ function numberToBase62(num, maxLength) {
5
+ let out = "";
6
+ while (num > 0 && out.length < (maxLength ?? Infinity)) {
7
+ out = hashBase[num % base] + out;
8
+ num = Math.floor(num / base);
9
+ }
10
+ return out.length > 0 ? out : "0";
11
+ }
12
+ function shortHash(input, length = 8) {
13
+ let h = 5381;
14
+ for (let i = 0; i < input.length; i++) h = h * 33 ^ input.charCodeAt(i);
15
+ h >>>= 0;
16
+ return numberToBase62(h, length);
17
+ }
18
+
19
+ //#endregion
20
+ export { numberToBase62, shortHash };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@mochi-css/core",
3
+ "repository": "git@github.com:Niikelion/mochi-css.git",
4
+ "version": "3.0.0",
5
+ "license": "MIT",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.mjs",
8
+ "types": "dist/index.d.ts",
9
+ "files": [
10
+ "/dist"
11
+ ],
12
+ "exports": {
13
+ "import": {
14
+ "types": "./dist/index.d.mts",
15
+ "import": "./dist/index.mjs"
16
+ },
17
+ "require": {
18
+ "types": "./dist/index.d.ts",
19
+ "require": "./dist/index.js"
20
+ }
21
+ },
22
+ "scripts": {
23
+ "build": "tsc --noEmit && tsdown",
24
+ "lint": "eslint src",
25
+ "lint:fix": "eslint src --fix",
26
+ "format": "prettier --write ."
27
+ },
28
+ "devDependencies": {
29
+ "@gamedev-sensei/ts-config": "^2.1.0",
30
+ "@gamedev-sensei/tsdown-config": "^2.1.0",
31
+ "@mochi-css/shared-config": "^2.0.0",
32
+ "@types/node": "^24.8.1",
33
+ "eslint": "^9.39.2",
34
+ "prettier": "^3.8.1",
35
+ "typescript": "^5.9.3"
36
+ }
37
+ }