@valkyriestudios/utils 12.47.0 → 12.49.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.
@@ -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 (nVal === 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
  }
package/cjs/hash/guid.js CHANGED
@@ -2,27 +2,39 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.guid = guid;
4
4
  exports.default = guid;
5
+ const CRYPTO = globalThis.crypto;
5
6
  const HEX = [];
6
7
  for (let i = 0; i < 256; i++) {
7
- HEX[i] = (i < 16 ? '0' : '') + i.toString(16);
8
- }
9
- let pool = new Uint8Array(0);
10
- let poolIdx = 0;
11
- function refill(size = 16 * 1024) {
12
- pool = new Uint8Array(size);
13
- crypto.getRandomValues(pool);
14
- poolIdx = 0;
8
+ HEX[i] = (i + 256).toString(16).substring(1);
15
9
  }
10
+ const POOL_SIZE = 16 * 1024;
11
+ const pool = new Uint8Array(POOL_SIZE);
12
+ let poolIdx = POOL_SIZE;
16
13
  function guid() {
17
- if (poolIdx + 16 > pool.length)
18
- refill();
19
- const buf = pool.subarray(poolIdx, poolIdx + 16);
14
+ if (poolIdx + 16 > POOL_SIZE) {
15
+ CRYPTO.getRandomValues(pool);
16
+ poolIdx = 0;
17
+ }
18
+ const p = poolIdx;
20
19
  poolIdx += 16;
21
- buf[6] = (buf[6] & 0x0f) | 0x40;
22
- buf[8] = (buf[8] & 0x3f) | 0x80;
23
- return (HEX[buf[0]] + HEX[buf[1]] + HEX[buf[2]] + HEX[buf[3]] + '-' +
24
- HEX[buf[4]] + HEX[buf[5]] + '-' +
25
- HEX[buf[6]] + HEX[buf[7]] + '-' +
26
- HEX[buf[8]] + HEX[buf[9]] + '-' +
27
- HEX[buf[10]] + HEX[buf[11]] + HEX[buf[12]] + HEX[buf[13]] + HEX[buf[14]] + HEX[buf[15]]);
20
+ return (HEX[pool[p]] +
21
+ HEX[pool[p + 1]] +
22
+ HEX[pool[p + 2]] +
23
+ HEX[pool[p + 3]] +
24
+ '-' +
25
+ HEX[pool[p + 4]] +
26
+ HEX[pool[p + 5]] +
27
+ '-' +
28
+ HEX[(pool[p + 6] & 0x0f) | 0x40] +
29
+ HEX[pool[p + 7]] +
30
+ '-' +
31
+ HEX[(pool[p + 8] & 0x3f) | 0x80] +
32
+ HEX[pool[p + 9]] +
33
+ '-' +
34
+ HEX[pool[p + 10]] +
35
+ HEX[pool[p + 11]] +
36
+ HEX[pool[p + 12]] +
37
+ HEX[pool[p + 13]] +
38
+ HEX[pool[p + 14]] +
39
+ HEX[pool[p + 15]]);
28
40
  }
package/cjs/hash/hexId.js CHANGED
@@ -2,27 +2,35 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hexId = hexId;
4
4
  exports.default = hexId;
5
+ const CRYPTO = globalThis.crypto;
5
6
  const HEX = [];
6
7
  for (let i = 0; i < 256; i++) {
7
- HEX[i] = (i < 16 ? '0' : '') + i.toString(16);
8
- }
9
- let pool = new Uint8Array(0);
10
- let poolIdx = 0;
11
- function refill(size = 16 * 1024) {
12
- pool = new Uint8Array(size);
13
- crypto.getRandomValues(pool);
14
- poolIdx = 0;
8
+ HEX[i] = (i + 256).toString(16).substring(1);
15
9
  }
