@valkyriestudios/utils 9.0.0 → 11.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.
Files changed (255) hide show
  1. package/README.md +2 -2
  2. package/dist/array/dedupe.d.ts +1 -0
  3. package/dist/array/dedupe.js +19 -0
  4. package/dist/array/is.d.ts +1 -0
  5. package/dist/array/is.js +6 -0
  6. package/dist/array/isNotEmpty.d.ts +1 -0
  7. package/dist/array/isNotEmpty.js +6 -0
  8. package/dist/array/join.d.ts +8 -0
  9. package/dist/array/join.js +24 -0
  10. package/dist/array/mapFn.d.ts +14 -0
  11. package/dist/array/mapFn.js +28 -0
  12. package/dist/array/mapKey.d.ts +12 -0
  13. package/dist/array/mapKey.js +27 -0
  14. package/dist/array/mapPrimitive.d.ts +10 -0
  15. package/dist/array/mapPrimitive.js +27 -0
  16. package/dist/array/shuffle.d.ts +1 -0
  17. package/dist/array/shuffle.js +11 -0
  18. package/dist/array/sort.d.ts +11 -0
  19. package/dist/array/sort.js +92 -0
  20. package/dist/boolean/is.d.ts +1 -0
  21. package/dist/boolean/is.js +6 -0
  22. package/dist/caching/memoize.d.ts +1 -0
  23. package/dist/caching/memoize.js +15 -0
  24. package/dist/date/addUTC.d.ts +1 -0
  25. package/{src/date/addUTC.mjs → dist/date/addUTC.js} +11 -26
  26. package/dist/date/diff.d.ts +1 -0
  27. package/dist/date/diff.js +38 -0
  28. package/dist/date/endOfUTC.d.ts +1 -0
  29. package/dist/date/endOfUTC.js +52 -0
  30. package/dist/date/is.d.ts +1 -0
  31. package/dist/date/is.js +6 -0
  32. package/dist/date/nowUnix.d.ts +1 -0
  33. package/dist/date/nowUnix.js +6 -0
  34. package/dist/date/nowUnixMs.d.ts +1 -0
  35. package/dist/date/nowUnixMs.js +6 -0
  36. package/dist/date/startOfUTC.d.ts +1 -0
  37. package/dist/date/startOfUTC.js +52 -0
  38. package/dist/date/toUTC.d.ts +1 -0
  39. package/dist/date/toUTC.js +9 -0
  40. package/dist/date/toUnix.d.ts +1 -0
  41. package/dist/date/toUnix.js +9 -0
  42. package/dist/deep/freeze.d.ts +7 -0
  43. package/dist/deep/freeze.js +23 -0
  44. package/dist/deep/get.d.ts +5 -0
  45. package/dist/deep/get.js +41 -0
  46. package/dist/deep/seal.d.ts +7 -0
  47. package/dist/deep/seal.js +23 -0
  48. package/dist/deep/set.d.ts +5 -0
  49. package/dist/deep/set.js +52 -0
  50. package/dist/equal.d.ts +2 -0
  51. package/dist/equal.js +43 -0
  52. package/dist/function/is.d.ts +1 -0
  53. package/dist/function/is.js +6 -0
  54. package/dist/function/noop.d.ts +1 -0
  55. package/dist/function/noop.js +5 -0
  56. package/dist/function/noopresolve.d.ts +1 -0
  57. package/dist/function/noopresolve.js +6 -0
  58. package/dist/function/noopreturn.d.ts +1 -0
  59. package/dist/function/noopreturn.js +6 -0
  60. package/dist/function/sleep.d.ts +1 -0
  61. package/dist/function/sleep.js +8 -0
  62. package/dist/hash/fnv1A.d.ts +1 -0
  63. package/dist/hash/fnv1A.js +51 -0
  64. package/dist/hash/guid.d.ts +1 -0
  65. package/{src/hash/guid.mjs → dist/hash/guid.js} +9 -14
  66. package/dist/is.d.ts +75 -0
  67. package/dist/is.js +77 -0
  68. package/dist/number/is.d.ts +1 -0
  69. package/dist/number/is.js +6 -0
  70. package/dist/number/isAbove.d.ts +1 -0
  71. package/dist/number/isAbove.js +6 -0
  72. package/dist/number/isAboveOrEqual.d.ts +1 -0
  73. package/dist/number/isAboveOrEqual.js +6 -0
  74. package/dist/number/isBelow.d.ts +1 -0
  75. package/dist/number/isBelow.js +6 -0
  76. package/dist/number/isBelowOrEqual.d.ts +1 -0
  77. package/dist/number/isBelowOrEqual.js +6 -0
  78. package/dist/number/isBetween.d.ts +1 -0
  79. package/dist/number/isBetween.js +11 -0
  80. package/dist/number/isInteger.d.ts +1 -0
  81. package/dist/number/isInteger.js +6 -0
  82. package/dist/number/isIntegerAbove.d.ts +1 -0
  83. package/dist/number/isIntegerAbove.js +6 -0
  84. package/dist/number/isIntegerAboveOrEqual.d.ts +1 -0
  85. package/dist/number/isIntegerAboveOrEqual.js +6 -0
  86. package/dist/number/isIntegerBelow.d.ts +1 -0
  87. package/dist/number/isIntegerBelow.js +6 -0
  88. package/dist/number/isIntegerBelowOrEqual.d.ts +1 -0
  89. package/dist/number/isIntegerBelowOrEqual.js +6 -0
  90. package/dist/number/isIntegerBetween.d.ts +1 -0
  91. package/dist/number/isIntegerBetween.js +11 -0
  92. package/dist/number/isNumericalNaN.d.ts +1 -0
  93. package/dist/number/isNumericalNaN.js +6 -0
  94. package/dist/number/randomBetween.d.ts +1 -0
  95. package/dist/number/randomBetween.js +9 -0
  96. package/dist/number/randomIntBetween.d.ts +1 -0
  97. package/dist/number/randomIntBetween.js +9 -0
  98. package/dist/number/round.d.ts +1 -0
  99. package/dist/number/round.js +10 -0
  100. package/dist/number/toPercentage.d.ts +1 -0
  101. package/dist/number/toPercentage.js +11 -0
  102. package/dist/object/define.d.ts +7 -0
  103. package/dist/object/define.js +9 -0
  104. package/dist/object/is.d.ts +1 -0
  105. package/dist/object/is.js +7 -0
  106. package/dist/object/isNotEmpty.d.ts +1 -0
  107. package/dist/object/isNotEmpty.js +6 -0
  108. package/dist/object/merge.d.ts +8 -0
  109. package/dist/object/merge.js +20 -0
  110. package/dist/object/pick.d.ts +5 -0
  111. package/dist/object/pick.js +34 -0
  112. package/dist/regexp/is.d.ts +1 -0
  113. package/dist/regexp/is.js +6 -0
  114. package/dist/regexp/sanitize.d.ts +1 -0
  115. package/dist/regexp/sanitize.js +8 -0
  116. package/dist/string/humanizeBytes.d.ts +8 -0
  117. package/dist/string/humanizeBytes.js +24 -0
  118. package/dist/string/humanizeNumber.d.ts +10 -0
  119. package/dist/string/humanizeNumber.js +60 -0
  120. package/dist/string/is.d.ts +1 -0
  121. package/dist/string/is.js +6 -0
  122. package/dist/string/isBetween.d.ts +1 -0
  123. package/dist/string/isBetween.js +14 -0
  124. package/dist/string/isNotEmpty.d.ts +1 -0
  125. package/dist/string/isNotEmpty.js +8 -0
  126. package/dist/string/shorten.d.ts +1 -0
  127. package/dist/string/shorten.js +11 -0
  128. package/package.json +303 -46
  129. package/CHANGELOG.md +0 -474
  130. package/array/dedupe.js +0 -33
  131. package/array/is.js +0 -9
  132. package/array/isNotEmpty.js +0 -9
  133. package/array/join.js +0 -41
  134. package/array/mapFn.js +0 -42
  135. package/array/mapKey.js +0 -38
  136. package/array/mapPrimitive.js +0 -43
  137. package/array/shuffle.js +0 -14
  138. package/array/sort.js +0 -125
  139. package/boolean/is.js +0 -9
  140. package/caching/memoize.js +0 -21
  141. package/date/addUTC.js +0 -60
  142. package/date/diff.js +0 -40
  143. package/date/endOfUTC.js +0 -55
  144. package/date/is.js +0 -9
  145. package/date/nowUnix.js +0 -9
  146. package/date/nowUnixMs.js +0 -9
  147. package/date/startOfUTC.js +0 -55
  148. package/date/toUTC.js +0 -10
  149. package/date/toUnix.js +0 -10
  150. package/deep/define.js +0 -12
  151. package/deep/freeze.js +0 -18
  152. package/deep/get.js +0 -31
  153. package/deep/seal.js +0 -18
  154. package/deep/set.js +0 -28
  155. package/equal.js +0 -37
  156. package/function/is.js +0 -8
  157. package/function/noop.js +0 -7
  158. package/function/noopresolve.js +0 -10
  159. package/function/noopreturn.js +0 -8
  160. package/function/sleep.js +0 -13
  161. package/hash/fnv1A.js +0 -49
  162. package/hash/guid.js +0 -16
  163. package/is.js +0 -319
  164. package/number/is.js +0 -9
  165. package/number/isAbove.js +0 -8
  166. package/number/isAboveOrEqual.js +0 -8
  167. package/number/isBelow.js +0 -8
  168. package/number/isBelowOrEqual.js +0 -8
  169. package/number/isBetween.js +0 -9
  170. package/number/isInteger.js +0 -9
  171. package/number/isIntegerAbove.js +0 -8
  172. package/number/isIntegerAboveOrEqual.js +0 -8
  173. package/number/isIntegerBelow.js +0 -8
  174. package/number/isIntegerBelowOrEqual.js +0 -8
  175. package/number/isIntegerBetween.js +0 -9
  176. package/number/isNumericalNaN.js +0 -9
  177. package/number/randomBetween.js +0 -11
  178. package/number/randomIntBetween.js +0 -11
  179. package/number/round.js +0 -12
  180. package/number/toPercentage.js +0 -15
  181. package/object/define.js +0 -12
  182. package/object/is.js +0 -11
  183. package/object/isNotEmpty.js +0 -10
  184. package/object/merge.js +0 -20
  185. package/object/pick.js +0 -41
  186. package/regexp/is.js +0 -11
  187. package/regexp/sanitize.js +0 -12
  188. package/src/array/dedupe.mjs +0 -24
  189. package/src/array/is.mjs +0 -5
  190. package/src/array/isNotEmpty.mjs +0 -5
  191. package/src/array/join.mjs +0 -31
  192. package/src/array/mapFn.mjs +0 -34
  193. package/src/array/mapKey.mjs +0 -31
  194. package/src/array/mapPrimitive.mjs +0 -29
  195. package/src/array/shuffle.mjs +0 -14
  196. package/src/array/sort.mjs +0 -102
  197. package/src/boolean/is.mjs +0 -5
  198. package/src/caching/memoize.mjs +0 -24
  199. package/src/date/diff.mjs +0 -46
  200. package/src/date/endOfUTC.mjs +0 -130
  201. package/src/date/is.mjs +0 -5
  202. package/src/date/nowUnix.mjs +0 -5
  203. package/src/date/nowUnixMs.mjs +0 -5
  204. package/src/date/startOfUTC.mjs +0 -129
  205. package/src/date/toUTC.mjs +0 -17
  206. package/src/date/toUnix.mjs +0 -9
  207. package/src/deep/define.mjs +0 -7
  208. package/src/deep/freeze.mjs +0 -22
  209. package/src/deep/get.mjs +0 -51
  210. package/src/deep/seal.mjs +0 -22
  211. package/src/deep/set.mjs +0 -45
  212. package/src/equal.mjs +0 -67
  213. package/src/function/is.mjs +0 -6
  214. package/src/function/noop.mjs +0 -5
  215. package/src/function/noopresolve.mjs +0 -6
  216. package/src/function/noopreturn.mjs +0 -6
  217. package/src/function/sleep.mjs +0 -12
  218. package/src/hash/fnv1A.mjs +0 -58
  219. package/src/is.mjs +0 -86
  220. package/src/number/is.mjs +0 -5
  221. package/src/number/isAbove.mjs +0 -6
  222. package/src/number/isAboveOrEqual.mjs +0 -6
  223. package/src/number/isBelow.mjs +0 -6
  224. package/src/number/isBelowOrEqual.mjs +0 -6
  225. package/src/number/isBetween.mjs +0 -13
  226. package/src/number/isInteger.mjs +0 -5
  227. package/src/number/isIntegerAbove.mjs +0 -6
  228. package/src/number/isIntegerAboveOrEqual.mjs +0 -6
  229. package/src/number/isIntegerBelow.mjs +0 -6
  230. package/src/number/isIntegerBelowOrEqual.mjs +0 -6
  231. package/src/number/isIntegerBetween.mjs +0 -13
  232. package/src/number/isNumericalNaN.mjs +0 -5
  233. package/src/number/randomBetween.mjs +0 -11
  234. package/src/number/randomIntBetween.mjs +0 -11
  235. package/src/number/round.mjs +0 -10
  236. package/src/number/toPercentage.mjs +0 -14
  237. package/src/object/define.mjs +0 -12
  238. package/src/object/is.mjs +0 -7
  239. package/src/object/isNotEmpty.mjs +0 -7
  240. package/src/object/merge.mjs +0 -27
  241. package/src/object/pick.mjs +0 -33
  242. package/src/regexp/is.mjs +0 -7
  243. package/src/regexp/sanitize.mjs +0 -12
  244. package/src/string/humanizeBytes.mjs +0 -29
  245. package/src/string/humanizeNumber.mjs +0 -84
  246. package/src/string/is.mjs +0 -5
  247. package/src/string/isBetween.mjs +0 -18
  248. package/src/string/isNotEmpty.mjs +0 -6
  249. package/src/string/shorten.mjs +0 -21
  250. package/string/humanizeBytes.js +0 -23
  251. package/string/humanizeNumber.js +0 -56
  252. package/string/is.js +0 -9
  253. package/string/isBetween.js +0 -14
  254. package/string/isNotEmpty.js +0 -11
  255. package/string/shorten.js +0 -15
