@valkyriestudios/utils 12.46.0 → 12.48.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/cjs/array/join.js CHANGED
@@ -4,7 +4,7 @@ exports.join = join;
4
4
  exports.default = join;
5
5
  const round_1 = require("../number/round");
6
6
  const isIntegerAboveOrEqual_1 = require("../number/isIntegerAboveOrEqual");
7
- const SPACE_RGX = /(\s)+/g;
7
+ const SPACE_RGX = /\s+/g;
8
8
  function join(val, opts) {
9
9
  let normalized;
10
10
  if (Array.isArray(val)) {
package/cjs/date/diff.js CHANGED
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.diff = diff;
4
4
  exports.default = diff;
5
5
  const convertToDate_1 = require("./convertToDate");
6
- const SECOND_IN_MILLISECONDS = 1000;
7
- const MINUTE_IN_MILLISECONDS = SECOND_IN_MILLISECONDS * 60;
8
- const HOUR_IN_MILLISECONDS = MINUTE_IN_MILLISECONDS * 60;
9
- const DAY_IN_MILLISECONDS = HOUR_IN_MILLISECONDS * 24;
10
- const WEEK_IN_MILLISECONDS = DAY_IN_MILLISECONDS * 7;
6
+ const INV_SECOND_IN_MILLISECONDS = 1.0 / 1000;
7
+ const INV_MINUTE_IN_MILLISECONDS = 1.0 / (60 * 1000);
8
+ const INV_HOUR_IN_MILLISECONDS = 1.0 / (60 * 60 * 1000);
9
+ const INV_DAY_IN_MILLISECONDS = 1.0 / (24 * 60 * 60 * 1000);
10
+ const INV_WEEK_IN_MILLISECONDS = 1.0 / (7 * 24 * 60 * 60 * 1000);
11
11
  function diff(val_a, val_b, key = 'millisecond') {
12
12
  const n_val_a = (0, convertToDate_1.convertToDate)(val_a);
13
13
  const n_val_b = (0, convertToDate_1.convertToDate)(val_b);
@@ -18,19 +18,19 @@ function diff(val_a, val_b, key = 'millisecond') {
18
18
  switch (key) {
19
19
  case 'week':
20
20
  case 'weeks':
21
- return diff_in_ms / WEEK_IN_MILLISECONDS;
21
+ return diff_in_ms * INV_WEEK_IN_MILLISECONDS;
22
22
  case 'day':
23
23
  case 'days':
24
- return diff_in_ms / DAY_IN_MILLISECONDS;
24
+ return diff_in_ms * INV_DAY_IN_MILLISECONDS;
25
25
  case 'hour':
26
26
  case 'hours':
27
- return diff_in_ms / HOUR_IN_MILLISECONDS;
27
+ return diff_in_ms * INV_HOUR_IN_MILLISECONDS;
28
28
  case 'minute':
29
29
  case 'minutes':
30
- return diff_in_ms / MINUTE_IN_MILLISECONDS;
30
+ return diff_in_ms * INV_MINUTE_IN_MILLISECONDS;
31
31
  case 'second':
32
32
  case 'seconds':
33
- return diff_in_ms / SECOND_IN_MILLISECONDS;
33
+ return diff_in_ms * INV_SECOND_IN_MILLISECONDS;
34
34
  default:
35
35
  return diff_in_ms;
36
36
  }
@@ -16,7 +16,7 @@ const WEEK_STARTS = {
16
16
  let DEFAULT_LOCALE = 'en-US';
17
17
  let DEFAULT_TZ = Intl?.DateTimeFormat?.().resolvedOptions?.().timeZone || 'UTC';
18
18
  let DEFAULT_SOW = 'mon';
19
- const ESCAPE_RGX = /\[[\s\S]+?]/g;
19
+ const ESCAPE_RGX = /\[([^\]]*)]/g;
20
20
  const intl_formatters = new LRU_1.default({ max_size: 100 });
21
21
  const spec_cache = new LRU_1.default({ max_size: 100 });
22
22
  const zone_offset_cache = new LRU_1.default({ max_size: 100 });
@@ -138,6 +138,10 @@ const Tokens = [
138
138
  ]
139
139
  .map(el => [el[0], el[1], el[0].length])
140
140
  .sort((a, b) => a[0].length > b[0].length ? -1 : 1);
141
+ const token_map = {};
142
+ for (const t of Tokens)
143
+ token_map[t[0]] = t;
144
+ const TOKENS_RGX = new RegExp(Tokens.map(([tok]) => tok).join('|'), 'g');
141
145
  function getSpecChain(spec) {
142
146
  const cached = spec_cache.get(spec);
143
147
  if (cached !== undefined)
@@ -146,30 +150,29 @@ function getSpecChain(spec) {
146
150
  const repl = [];
147
151
  let repl_len = 0;
148
152
  if (base.indexOf('[') >= 0) {
149
- base = base.replace(ESCAPE_RGX, match => {
153
+ base = base.replace(ESCAPE_RGX, (_, inner) => {
150
154
  const escape_token = '$' + repl_len++ + '$';
151
- repl.push([escape_token, match.slice(1, -1)]);
155
+ repl.push([escape_token, inner]);
152
156
  return escape_token;
153
157
  });
154
158
  }
155
- const chain = [];
156
- const matched_positions = new Set();
157
- for (let i = 0; i < Tokens.length; i++) {
158
- const [token] = Tokens[i];
159
- let pos = base.indexOf(token);
160
- const token_len = token.length;
161
- while (pos !== -1) {
162
- if (!matched_positions.has(pos)) {
163
- chain.push(Tokens[i]);
164
- for (let j = 0; j < token_len; j++) {
165
- matched_positions.add(pos + j);
166
- }
167
- }
168
- pos = base.indexOf(token, pos + 1);
159
+ TOKENS_RGX.lastIndex = 0;
160
+ const parts = [];
161
+ let last_idx = 0;
162
+ let has_token = false;
163
+ let m;
164
+ while (m = TOKENS_RGX.exec(base)) {
165
+ if (m.index > last_idx) {
166
+ parts.push({ literal: base.slice(last_idx, m.index) });
169
167
  }
168
+ parts.push({ token: token_map[m[0]] });
169
+ has_token = true;
170
+ last_idx = m.index + m[0].length;
170
171
  }
171
- const chain_len = chain.length;
172
- const result = chain_len ? { base, chain, chain_len, repl } : null;
172
+ if (last_idx < base.length) {
173
+ parts.push({ literal: base.slice(last_idx) });
174
+ }
175
+ const result = has_token ? { parts, repl } : null;
173
176
  spec_cache.set(spec, result);
174
177
  return result;
175
178
  }
@@ -190,24 +193,22 @@ function format(val, spec, locale = DEFAULT_LOCALE, zone = DEFAULT_TZ, sow = DEF
190
193
  if (!n_spec)
191
194
  return n_val.toISOString();
192
195
  const d = toZone(n_val, zone);
193
- let base = n_spec.base;
194
- const repl = [...n_spec.repl];
195
- let repl_len = n_spec.repl.length;
196
- for (let i = 0; i < n_spec.chain_len; i++) {
197
- const el = n_spec.chain[i];
198
- let pos = base.indexOf(el[0]);
199
- const token_val = el[1](d, locale, sow);
200
- while (pos !== -1) {
201
- const key = '$' + repl_len++ + '$';
202
- repl.push([key, token_val]);
203
- base = base.slice(0, pos) + key + base.slice(pos + el[2]);
204
- pos = base.indexOf(el[0], pos + el[2]);
196
+ const { parts, repl } = n_spec;
197
+ let out = '';
198
+ for (let i = 0; i < parts.length; i++) {
199
+ const part = parts[i];
200
+ if ('literal' in part) {
201
+ out += part.literal;
202
+ }
203
+ else {
204
+ out += part.token[1](d, locale, sow);
205
205
  }
206
206
  }
207
- for (let i = 0; i < repl_len; i++) {
208
- base = base.replace(repl[i][0], repl[i][1]);
207
+ let result = out;
208
+ for (let i = 0; i < repl.length; i++) {
209
+ result = result.replace(repl[i][0], repl[i][1]);
209
210
  }
210
- return base;
211
+ return result;
211
212
  }
212
213
  format.getLocale = function () {
213
214
  return DEFAULT_LOCALE;
package/cjs/deep/get.js CHANGED
@@ -3,87 +3,61 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deepGet = deepGet;
4
4
  exports.default = deepGet;
5
5
  function deepGet(obj, path, get_parent = false) {
6
- if (Object.prototype.toString.call(obj) !== '[object Object]' &&
7
- !Array.isArray(obj))
6
+ if (Object.prototype.toString.call(obj) !== '[object Object]' && !Array.isArray(obj)) {
8
7
  throw new TypeError('deepGet: Requires object or array');
9
- if (typeof path !== 'string' ||
10
- !path.length)
8
+ }
9
+ if (!path || typeof path !== 'string') {
11
10
  throw new TypeError('deepGet: Invalid path provided');
12
- const nodes = [];
13
- let node = obj;
14
- let key = '';
15
- for (let i = 0; i < path.length; i++) {
16
- const char = path[i];
17
- switch (char) {
18
- case '[':
19
- case ']':
20
- case '.':
21
- if (!key)
22
- break;
23
- if (Array.isArray(node)) {
24
- let ix = Number(key);
25
- if (!isNaN(ix)) {
26
- ix = ix | 0;
27
- if (ix < 0 || ix > node.length - 1)
28
- return undefined;
29
- node = node[ix];
30
- nodes.push(node);
31
- }
32
- else {
33
- const extracted = [];
34
- for (let y = 0; y < node.length; y++) {
35
- const el = deepGet(node[y], key);
36
- if (el !== undefined) {
37
- extracted.push(...Array.isArray(el) ? el : [el]);
11
+ }
12
+ let cursor = obj;
13
+ let parent = obj;
14
+ let keyStart = 0;
15
+ const len = path.length;
16
+ for (let i = 0; i <= len; i++) {
17
+ const code = i === len ? 46 : path.charCodeAt(i);
18
+ if (code === 46 || code === 91 || code === 93) {
19
+ if (i === keyStart) {
20
+ keyStart = i + 1;
21
+ continue;
22
+ }
23
+ const key = path.substring(keyStart, i);
24
+ keyStart = i + 1;
25
+ parent = cursor;
26
+ if (Array.isArray(cursor)) {
27
+ const idx = +key;
28
+ if (idx === idx) {
29
+ cursor = cursor[idx | 0];
30
+ }
31
+ else {
32
+ const mapped = [];
33
+ const cLen = cursor.length;
34
+ for (let j = 0; j < cLen; j++) {
35
+ const item = cursor[j];
36
+ if (item && typeof item === 'object') {
37
+ const val = item[key];
38
+ if (val !== undefined) {
39
+ if (Array.isArray(val)) {
40
+ const vLen = val.length;
41
+ for (let k = 0; k < vLen; k++)
42
+ mapped.push(val[k]);
43
+ }
44
+ else {
45
+ mapped.push(val);
46
+ }
38
47
  }
39
48
  }
40
- node = extracted;
41
- nodes.push(node);
42
49
  }
50
+ if (mapped.length === 0)
51
+ return undefined;
52
+ cursor = mapped;
43
53
  }
44
- else if (typeof node === 'object' && node !== null) {
45
- node = node[key];
46
- nodes.push(node);
47
- }
48
- key = '';
49
- break;
50
- default:
51
- key += char;
52
- break;
53
- }
54
- }
55
- if (key) {
56
- if (Array.isArray(node)) {
57
- let ix = Number(key);
58
- if (!isNaN(ix)) {
59
- ix = ix | 0;
60
- if (ix < 0 || ix > node.length - 1)
61
- return undefined;
62
- node = node[ix];
63
- nodes.push(node);
64
54
  }
65
- else {
66
- const extracted = [];
67
- for (let i = 0; i < node.length; i++) {
68
- const val = node[i]?.[key];
69
- if (val !== undefined)
70
- extracted.push(...Array.isArray(val) ? val : [val]);
71
- }
72
- node = extracted.length ? extracted : undefined;
73
- nodes.push(node);
55
+ else if (cursor) {
56
+ cursor = cursor[key];
74
57
  }
75
- }
76
- else if (typeof node === 'object' && node !== null) {
77
- node = node[key];
78
- nodes.push(node);
79
- if (node === undefined)
58
+ if (cursor === undefined)
80
59
  return undefined;
81
60
  }
82
- else {
83
- return undefined;
84
- }
85
61
  }
86
- if (get_parent)
87
- nodes.pop();
88
- return nodes.length ? nodes.pop() : obj;
62
+ return get_parent ? parent : cursor;
89
63
  }
package/cjs/deep/set.js CHANGED
@@ -9,45 +9,82 @@ function deepSet(obj, path, value, define = false) {
9
9
  throw new TypeError('Deepset is only supported for objects');
10
10
  if (typeof path !== 'string')
11
11
  throw new TypeError('No path was given');
12
- if (RGX_MALICIOUS.test(path))
13
- throw new TypeError('Malicious path provided');
14
- const path_s = path.trim();
15
- if (!path_s.length)
12
+ if (path.trim().length === 0) {
16
13
  throw new TypeError('No path was given');
17
- const parts = path_s
18
- .replace(/\[/g, '.')
19
- .replace(/(\.){2,}/g, '.')
20
- .replace(/(^\.|\.$|\])/g, '')
21
- .split('.');
22
- const last_part_ix = parts.length - 1;
23
- for (let i = 0; i < last_part_ix; i++) {
24
- if (Array.isArray(obj)) {
25
- const idx = parseInt(parts[i]);
26
- if (!Number.isInteger(idx) || idx < 0)
27
- throw new TypeError('Invalid path provided');
28
- if (!obj[idx])
29
- obj[idx] = {};
30
- obj = obj[idx];
31
- }
32
- else {
33
- if (!obj[parts[i]])
34
- obj[parts[i]] = {};
35
- obj = obj[parts[i]];
36
- }
37
14
  }
38
- if (!Array.isArray(obj) && Object.prototype.toString.call(obj) !== '[object Object]')
39
- return false;
40
- if (define) {
41
- Object.defineProperty(obj, parts[last_part_ix], value);
42
- }
43
- else if (Array.isArray(obj)) {
44
- const idx = parseInt(parts[last_part_ix]);
45
- if (!Number.isInteger(idx) || idx < 0)
46
- throw new TypeError('Invalid path provided');
47
- obj[idx] = value;
15
+ if (RGX_MALICIOUS.test(path)) {
16
+ throw new TypeError('Malicious path provided');
48
17
  }
49
- else {
50
- obj[parts[last_part_ix]] = value;
18
+ let cursor = obj;
19
+ let keyStart = 0;
20
+ const len = path.length;
21
+ for (let i = 0; i <= len; i++) {
22
+ const code = i === len ? 46 : path.charCodeAt(i);
23
+ if (code === 46 || code === 91 || code === 93) {
24
+ if (i === keyStart) {
25
+ keyStart = i + 1;
26
+ continue;
27
+ }
28
+ const key = path.substring(keyStart, i);
29
+ keyStart = i + 1;
30
+ let isEnd = i === len;
31
+ if (!isEnd) {
32
+ let j = i + 1;
33
+ isEnd = true;
34
+ for (; j < len; j++) {
35
+ const c = path.charCodeAt(j);
36
+ if (c !== 46 && c !== 91 && c !== 93) {
37
+ isEnd = false;
38
+ break;
39
+ }
40
+ }
41
+ }
42
+ if (isEnd) {
43
+ if (Array.isArray(cursor)) {
44
+ const idx = +key;
45
+ if (idx !== idx || (idx | 0) !== idx || idx < 0) {
46
+ throw new TypeError('Invalid path provided');
47
+ }
48
+ if (define) {
49
+ Object.defineProperty(cursor, key, value);
50
+ }
51
+ else {
52
+ cursor[idx] = value;
53
+ }
54
+ }
55
+ else if (define) {
56
+ Object.defineProperty(cursor, key, value);
57
+ }
58
+ else {
59
+ cursor[key] = value;
60
+ }
61
+ return true;
62
+ }
63
+ let nextCursor;
64
+ if (Array.isArray(cursor)) {
65
+ const idx = +key;
66
+ if (idx !== idx || (idx | 0) !== idx || idx < 0) {
67
+ throw new TypeError('Invalid path provided');
68
+ }
69
+ nextCursor = cursor[idx];
70
+ }
71
+ else {
72
+ nextCursor = cursor[key];
73
+ }
74
+ if (nextCursor === undefined || nextCursor === null) {
75
+ nextCursor = {};
76
+ if (Array.isArray(cursor)) {
77
+ cursor[+key] = nextCursor;
78
+ }
79
+ else {
80
+ cursor[key] = nextCursor;
81
+ }
82
+ }
83
+ else if (typeof nextCursor !== 'object') {
84
+ return false;
85
+ }
86
+ cursor = nextCursor;
87
+ }
51
88
  }
52
- return true;
89
+ return false;
53
90
  }
@@ -3,96 +3,131 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toObject = toObject;
4
4
  exports.default = toObject;
5
5
  const isFormat_1 = require("../date/isFormat");
6
- const RGX_TOKENS = /[^.[\]]+/g;
6
+ const forbiddenKeys_1 = require("../string/forbiddenKeys");
7
7
  function assign(acc, rawkey, value, single) {
8
+ if (rawkey.indexOf('.') === -1 && rawkey.indexOf('[') === -1) {
9
+ if (forbiddenKeys_1.FORBIDDEN_KEYS.has(rawkey))
10
+ return;
11
+ if (single?.has(rawkey)) {
12
+ acc[rawkey] = value;
13
+ return;
14
+ }
15
+ const existing = acc[rawkey];
16
+ if (existing === undefined) {
17
+ acc[rawkey] = value;
18
+ }
19
+ else if (Array.isArray(existing)) {
20
+ existing.push(value);
21
+ }
22
+ else {
23
+ acc[rawkey] = [existing, value];
24
+ }
25
+ return;
26
+ }
27
+ const keys = [];
28
+ let start = 0;
29
+ const len = rawkey.length;
30
+ for (let i = 0; i < len; i++) {
31
+ const code = rawkey.charCodeAt(i);
32
+ if (code === 46 || code === 91 || code === 93) {
33
+ if (i > start)
34
+ keys.push(rawkey.substring(start, i));
35
+ start = i + 1;
36
+ }
37
+ }
38
+ if (start < len)
39
+ keys.push(rawkey.substring(start));
8
40
  let cursor = acc;
9
- const keys = rawkey.match(RGX_TOKENS);
10
41
  const keys_len = keys.length;
11
42
  for (let i = 0; i < keys_len; i++) {
12
43
  const key = keys[i];
13
- switch (key) {
14
- case '__proto__':
15
- case 'constructor':
16
- case 'prototype':
17
- return;
18
- default: {
19
- if (i < (keys_len - 1)) {
20
- const n_key = Array.isArray(cursor) ? Number(key) : key;
21
- if (!cursor[n_key])
22
- cursor[n_key] = isNaN(Number(keys[i + 1])) ? {} : [];
23
- cursor = cursor[n_key];
24
- }
25
- else if (!(key in cursor) || (single && single.has(key))) {
26
- cursor[key] = value;
44
+ if (forbiddenKeys_1.FORBIDDEN_KEYS.has(key))
45
+ return;
46
+ const isLast = i === keys_len - 1;
47
+ const cursorKey = Array.isArray(cursor) ? +key : key;
48
+ if (isLast) {
49
+ if (cursor[cursorKey] === undefined || (single && single.has(key))) {
50
+ cursor[cursorKey] = value;
51
+ }
52
+ else {
53
+ const existing = cursor[cursorKey];
54
+ if (Array.isArray(existing)) {
55
+ existing.push(value);
27
56
  }
28
57
  else {
29
- const cursor_val = cursor[key];
30
- if (Array.isArray(cursor_val)) {
31
- cursor_val.push(value);
32
- }
33
- else {
34
- cursor[key] = [cursor_val, value];
35
- }
58
+ cursor[cursorKey] = [existing, value];
36
59
  }
37
60
  }
38
61
  }
62
+ else {
63
+ if (cursor[cursorKey] === undefined) {
64
+ cursor[cursorKey] = isNaN(+keys[i + 1]) ? {} : [];
65
+ }
66
+ cursor = cursor[cursorKey];
67
+ }
39
68
  }
40
69
  }
41
70
  function toObject(form, config) {
42
71
  if (!(form instanceof FormData))
43
72
  throw new Error('formdata/toObject: Value is not an instance of FormData');
44
- const set = config?.raw === true ? null : new Set(Array.isArray(config?.raw) ? config?.raw : []);
45
- const set_guard = !!(set && set.size > 0);
46
- const single = Array.isArray(config?.single) ? new Set(config.single) : null;
47
- const nBool = config?.normalize_bool !== false;
48
- const nNull = config?.normalize_null !== false;
49
- const nDate = config?.normalize_date !== false;
50
- const nNumber = config?.normalize_number !== false;
51
73
  const acc = {};
52
- if (set === null) {
74
+ const single = Array.isArray(config?.single) ? new Set(config.single) : null;
75
+ if (config?.raw === true) {
53
76
  for (const [key, value] of form) {
54
77
  assign(acc, key, value, single);
55
78
  }
56
79
  return acc;
57
80
  }
81
+ const rawConfig = config?.raw;
82
+ const set = rawConfig ? new Set(Array.isArray(rawConfig) ? rawConfig : []) : null;
83
+ const hasSet = set !== null && set.size > 0;
84
+ const nBool = config?.normalize_bool !== false;
85
+ const nNull = config?.normalize_null !== false;
86
+ const nDate = config?.normalize_date !== false;
87
+ const nNumber = config?.normalize_number !== false;
58
88
  for (const [key, value] of form) {
59
- if (set_guard && set.has(key)) {
89
+ if (hasSet && set.has(key)) {
60
90
  assign(acc, key, value, single);
61
91
  continue;
62
92
  }
63
- switch (value) {
64
- case 'true':
65
- case 'TRUE':
66
- case 'True':
67
- assign(acc, key, nBool ? true : value, single);
68
- continue;
69
- case 'false':
70
- case 'FALSE':
71
- case 'False':
72
- assign(acc, key, nBool ? false : value, single);
73
- continue;
74
- case 'null':
75
- case 'NULL':
76
- case 'Null':
77
- assign(acc, key, nNull ? null : value, single);
93
+ if (typeof value === 'string') {
94
+ const len = value.length;
95
+ if (len === 0) {
96
+ assign(acc, key, value, single);
78
97
  continue;
79
- default: {
80
- if (typeof value === 'string' && value) {
81
- if (nNumber && value[0] !== '0') {
82
- const nVal = Number(value);
83
- if (!isNaN(nVal)) {
84
- assign(acc, key, nVal, single);
85
- continue;
86
- }
87
- }
88
- if (nDate && value[4] === '-' && value[7] === '-' && value[10] === 'T' && (0, isFormat_1.isDateFormat)(value, 'ISO')) {
89
- assign(acc, key, new Date(value), single);
90
- continue;
91
- }
98
+ }
99
+ if (len === 4) {
100
+ if (nBool && (value === 'true' || value === 'TRUE' || value === 'True')) {
101
+ assign(acc, key, true, single);
102
+ continue;
92
103
  }
93
- assign(acc, key, value, single);
104
+ if (nNull && (value === 'null' || value === 'NULL' || value === 'Null')) {
105
+ assign(acc, key, null, single);
106
+ continue;
107
+ }
108
+ }
109
+ else if (len === 5) {
110
+ if (nBool && (value === 'false' || value === 'FALSE' || value === 'False')) {
111
+ assign(acc, key, false, single);
112
+ continue;
113
+ }
114
+ }
115
+ if (nNumber && value.charCodeAt(0) !== 48) {
116
+ const nVal = +value;
117
+ if (!isNaN(nVal)) {
118
+ assign(acc, key, nVal, single);
119
+ continue;
120
+ }
121
+ }
122
+ if (nDate && len >= 10 &&
123
+ value.charCodeAt(4) === 45 &&
124
+ value.charCodeAt(7) === 45 &&
125
+ (0, isFormat_1.isDateFormat)(value, 'ISO')) {
126
+ assign(acc, key, new Date(value), single);
127
+ continue;
94
128
  }
95
129
  }
130
+ assign(acc, key, value, single);
96
131
  }
97
132
  return acc;
98
133
  }
package/cjs/hash/djb2.js CHANGED
@@ -10,5 +10,5 @@ function djb2(data) {
10
10
  for (let i = 0; i < len; i++) {
11
11
  hash = ((hash << 5) + hash) ^ normalized.charCodeAt(i);
12
12
  }
13
- return String(hash >>> 0);
13
+ return (hash >>> 0).toString();
14
14
  }
package/cjs/hash/fnv1A.js CHANGED
@@ -6,13 +6,14 @@ exports.default = fnv1A;
6
6
  const utils_1 = require("./utils");
7
7
  exports.FNV_32 = 2166136261;
8
8
  exports.FNV_64 = 1099511628211n;
9
+ const FNV_PRIME = 16777619;
9
10
  function fnv1A(data, offset = exports.FNV_32) {
10
11
  let hash = offset;
11
- const normalized = (0, utils_1.toString)(data);
12
- const len = normalized.length;
12
+ const str = (0, utils_1.toString)(data);
13
+ const len = str.length;
13
14
  for (let i = 0; i < len; i++) {
14
- hash ^= normalized.charCodeAt(i);
15
- hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
15
+ hash ^= str.charCodeAt(i);
16
+ hash = Math.imul(hash, FNV_PRIME);
16
17
  }
17
18
  return hash >>> 0;
18
19
  }