10
+ const POOL_SIZE = 16 * 1024;
11
+ const pool = new Uint8Array(POOL_SIZE);
12
+ let poolIdx = POOL_SIZE;
16
13
  function hexId(size) {
17
- if (!Number.isInteger(size) || size <= 0)
14
+ if (typeof size !== 'number' || size <= 0 || (size | 0) !== size)
18
15
  return '';
19
- if (poolIdx + size > pool.length)
20
- refill();
21
- const buf = pool.subarray(poolIdx, poolIdx + size);
16
+ if (size > POOL_SIZE) {
17
+ const buf = new Uint8Array(size);
18
+ CRYPTO.getRandomValues(buf);
19
+ let out = '';
20
+ for (let i = 0; i < size; i++) {
21
+ out += HEX[buf[i]];
22
+ }
23
+ return out;
24
+ }
25
+ if (poolIdx + size > POOL_SIZE) {
26
+ CRYPTO.getRandomValues(pool);
27
+ poolIdx = 0;
28
+ }
29
+ let i = poolIdx;
30
+ const end = i + size;
22
31
  poolIdx += size;
23
32
  let out = '';
24
- for (let i = 0; i < buf.length; i++) {
25
- out += HEX[buf[i]];
26
- }
33
+ while (i < end)
34
+ out += HEX[pool[i++]];
27
35
  return out;
28
36
  }