@@ -0,0 +1 @@
1
+ export default function isIntegerBetween(val: any, min: number, max: number): boolean;
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function isIntegerBetween(val, min, max) {
4
+ if (!Number.isInteger(val) ||
5
+ !Number.isFinite(min) ||
6
+ !Number.isFinite(max) ||
7
+ min >= max)
8
+ return false;
9
+ return val >= min && val <= max;
10
+ }
11
+ exports.default = isIntegerBetween;
@@ -0,0 +1 @@
1
+ export default function isNumericalNaN(val: any): boolean;
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function isNumericalNaN(val) {
4
+ return Number.isNaN(val) || val === Infinity;
5
+ }
6
+ exports.default = isNumericalNaN;
@@ -0,0 +1 @@
1
+ export default function randomBetween(min?: number, max?: number): number;
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function randomBetween(min = 0, max = 10) {
4
+ if (!Number.isFinite(min) ||
5
+ !Number.isFinite(max))
6
+ throw new TypeError('Min/Max should be numeric');
7
+ return (Math.random() * (max - min)) + min;
8
+ }
9
+ exports.default = randomBetween;
@@ -0,0 +1 @@
1
+ export default function randomIntBetween(min?: number, max?: number): number;
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function randomIntBetween(min = 0, max = 10) {
4
+ if (!Number.isFinite(min) ||
5
+ !Number.isFinite(max))
6
+ throw new TypeError('Min/Max should be numeric');
7
+ return Math.floor((Math.random() * (max - min)) + min);
8
+ }
9
+ exports.default = randomIntBetween;
@@ -0,0 +1 @@
1
+ export default function round(val: number, precision?: number): number;
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function round(val, precision = 0) {
4
+ if (!Number.isFinite(val))
5
+ throw new TypeError('Value should be numeric');
6
+ const exp = Math.pow(10, Number.isInteger(precision) && precision > 0 ? precision : 0);
7
+ const num = (val * exp) * (1 + Number.EPSILON);
8
+ return Math.round(num) / exp;
9
+ }
10
+ exports.default = round;
@@ -0,0 +1 @@
1
+ export default function toPercentage(val: number, precision?: number, min?: number, max?: number): number;
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const round_1 = require("./round");
4
+ function toPercentage(val, precision = 0, min = 0, max = 1) {
5
+ if (!Number.isFinite(val) ||
6
+ !Number.isFinite(min) ||
7
+ !Number.isFinite(max))
8
+ throw new TypeError('value/min/max should be numeric');
9
+ return (0, round_1.default)(((val - min) / (max - min)) * 100, precision);
10
+ }
11
+ exports.default = toPercentage;
@@ -0,0 +1,7 @@
1
+ export default function define(props: {
2
+ [key: string]: any;
3
+ }, obj?: {
4
+ [key: string]: any;
5
+ }): {
6
+ [key: string]: any;
7
+ };
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function define(props, obj = {}) {
4
+ if (Object.prototype.toString.call(props) !== '[object Object]' ||
5
+ Object.prototype.toString.call(obj) !== '[object Object]')
6
+ throw new TypeError('Please pass an object as the value for props and obj');
7
+ return Object.defineProperties(obj, props);
8
+ }
9
+ exports.default = define;
@@ -0,0 +1 @@
1
+ export default function isObject(val: any): boolean;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const PROTO_OBJ = '[object Object]';
4
+ function isObject(val) {
5
+ return Object.prototype.toString.call(val) === PROTO_OBJ;
6
+ }
7
+ exports.default = isObject;
@@ -0,0 +1 @@
1
+ export default function isNotEmptyObject(val: any): boolean;
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function isNotEmptyObject(val) {
4
+ return Object.prototype.toString.call(val) === '[object Object]' && Object.keys(val).length > 0;
5
+ }
6
+ exports.default = isNotEmptyObject;
@@ -0,0 +1,8 @@
1
+ declare function merge(target: {
2
+ [key: string]: any;
3
+ }, source?: {
4
+ [key: string]: any;
5
+ }): {
6
+ [key: string]: any;
7
+ };
8
+ export default merge;
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function merge(target, source = {}) {
4
+ if (Object.prototype.toString.call(target) !== '[object Object]' ||
5
+ Object.prototype.toString.call(source) !== '[object Object]')
6
+ throw new TypeError('Please pass a target and object to merge');
7
+ return Object.keys(target).reduce((acc, key) => {
8
+ if (Object.prototype.toString.call(target[key]) === '[object Object]' &&
9
+ !Array.isArray(target[key])) {
10
+ acc[key] = source[key] ? merge(target[key], source[key]) : target[key];
11
+ }
12
+ else {
13
+ acc[key] = Object.prototype.hasOwnProperty.call(source, key)
14
+ ? source[key]
15
+ : target[key];
16
+ }
17
+ return acc;
18
+ }, {});
19
+ }
20
+ exports.default = merge;
@@ -0,0 +1,5 @@
1
+ export default function pick(obj: {
2
+ [key: string]: any;
3
+ }, keys: string[]): {
4
+ [key: string]: any;
5
+ };
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const get_1 = require("../deep/get");
4
+ const set_1 = require("../deep/set");
5
+ function pick(obj, keys) {
6
+ if (Object.prototype.toString.call(obj) !== '[object Object]' ||
7
+ !Array.isArray(keys) ||
8
+ keys.length === 0)
9
+ throw new TypeError('Please pass an object to pick from and a keys array');
10
+ const map = {};
11
+ let key_deep = false;
12
+ let val;
13
+ for (const key of keys) {
14
+ if (typeof key !== 'string')
15
+ continue;
16
+ const sanitized = key.trim();
17
+ if (sanitized.length === 0)
18
+ continue;
19
+ key_deep = /(\.|\[)/g.test(sanitized);
20
+ val = key_deep
21
+ ? (0, get_1.default)(obj, sanitized)
22
+ : obj[sanitized];
23
+ if (val === undefined)
24
+ continue;
25
+ if (key_deep) {
26
+ (0, set_1.default)(map, sanitized, val);
27
+ }
28
+ else {
29
+ map[sanitized] = val;
30
+ }
31
+ }
32
+ return map;
33
+ }
34
+ exports.default = pick;
@@ -0,0 +1 @@
1
+ export default function isRegExp(val: any): boolean;
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function isRegExp(val) {
4
+ return Object.prototype.toString.call(val) === '[object RegExp]';
5
+ }
6
+ exports.default = isRegExp;
@@ -0,0 +1 @@
1
+ export default function sanitizeRegExp(val: string): string | false;
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function sanitizeRegExp(val) {
4
+ if (typeof val !== 'string')
5
+ return false;
6
+ return val.trim().replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
7
+ }
8
+ exports.default = sanitizeRegExp;
@@ -0,0 +1,8 @@
1
+ interface humanizeBytesOptions {
2
+ delim?: string;
3
+ separator?: string;
4
+ precision?: number;
5
+ units?: string[];
6
+ }
7
+ export default function humanizeBytes(val: number | string, options?: humanizeBytesOptions): string;
8
+ export {};
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const humanizeNumber_1 = require("./humanizeNumber");
4
+ const isNotEmpty_1 = require("../string/isNotEmpty");
5
+ function humanizeBytes(val, options = {}) {
6
+ const has_opts = Object.prototype.toString.call(options) === '[object Object]';
7
+ return (0, humanizeNumber_1.default)(val, {
8
+ delim: has_opts && typeof options.delim === 'string'
9
+ ? options.delim
10
+ : ',',
11
+ separator: has_opts && typeof options.separator === 'string' && options.separator.trim().length > 0
12
+ ? options.separator
13
+ : '.',
14
+ precision: has_opts && Number.isInteger(options.precision) && options.precision >= 0
15
+ ? options.precision
16
+ : 2,
17
+ units: has_opts && Array.isArray(options.units) && options.units.length > 0
18
+ ? options.units.filter(el => (0, isNotEmpty_1.default)(el))
19
+ : [' bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB'],
20
+ divider: 1024,
21
+ real: true,
22
+ });
23
+ }
24
+ exports.default = humanizeBytes;
@@ -0,0 +1,10 @@
1
+ interface humanizeNumberOptions {
2
+ delim?: string;
3
+ separator?: string;
4
+ precision?: number;
5
+ units?: string[] | boolean;
6
+ divider?: number;
7
+ real?: boolean;
8
+ }
9
+ export default function humanizeNumber(val: number | string, options?: humanizeNumberOptions): string;
10
+ export {};
@@ -0,0 +1,60 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const is_1 = require("../boolean/is");
4
+ const is_2 = require("../string/is");
5
+ const round_1 = require("../number/round");
6
+ function humanizeNumber(val, options = {}) {
7
+ const has_opts = Object.prototype.toString.call(options) === '[object Object]';
8
+ const OPTS = {
9
+ delim: has_opts && typeof options.delim === 'string'
10
+ ? options.delim
11
+ : ',',
12
+ separator: has_opts && typeof options.separator === 'string' && options.separator.trim().length > 0
13
+ ? options.separator
14
+ : '.',
15
+ precision: has_opts && Number.isInteger(options.precision) && options.precision >= 0
16
+ ? options.precision
17
+ : 2,
18
+ units: has_opts && ((Array.isArray(options.units) && options.units.length > 0) || options.units === false)
19
+ ? options.units ? options.units.filter(is_2.default) : false
20
+ : ['', 'k', 'm', 'b', 't', 'q'],
21
+ divider: has_opts && Number.isInteger(options.divider) && options.divider > 1
22
+ ? options.divider
23
+ : 1000,
24
+ real: has_opts && (0, is_1.default)(options.real)
25
+ ? options.real
26
+ : false,
27
+ };
28
+ let normalized;
29
+ if (OPTS.real) {
30
+ normalized = typeof val === 'string' ? parseInt(val.trim(), 10) : Number.isFinite(val) ? Math.round(val) : 0;
31
+ }
32
+ else {
33
+ normalized = typeof val === 'string' ? parseFloat(val) : Number.isFinite(val) ? val : 0;
34
+ }
35
+ if (!Number.isFinite(normalized) || normalized === 0) {
36
+ return `0${Array.isArray(OPTS.units) && OPTS.units.length > 0 ? OPTS.units[0] : ''}`;
37
+ }
38
+ const sign = normalized < 0 ? '-' : '';
39
+ normalized = Math.abs(normalized);
40
+ let postfix = '';
41
+ if (Array.isArray(OPTS.units) && OPTS.units.length > 0) {
42
+ let unit_ix = 0;
43
+ while (normalized >= OPTS.divider) {
44
+ unit_ix++;
45
+ normalized = normalized / OPTS.divider;
46
+ if (unit_ix === OPTS.units.length - 1)
47
+ break;
48
+ }
49
+ postfix = OPTS.units[unit_ix];
50
+ }
51
+ normalized = (0, round_1.default)(normalized, OPTS.precision);
52
+ const humanized = `${normalized}`.split('.');
53
+ humanized[0] = humanized[0].split('').reverse().map((char, ix, original) => {
54
+ if (ix > 0 && ix < original.length && ix % 3 === 0)
55
+ return char + OPTS.delim;
56
+ return char;
57
+ }).reverse().join('');
58
+ return `${sign}${humanized.join(OPTS.separator)}${postfix}`;
59
+ }
60
+ exports.default = humanizeNumber;
@@ -0,0 +1 @@
1
+ export default function isString(val: any): boolean;
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function isString(val) {
4
+ return typeof val === 'string';
5
+ }
6
+ exports.default = isString;
@@ -0,0 +1 @@
1
+ export default function isStringBetween(val: any, min: number, max: number, trimmed?: boolean): boolean;
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function isStringBetween(val, min, max, trimmed = true) {
4
+ if (typeof val !== 'string' ||
5
+ !Number.isFinite(min) ||
6
+ min < 0 ||
7
+ !Number.isFinite(max) ||
8
+ max < 0 ||
9
+ min >= max)
10
+ return false;
11
+ const length = (trimmed === true ? val.trim() : val).length;
12
+ return length >= min && length <= max;
13
+ }
14
+ exports.default = isStringBetween;
@@ -0,0 +1 @@
1
+ export default function isNotEmptyString(val: any, trimmed?: boolean): boolean;
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function isNotEmptyString(val, trimmed = true) {
4
+ if (typeof val !== 'string')
5
+ return false;
6
+ return (trimmed === true ? val.trim() : val).length > 0;
7
+ }
8
+ exports.default = isNotEmptyString;
@@ -0,0 +1 @@
1
+ export default function shorten(val: string, length: number, postfix?: string): string;
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function shorten(val, length, postfix = '...') {
4
+ if (typeof val !== 'string')
5
+ return '';
6
+ if (typeof postfix !== 'string' || !Number.isFinite(length) || length <= 0)
7
+ return val;
8
+ const sanitized = val.trim();
9
+ return sanitized.length <= length ? sanitized : `${sanitized.substr(0, length)}${postfix}`;
10
+ }
11
+ exports.default = shorten;