@tamagui/helpers 1.0.1-beta.141 → 1.0.1-beta.142

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.
@@ -18,20 +18,31 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var simpleHash_exports = {};
20
20
  __export(simpleHash_exports, {
21
+ isValidCSSCharCode: () => isValidCSSCharCode,
21
22
  simpleHash: () => simpleHash
22
23
  });
23
24
  module.exports = __toCommonJS(simpleHash_exports);
24
- const simpleHash = (str) => {
25
+ const simpleHash = (str, hashMin = 10) => {
25
26
  let hash = 0;
26
- for (let i = 0; i < str.length; i++) {
27
+ let valids = ``;
28
+ const len = str.length;
29
+ for (let i = 0; i < len; i++) {
27
30
  const char = str.charCodeAt(i);
28
- hash = (hash << 5) - hash + char;
29
- hash &= hash;
31
+ if (isValidCSSCharCode(char) && len <= hashMin) {
32
+ valids += str[i];
33
+ } else {
34
+ hash = (hash << 5) - hash + char;
35
+ hash &= hash;
36
+ }
30
37
  }
31
- return new Uint32Array([hash])[0].toString(36);
38
+ return valids + (hash ? new Uint32Array([hash])[0].toString(36) : "");
32
39
  };
40
+ function isValidCSSCharCode(code) {
41
+ return code >= 65 && code <= 90 || code >= 97 && code <= 122 || code == 95 || code === 45 || code >= 48 && code <= 57;
42
+ }
33
43
  // Annotate the CommonJS export names for ESM import in node:
34
44
  0 && (module.exports = {
45
+ isValidCSSCharCode,
35
46
  simpleHash
36
47
  });
37
48
  //# sourceMappingURL=simpleHash.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/simpleHash.ts"],
4
- "sourcesContent": ["export const simpleHash = (str: string) => {\n let hash = 0\n for (let i = 0; i < str.length; i++) {\n const char = str.charCodeAt(i)\n hash = (hash << 5) - hash + char\n hash &= hash // Convert to 32bit integer\n }\n return new Uint32Array([hash])[0].toString(36)\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,aAAa,CAAC,QAAgB;AACzC,MAAI,OAAO;AACX,WAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACnC,UAAM,OAAO,IAAI,WAAW,CAAC;AAC7B,WAAQ,SAAQ,KAAK,OAAO;AAC5B,YAAQ;AAAA,EACV;AACA,SAAO,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE;AAC/C;",
4
+ "sourcesContent": ["export const simpleHash = (str: string, hashMin = 10) => {\n let hash = 0\n let valids = ``\n const len = str.length\n for (let i = 0; i < len; i++) {\n const char = str.charCodeAt(i)\n // dont do more than 10 non-hashed to avoid getting too girthy\n if (isValidCSSCharCode(char) && len <= hashMin) {\n valids += str[i]\n } else {\n hash = (hash << 5) - hash + char\n hash &= hash // Convert to 32bit integer\n }\n }\n return valids + (hash ? new Uint32Array([hash])[0].toString(36) : '')\n}\n\nexport function isValidCSSCharCode(code: number) {\n return (\n // A-Z\n (code >= 65 && code <= 90) ||\n // a-z\n (code >= 97 && code <= 122) ||\n // _\n code == 95 ||\n // -\n code === 45 ||\n // 0-9\n (code >= 48 && code <= 57)\n )\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,aAAa,CAAC,KAAa,UAAU,OAAO;AACvD,MAAI,OAAO;AACX,MAAI,SAAS;AACb,QAAM,MAAM,IAAI;AAChB,WAAS,IAAI,GAAG,IAAI,KAAK,KAAK;AAC5B,UAAM,OAAO,IAAI,WAAW,CAAC;AAE7B,QAAI,mBAAmB,IAAI,KAAK,OAAO,SAAS;AAC9C,gBAAU,IAAI;AAAA,IAChB,OAAO;AACL,aAAQ,SAAQ,KAAK,OAAO;AAC5B,cAAQ;AAAA,IACV;AAAA,EACF;AACA,SAAO,SAAU,QAAO,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE,IAAI;AACpE;AAEO,4BAA4B,MAAc;AAC/C,SAEG,QAAQ,MAAM,QAAQ,MAEtB,QAAQ,MAAM,QAAQ,OAEvB,QAAQ,MAER,SAAS,MAER,QAAQ,MAAM,QAAQ;AAE3B;",
6
6
  "names": []
7
7
  }
@@ -1,13 +1,23 @@
1
- const simpleHash = (str) => {
1
+ const simpleHash = (str, hashMin = 10) => {
2
2
  let hash = 0;
3
- for (let i = 0; i < str.length; i++) {
3
+ let valids = ``;
4
+ const len = str.length;
5
+ for (let i = 0; i < len; i++) {
4
6
  const char = str.charCodeAt(i);
5
- hash = (hash << 5) - hash + char;
6
- hash &= hash;
7
+ if (isValidCSSCharCode(char) && len <= hashMin) {
8
+ valids += str[i];
9
+ } else {
10
+ hash = (hash << 5) - hash + char;
11
+ hash &= hash;
12
+ }
7
13
  }
8
- return new Uint32Array([hash])[0].toString(36);
14
+ return valids + (hash ? new Uint32Array([hash])[0].toString(36) : "");
9
15
  };
16
+ function isValidCSSCharCode(code) {
17
+ return code >= 65 && code <= 90 || code >= 97 && code <= 122 || code == 95 || code === 45 || code >= 48 && code <= 57;
18
+ }
10
19
  export {
20
+ isValidCSSCharCode,
11
21
  simpleHash
12
22
  };
13
23
  //# sourceMappingURL=simpleHash.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/simpleHash.ts"],
4
- "sourcesContent": ["export const simpleHash = (str: string) => {\n let hash = 0\n for (let i = 0; i < str.length; i++) {\n const char = str.charCodeAt(i)\n hash = (hash << 5) - hash + char\n hash &= hash // Convert to 32bit integer\n }\n return new Uint32Array([hash])[0].toString(36)\n}\n"],
5
- "mappings": "AAAO,MAAM,aAAa,CAAC,QAAgB;AACzC,MAAI,OAAO;AACX,WAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACnC,UAAM,OAAO,IAAI,WAAW,CAAC;AAC7B,WAAQ,SAAQ,KAAK,OAAO;AAC5B,YAAQ;AAAA,EACV;AACA,SAAO,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE;AAC/C;",
4
+ "sourcesContent": ["export const simpleHash = (str: string, hashMin = 10) => {\n let hash = 0\n let valids = ``\n const len = str.length\n for (let i = 0; i < len; i++) {\n const char = str.charCodeAt(i)\n // dont do more than 10 non-hashed to avoid getting too girthy\n if (isValidCSSCharCode(char) && len <= hashMin) {\n valids += str[i]\n } else {\n hash = (hash << 5) - hash + char\n hash &= hash // Convert to 32bit integer\n }\n }\n return valids + (hash ? new Uint32Array([hash])[0].toString(36) : '')\n}\n\nexport function isValidCSSCharCode(code: number) {\n return (\n // A-Z\n (code >= 65 && code <= 90) ||\n // a-z\n (code >= 97 && code <= 122) ||\n // _\n code == 95 ||\n // -\n code === 45 ||\n // 0-9\n (code >= 48 && code <= 57)\n )\n}\n"],
5
+ "mappings": "AAAO,MAAM,aAAa,CAAC,KAAa,UAAU,OAAO;AACvD,MAAI,OAAO;AACX,MAAI,SAAS;AACb,QAAM,MAAM,IAAI;AAChB,WAAS,IAAI,GAAG,IAAI,KAAK,KAAK;AAC5B,UAAM,OAAO,IAAI,WAAW,CAAC;AAE7B,QAAI,mBAAmB,IAAI,KAAK,OAAO,SAAS;AAC9C,gBAAU,IAAI;AAAA,IAChB,OAAO;AACL,aAAQ,SAAQ,KAAK,OAAO;AAC5B,cAAQ;AAAA,IACV;AAAA,EACF;AACA,SAAO,SAAU,QAAO,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE,IAAI;AACpE;AAEO,4BAA4B,MAAc;AAC/C,SAEG,QAAQ,MAAM,QAAQ,MAEtB,QAAQ,MAAM,QAAQ,OAEvB,QAAQ,MAER,SAAS,MAER,QAAQ,MAAM,QAAQ;AAE3B;",
6
6
  "names": []
7
7
  }
@@ -1,13 +1,23 @@
1
- const simpleHash = (str) => {
1
+ const simpleHash = (str, hashMin = 10) => {
2
2
  let hash = 0;
3
- for (let i = 0; i < str.length; i++) {
3
+ let valids = ``;
4
+ const len = str.length;
5
+ for (let i = 0; i < len; i++) {
4
6
  const char = str.charCodeAt(i);
5
- hash = (hash << 5) - hash + char;
6
- hash &= hash;
7
+ if (isValidCSSCharCode(char) && len <= hashMin) {
8
+ valids += str[i];
9
+ } else {
10
+ hash = (hash << 5) - hash + char;
11
+ hash &= hash;
12
+ }
7
13
  }
8
- return new Uint32Array([hash])[0].toString(36);
14
+ return valids + (hash ? new Uint32Array([hash])[0].toString(36) : "");
9
15
  };
16
+ function isValidCSSCharCode(code) {
17
+ return code >= 65 && code <= 90 || code >= 97 && code <= 122 || code == 95 || code === 45 || code >= 48 && code <= 57;
18
+ }
10
19
  export {
20
+ isValidCSSCharCode,
11
21
  simpleHash
12
22
  };
13
23
  //# sourceMappingURL=simpleHash.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/simpleHash.ts"],
4
- "sourcesContent": ["export const simpleHash = (str: string) => {\n let hash = 0\n for (let i = 0; i < str.length; i++) {\n const char = str.charCodeAt(i)\n hash = (hash << 5) - hash + char\n hash &= hash // Convert to 32bit integer\n }\n return new Uint32Array([hash])[0].toString(36)\n}\n"],
5
- "mappings": "AAAO,MAAM,aAAa,CAAC,QAAgB;AACzC,MAAI,OAAO;AACX,WAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACnC,UAAM,OAAO,IAAI,WAAW,CAAC;AAC7B,WAAQ,SAAQ,KAAK,OAAO;AAC5B,YAAQ;AAAA,EACV;AACA,SAAO,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE;AAC/C;",
4
+ "sourcesContent": ["export const simpleHash = (str: string, hashMin = 10) => {\n let hash = 0\n let valids = ``\n const len = str.length\n for (let i = 0; i < len; i++) {\n const char = str.charCodeAt(i)\n // dont do more than 10 non-hashed to avoid getting too girthy\n if (isValidCSSCharCode(char) && len <= hashMin) {\n valids += str[i]\n } else {\n hash = (hash << 5) - hash + char\n hash &= hash // Convert to 32bit integer\n }\n }\n return valids + (hash ? new Uint32Array([hash])[0].toString(36) : '')\n}\n\nexport function isValidCSSCharCode(code: number) {\n return (\n // A-Z\n (code >= 65 && code <= 90) ||\n // a-z\n (code >= 97 && code <= 122) ||\n // _\n code == 95 ||\n // -\n code === 45 ||\n // 0-9\n (code >= 48 && code <= 57)\n )\n}\n"],
5
+ "mappings": "AAAO,MAAM,aAAa,CAAC,KAAa,UAAU,OAAO;AACvD,MAAI,OAAO;AACX,MAAI,SAAS;AACb,QAAM,MAAM,IAAI;AAChB,WAAS,IAAI,GAAG,IAAI,KAAK,KAAK;AAC5B,UAAM,OAAO,IAAI,WAAW,CAAC;AAE7B,QAAI,mBAAmB,IAAI,KAAK,OAAO,SAAS;AAC9C,gBAAU,IAAI;AAAA,IAChB,OAAO;AACL,aAAQ,SAAQ,KAAK,OAAO;AAC5B,cAAQ;AAAA,IACV;AAAA,EACF;AACA,SAAO,SAAU,QAAO,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE,IAAI;AACpE;AAEO,4BAA4B,MAAc;AAC/C,SAEG,QAAQ,MAAM,QAAQ,MAEtB,QAAQ,MAAM,QAAQ,OAEvB,QAAQ,MAER,SAAS,MAER,QAAQ,MAAM,QAAQ;AAE3B;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/helpers",
3
- "version": "1.0.1-beta.141",
3
+ "version": "1.0.1-beta.142",
4
4
  "source": "src/index.ts",
5
5
  "types": "./types/index.d.ts",
6
6
  "main": "dist/cjs",
@@ -20,7 +20,7 @@
20
20
  "clean:build": "tamagui-build clean:build"
21
21
  },
22
22
  "devDependencies": {
23
- "@tamagui/build": "^1.0.1-beta.141",
23
+ "@tamagui/build": "^1.0.1-beta.142",
24
24
  "react": "*",
25
25
  "react-native": "*"
26
26
  },
@@ -31,5 +31,12 @@
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
+ "exports": {
35
+ "./package.json": "./package.json",
36
+ ".": {
37
+ "import": "./dist/esm/index.js",
38
+ "require": "./dist/cjs/index.js"
39
+ }
40
+ },
34
41
  "gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14"
35
42
  }
package/src/simpleHash.ts CHANGED
@@ -1,9 +1,31 @@
1
- export const simpleHash = (str: string) => {
1
+ export const simpleHash = (str: string, hashMin = 10) => {
2
2
  let hash = 0
3
- for (let i = 0; i < str.length; i++) {
3
+ let valids = ``
4
+ const len = str.length
5
+ for (let i = 0; i < len; i++) {
4
6
  const char = str.charCodeAt(i)
5
- hash = (hash << 5) - hash + char
6
- hash &= hash // Convert to 32bit integer
7
+ // dont do more than 10 non-hashed to avoid getting too girthy
8
+ if (isValidCSSCharCode(char) && len <= hashMin) {
9
+ valids += str[i]
10
+ } else {
11
+ hash = (hash << 5) - hash + char
12
+ hash &= hash // Convert to 32bit integer
13
+ }
7
14
  }
8
- return new Uint32Array([hash])[0].toString(36)
15
+ return valids + (hash ? new Uint32Array([hash])[0].toString(36) : '')
16
+ }
17
+
18
+ export function isValidCSSCharCode(code: number) {
19
+ return (
20
+ // A-Z
21
+ (code >= 65 && code <= 90) ||
22
+ // a-z
23
+ (code >= 97 && code <= 122) ||
24
+ // _
25
+ code == 95 ||
26
+ // -
27
+ code === 45 ||
28
+ // 0-9
29
+ (code >= 48 && code <= 57)
30
+ )
9
31
  }
@@ -1,2 +1,3 @@
1
- export declare const simpleHash: (str: string) => string;
1
+ export declare const simpleHash: (str: string, hashMin?: number) => string;
2
+ export declare function isValidCSSCharCode(code: number): boolean;
2
3
  //# sourceMappingURL=simpleHash.d.ts.map