package/cjs/hash/utils.js CHANGED
@@ -2,39 +2,31 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toString = toString;
4
4
  function toString(raw) {
5
- switch (typeof raw) {
6
- case 'string':
7
- return raw;
8
- case 'number':
9
- return Number.isFinite(raw) ? String(raw) : 'nan';
10
- case 'bigint':
11
- return raw.toString();
12
- case 'boolean':
13
- return raw ? 'true' : 'false';
14
- case 'undefined':
15
- return 'undefined';
16
- case 'object':
17
- if (raw === null) {
18
- return 'null';
19
- }
20
- else if (Array.isArray(raw) || Object.prototype.toString.call(raw) === '[object Object]') {
21
- return JSON.stringify(raw);
22
- }
23
- else if (raw instanceof RegExp) {
24
- return String(raw);
25
- }
26
- else if (raw instanceof Date) {
27
- return String(raw.getTime());
28
- }
29
- else if (raw instanceof Error) {
30
- return raw.name + '|' + raw.message;
31
- }
32
- else {
33
- throw new TypeError('A Hash could not be calculated for this datatype');
34
- }
35
- case 'symbol':
5
+ const type = typeof raw;
6
+ if (type === 'string')
7
+ return raw;
8
+ if (type === 'number')
9
+ return Number.isFinite(raw) ? String(raw) : 'nan';
10
+ if (type === 'boolean')
11
+ return raw ? 'true' : 'false';
12
+ if (type === 'undefined')
13
+ return 'undefined';
14
+ if (type === 'object') {
15
+ if (raw === null)
16
+ return 'null';
17
+ if (Array.isArray(raw) || Object.prototype.toString.call(raw) === '[object Object]')
18
+ return JSON.stringify(raw);
19
+ if (raw instanceof Date)
20
+ return String(raw.getTime());
21
+ if (raw instanceof RegExp)
36
22
  return String(raw);
37
- default:
38
- throw new TypeError('A Hash could not be calculated for this datatype');
23
+ if (raw instanceof Error)
24
+ return raw.name + '|' + raw.message;
25
+ throw new TypeError('A Hash could not be calculated for this datatype');
39
26
  }
27
+ if (type === 'bigint')
28
+ return raw.toString();
29
+ if (type === 'symbol')
30
+ return raw.toString();
31
+ throw new TypeError('A Hash could not be calculated for this datatype');
40
32
  }
@@ -2,41 +2,42 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.uuidv7 = uuidv7;
4
4
  exports.default = uuidv7;
5
+ const CRYPTO = globalThis.crypto;
5
6
  const HEX = [];
6
7
  for (let i = 0; i < 256; i++) {
7
- HEX[i] = (i < 16 ? '0' : '') + i.toString(16);
8
- }
9
- let pool = new Uint8Array(0);
10
- let poolIdx = 0;
11
- function refill(size = 16 * 1024) {
12
- pool = new Uint8Array(size);
13
- crypto.getRandomValues(pool);
14
- poolIdx = 0;
8
+ HEX[i] = (i + 256).toString(16).substring(1);
15
9
  }
10
+ const POOL_SIZE = 16 * 1024;
11
+ const pool = new Uint8Array(POOL_SIZE);
12
+ let poolIdx = POOL_SIZE;
16
13
  function uuidv7() {
17
- if (poolIdx + 10 > pool.length)
18
- refill();
19
- const rand = pool.subarray(poolIdx, poolIdx + 10);
14
+ if (poolIdx + 10 > POOL_SIZE) {
15
+ CRYPTO.getRandomValues(pool);
16
+ poolIdx = 0;
17
+ }
18
+ const p = poolIdx;
20
19
  poolIdx += 10;
21
- const time = BigInt(Date.now());
22
- return (HEX[Number((time >> 40n) & 0xffn)] +
23
- HEX[Number((time >> 32n) & 0xffn)] +
24
- HEX[Number((time >> 24n) & 0xffn)] +
25
- HEX[Number((time >> 16n) & 0xffn)] +
20
+ const time = Date.now();
21
+ const timeHi = (time / 4294967296) | 0;
22
+ const timeLo = time >>> 0;
23
+ return (HEX[(timeHi >>> 8) & 0xff] +
24
+ HEX[timeHi & 0xff] +
25
+ HEX[(timeLo >>> 24) & 0xff] +
26
+ HEX[(timeLo >>> 16) & 0xff] +
26
27
  '-' +
27
- HEX[Number((time >> 8n) & 0xffn)] +
28
- HEX[Number(time & 0xffn)] +
28
+ HEX[(timeLo >>> 8) & 0xff] +
29
+ HEX[timeLo & 0xff] +
29
30
  '-' +
30
- HEX[(rand[0] & 0x0f) | 0x70] +
31
- HEX[rand[1]] +
31
+ HEX[(pool[p] & 0x0f) | 0x70] +
32
+ HEX[pool[p + 1]] +
32
33
  '-' +
33
- HEX[(rand[2] & 0x3f) | 0x80] +
34
- HEX[rand[3]] +
34
+ HEX[(pool[p + 2] & 0x3f) | 0x80] +
35
+ HEX[pool[p + 3]] +
35
36
  '-' +
36
- HEX[rand[4]] +
37
- HEX[rand[5]] +
38
- HEX[rand[6]] +
39
- HEX[rand[7]] +
40
- HEX[rand[8]] +
41
- HEX[rand[9]]);
37
+ HEX[pool[p + 4]] +
38
+ HEX[pool[p + 5]] +
39
+ HEX[pool[p + 6]] +
40
+ HEX[pool[p + 7]] +
41
+ HEX[pool[p + 8]] +
42
+ HEX[pool[p + 9]]);
42
43
  }
@@ -6,7 +6,7 @@ const ROUND_EPSILON = 1 + Number.EPSILON;
6
6
  function round(val, precision = 0) {
7
7
  if (!Number.isFinite(val))
8
8
  throw new TypeError('Value should be numeric');
9
- if (!Number.isInteger(precision) || precision <= 0)
9
+ if (typeof precision !== 'number' || precision <= 0 || (precision | 0) !== precision)
10
10
  return Math.round(val * ROUND_EPSILON);
11
11
  const exp = Math.pow(10, precision);
12
12
  return Math.round((val * exp) * ROUND_EPSILON) / exp;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FORBIDDEN_KEYS = void 0;
4
+ exports.FORBIDDEN_KEYS = new Set([
5
+ '__proto__',
6
+ 'constructor',
7
+ 'prototype',
8
+ ]);
@@ -9,6 +9,7 @@ function humanizeNumber(val, options = {}) {
9
9
  const SEPARATOR = typeof options?.separator === 'string' && options.separator.length ? options.separator : '.';
10
10
  const PRECISION = Number.isInteger(options?.precision) && options.precision >= 0 ? options.precision : 2;
11
11
  const DIVIDER = Number.isInteger(options?.divider) && options.divider >= 2 ? options.divider : 1000;
12
+ const INV_DIVIDER = 1.0 / DIVIDER;
12
13
  const REAL = options?.real === true;
13
14
  const UNITS = Array.isArray(options?.units) && options.units.length
14
15
  ? options.units
@@ -25,7 +26,7 @@ function humanizeNumber(val, options = {}) {
25
26
  let unit_ix = 0;
26
27
  if (UNITS) {
27
28
  while (normalized >= DIVIDER && unit_ix < UNITS.length - 1) {
28
- normalized /= DIVIDER;
29
+ normalized *= INV_DIVIDER;
29
30
  unit_ix++;
30
31
  }
31
32
  }
package/esm/array/join.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { round } from '../number/round';
2
2
  import { isIntegerAboveOrEqual } from '../number/isIntegerAboveOrEqual';
3
- const SPACE_RGX = /(\s)+/g;
3
+ const SPACE_RGX = /\s+/g;
4
4
  function join(val, opts) {
5
5
  let normalized;
6
6
  if (Array.isArray(val)) {
@@ -1,12 +1,19 @@
1
- import { isDate } from './is';
2
1
  function convertToDate(val) {
3
- if (isDate(val)) {
4
- return val;
2
+ switch (typeof val) {
3
+ case 'number': {
4
+ if (val !== val)
5
+ return null;
6
+ const d = new Date(val);
7
+ return d.getTime() === d.getTime() ? d : null;
8
+ }
9
+ case 'object':
10
+ return val instanceof Date && val.getTime() === val.getTime() ? val : null;
11
+ case 'string': {
12
+ const d = new Date(val);
13
+ return d.getTime() === d.getTime() ? d : null;
14
+ }
15
+ default:
16
+ return null;
5
17
  }
6
- else if (typeof val === 'string') {
7
- const date = new Date(val);
8
- return Number.isNaN(date.getTime()) ? null : date;
9
- }
10
- return null;
11
18
  }
12
19
  export { convertToDate, convertToDate as default };
package/esm/date/diff.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { convertToDate } from './convertToDate';
2
- const SECOND_IN_MILLISECONDS = 1000;
3
- const MINUTE_IN_MILLISECONDS = SECOND_IN_MILLISECONDS * 60;
4
- const HOUR_IN_MILLISECONDS = MINUTE_IN_MILLISECONDS * 60;
5
- const DAY_IN_MILLISECONDS = HOUR_IN_MILLISECONDS * 24;
6
- const WEEK_IN_MILLISECONDS = DAY_IN_MILLISECONDS * 7;
2
+ const INV_SECOND_IN_MILLISECONDS = 1.0 / 1000;
3
+ const INV_MINUTE_IN_MILLISECONDS = 1.0 / (60 * 1000);
4
+ const INV_HOUR_IN_MILLISECONDS = 1.0 / (60 * 60 * 1000);
5
+ const INV_DAY_IN_MILLISECONDS = 1.0 / (24 * 60 * 60 * 1000);
6
+ const INV_WEEK_IN_MILLISECONDS = 1.0 / (7 * 24 * 60 * 60 * 1000);
7
7
  function diff(val_a, val_b, key = 'millisecond') {
8
8
  const n_val_a = convertToDate(val_a);
9
9
  const n_val_b = convertToDate(val_b);
@@ -14,19 +14,19 @@ function diff(val_a, val_b, key = 'millisecond') {
14
14
  switch (key) {
15
15
  case 'week':
16
16
  case 'weeks':
17
- return diff_in_ms / WEEK_IN_MILLISECONDS;
17
+ return diff_in_ms * INV_WEEK_IN_MILLISECONDS;
18
18
  case 'day':
19
19
  case 'days':
20
- return diff_in_ms / DAY_IN_MILLISECONDS;
20
+ return diff_in_ms * INV_DAY_IN_MILLISECONDS;
21
21
  case 'hour':
22
22
  case 'hours':
23
- return diff_in_ms / HOUR_IN_MILLISECONDS;
23
+ return diff_in_ms * INV_HOUR_IN_MILLISECONDS;
24
24
  case 'minute':
25
25
  case 'minutes':
26
- return diff_in_ms / MINUTE_IN_MILLISECONDS;
26
+ return diff_in_ms * INV_MINUTE_IN_MILLISECONDS;
27
27
  case 'second':
28
28
  case 'seconds':
29
- return diff_in_ms / SECOND_IN_MILLISECONDS;
29
+ return diff_in_ms * INV_SECOND_IN_MILLISECONDS;
30
30
  default:
31
31
  return diff_in_ms;
32
32
  }