atomic-fns 0.3.5 → 0.4.3

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 (109) hide show
  1. package/README.md +1 -12
  2. package/{core → dist}/collections/BTree.d.ts +6 -6
  3. package/{core → dist}/collections/BTree.js +17 -17
  4. package/{core → dist}/collections/Heap.d.ts +3 -3
  5. package/{core → dist}/collections/Heap.js +0 -0
  6. package/dist/collections/LRUCache.d.ts +80 -0
  7. package/dist/collections/LRUCache.js +126 -0
  8. package/{core → dist}/collections/SortedMap.d.ts +2 -2
  9. package/{core → dist}/collections/SortedMap.js +0 -0
  10. package/{core → dist}/collections/SortedSet.d.ts +3 -3
  11. package/{core → dist}/collections/SortedSet.js +1 -1
  12. package/{core → dist}/collections/SortedTree.d.ts +3 -3
  13. package/{core → dist}/collections/SortedTree.js +1 -1
  14. package/{core → dist}/collections/SplayTree.d.ts +5 -5
  15. package/{core → dist}/collections/SplayTree.js +0 -0
  16. package/{core → dist}/collections/abc.d.ts +0 -0
  17. package/{core → dist}/collections/abc.js +0 -0
  18. package/{core → dist}/collections/deque.d.ts +7 -7
  19. package/{core → dist}/collections/deque.js +6 -8
  20. package/{core → dist}/collections/frozenset.d.ts +0 -0
  21. package/{core → dist}/collections/frozenset.js +3 -6
  22. package/{core → dist}/collections/index.d.ts +207 -105
  23. package/{core → dist}/collections/index.js +179 -436
  24. package/{core → dist}/functools/index.d.ts +30 -16
  25. package/{core → dist}/functools/index.js +34 -12
  26. package/dist/globals/decimal.d.ts +142 -0
  27. package/dist/globals/decimal.js +371 -0
  28. package/{core → dist}/globals/index.d.ts +26 -25
  29. package/{core → dist}/globals/index.js +16 -37
  30. package/dist/i18n/currency.d.ts +24 -0
  31. package/dist/i18n/currency.js +85 -0
  32. package/dist/i18n/date/index.d.ts +204 -0
  33. package/dist/i18n/date/index.js +530 -0
  34. package/dist/i18n/date/utils.d.ts +65 -0
  35. package/dist/i18n/date/utils.js +290 -0
  36. package/dist/i18n/duration.d.ts +112 -0
  37. package/dist/i18n/duration.js +392 -0
  38. package/dist/i18n/format.d.ts +26 -0
  39. package/dist/i18n/format.js +495 -0
  40. package/{core → dist}/i18n/index.d.ts +2 -1
  41. package/{core → dist}/i18n/index.js +2 -1
  42. package/{core → dist}/index.d.ts +0 -0
  43. package/{core → dist}/index.js +0 -0
  44. package/{core → dist}/itertools/index.d.ts +74 -46
  45. package/{core → dist}/itertools/index.js +28 -56
  46. package/{core → dist}/math/index.d.ts +9 -10
  47. package/{core → dist}/math/index.js +3 -1
  48. package/{core → dist}/operators/index.d.ts +4 -4
  49. package/{core → dist}/operators/index.js +2 -8
  50. package/{core → dist}/random/index.d.ts +1 -1
  51. package/{core → dist}/random/index.js +5 -5
  52. package/package.json +28 -42
  53. package/.editorconfig +0 -12
  54. package/.esdoc.json +0 -27
  55. package/.eslintignore +0 -1
  56. package/.eslintrc.json +0 -35
  57. package/.firebaserc +0 -5
  58. package/.prettierrc +0 -19
  59. package/core/collections/BTree.ts +0 -1340
  60. package/core/collections/Heap.ts +0 -189
  61. package/core/collections/LRUCache.d.ts +0 -152
  62. package/core/collections/LRUCache.js +0 -409
  63. package/core/collections/LRUCache.ts +0 -486
  64. package/core/collections/SortedMap.ts +0 -146
  65. package/core/collections/SortedSet.ts +0 -110
  66. package/core/collections/SortedTree.ts +0 -160
  67. package/core/collections/SplayTree.ts +0 -354
  68. package/core/collections/abc.ts +0 -176
  69. package/core/collections/deque.ts +0 -338
  70. package/core/collections/frozenset.ts +0 -37
  71. package/core/collections/index.ts +0 -1024
  72. package/core/collections/test.html +0 -10
  73. package/core/collections/typedArrays.d.ts +0 -31
  74. package/core/collections/typedArrays.js +0 -143
  75. package/core/collections/typedArrays.ts +0 -163
  76. package/core/functools/index.ts +0 -260
  77. package/core/globals/index.ts +0 -481
  78. package/core/i18n/date/format.d.ts +0 -16
  79. package/core/i18n/date/format.js +0 -307
  80. package/core/i18n/date/format.ts +0 -343
  81. package/core/i18n/date/index.d.ts +0 -224
  82. package/core/i18n/date/index.js +0 -387
  83. package/core/i18n/date/index.ts +0 -471
  84. package/core/i18n/date/test.html +0 -67
  85. package/core/i18n/index.ts +0 -8
  86. package/core/index.ts +0 -8
  87. package/core/itertools/index.ts +0 -494
  88. package/core/math/index.ts +0 -152
  89. package/core/operators/index.ts +0 -310
  90. package/core/random/index.ts +0 -66
  91. package/firebase.json +0 -10
  92. package/jasmine.json +0 -14
  93. package/tests/BTree.spec.ts +0 -143
  94. package/tests/Cache.spec.ts +0 -161
  95. package/tests/Heap.spec.ts +0 -66
  96. package/tests/SortedMap.spec.ts +0 -144
  97. package/tests/SortedSet.spec.ts +0 -84
  98. package/tests/SortedTree.spec.ts +0 -164
  99. package/tests/SplayTree.spec.ts +0 -121
  100. package/tests/collections.spec.ts +0 -288
  101. package/tests/deque.spec.ts +0 -107
  102. package/tests/globals.spec.ts +0 -270
  103. package/tests/itertools.spec.ts +0 -266
  104. package/tests/math.spec.ts +0 -25
  105. package/tests/operators.spec.ts +0 -40
  106. package/tests/random.spec.ts +0 -46
  107. package/tsconfig.json +0 -126
  108. package/tsconfig.node.json +0 -18
  109. package/tsconfig.xo.json +0 -9
@@ -1,481 +0,0 @@
1
- /**
2
- * This module includes global functions and constants.
3
- *
4
- * @module Globals
5
- */
6
-
7
- /** This is just a noop function. */
8
- export const noop = () => {}
9
-
10
- /**
11
- * A generic function type with arbitrary arguments and return.
12
- */
13
- export type Function<T = any> = (...args: any) => T
14
-
15
- /**
16
- * An iteratee function used for collection methods.
17
- * @see {@link Collections.filter}
18
- * @see {@link Collections.find}
19
- * @see {@link Collections.forEach}
20
- * @see {@link Collections.index}
21
- * @see {@link Collections.map}
22
- * @see {@link Collections.pick}
23
- * @see {@link Collections.omit}
24
- * @see {@link Collections.uniq}
25
- * @see {@link Collections.sortedUniq}
26
- * @see {@link Collections.groupBy}
27
- */
28
- export type Iteratee<T = any, K = any> = (value: T, key?: K, arr?) => any
29
-
30
- export type Predicate<T = any> = (value: T) => any
31
-
32
- /** A function that always returns `true`. */
33
- export const True = () => true
34
-
35
- /** A function that always returns `false`. */
36
- export const False = () => false
37
-
38
- /**
39
- * A custom error class that inherits from the Error object.
40
- * @class CustomError
41
- * @extends {Error}
42
- */
43
- export class CustomError extends Error {
44
- /**
45
- * Returns a new CustomError with the specified message.
46
- * @param {string} message
47
- * @constructor
48
- */
49
- constructor(message?: string) {
50
- super(message)
51
- this.name = this.constructor.name
52
- if (typeof Error.captureStackTrace === 'function') {
53
- Error.captureStackTrace(this, this.constructor)
54
- } else {
55
- this.stack = new Error(message).stack
56
- }
57
- }
58
- }
59
-
60
- /**
61
- * Custom error to signal an invalid index access.
62
- * @extends {CustomError}
63
- */
64
- export class IndexError extends CustomError {}
65
-
66
- /**
67
- * Raised when a system function returns an I/O failure such as "file not found"
68
- * or "disk full".
69
- * @extends {CustomError}
70
- */
71
- export class IOError extends CustomError {}
72
-
73
- /**
74
- * Custom error to signal an invalid key access.
75
- * @extends {CustomError}
76
- */
77
- export class KeyError extends CustomError {}
78
-
79
- /**
80
- * Custom error to signal an invalid operation.
81
- * @extends {CustomError}
82
- */
83
- export class NotImplementedError extends CustomError {}
84
-
85
- /**
86
- * Custom error to signal an invalid value.
87
- * @extends {CustomError}
88
- */
89
- export class ValueError extends CustomError {}
90
-
91
- /**
92
- * Raised when the second argument of a division or modulo operation is zero.
93
- * @extends {CustomError}
94
- */
95
- export class ZeroDivisionError extends CustomError {}
96
-
97
- /**
98
- * Returns the true type of any value with correct detection for null, Array,
99
- * Object, Promise, Symbol, and NaN. The correct values are inferred from {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag | Symbol.toStringTag} and the value's prototype.
100
- * @param value
101
- * @returns The value type.
102
- */
103
- export function type(value) {
104
- const result = typeof value
105
- if (result === 'object') {
106
- if (value) {
107
- if (value instanceof String) return 'string'
108
- if (value instanceof Boolean) return 'boolean'
109
- if (value instanceof Function) return 'function'
110
- if (value instanceof Array) return 'array'
111
- if (value instanceof Error) return 'error'
112
- if (value[Symbol.toStringTag]) return value[Symbol.toStringTag]
113
-
114
- const className = str(value)
115
- if (className === '[object Window]') return 'object'
116
- if (className.endsWith('Array]') || Array.isArray(value)) {
117
- return 'array'
118
- }
119
-
120
- if (className.endsWith('Function]') || typeof value.call === 'function') {
121
- return 'function'
122
- }
123
-
124
- // Other primitive types
125
- if (className === '[object Promise]' || value instanceof Promise) {
126
- return 'Promise'
127
- }
128
- } else {
129
- return 'null'
130
- }
131
- } else if (result === 'function' && typeof value.call === 'undefined') {
132
- return 'object'
133
- } else if (Number.isNaN(value)) return 'NaN'
134
- return result
135
- }
136
-
137
- /**
138
- * Returns a string representing the object.
139
- * @param obj
140
- * @returns `obj.toString()` or `''` if `obj` is `null` or `undefined`.
141
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString | Object.toString }
142
- */
143
- export const str = (obj) => (obj != null ? obj.toString() : '')
144
-
145
- export function hasOwnProperty(obj, prop) {
146
- return Object.prototype.hasOwnProperty.call(obj, prop)
147
- }
148
-
149
- /** Check if value is a boolean type. */
150
- export const isBool = (x): x is boolean => type(x) === 'boolean'
151
-
152
- /** Check if value is an `Error` type. */
153
- export const isError = (x): x is Error => x instanceof Error
154
-
155
- /** Check if value is an iterable type. */
156
- export const isIterable = (x): x is IterableIterator<any> => {
157
- if (x == null) return false
158
- return typeof x[Symbol.iterator] === 'function'
159
- }
160
-
161
- /** Check if value is a native `Date` type. */
162
- export const isDate = (x): x is Date => x instanceof Date
163
-
164
- /** Check if value is an object type. */
165
- export const isObject = (x): x is Object => typeof x === 'object' && type(x) === 'object'
166
-
167
- /** Check if value is a string type. */
168
- export const isString = (x): x is string => type(x) === 'string'
169
-
170
- /** Check if value is an Array type. */
171
- export const isArray = (x): x is any[] => Array.isArray(x)
172
-
173
- /**
174
- * Check if value is Array-like type.
175
- * A value is considered array-like if it's not a function and has a `.length` number property.
176
- */
177
- export const isArrayLike = (x) => {
178
- const T = type(x)
179
- return T === 'array' || (T === 'object' && isNumber(x.length))
180
- }
181
-
182
- /** Check if value is a number type. */
183
- export const isNumber = (x): x is number => type(x) === 'number'
184
-
185
- /** Check if value is an integer number type. */
186
- export const isInteger = (x): x is number => type(x) === 'number' && Math.floor(x) === x
187
-
188
- /** Check if value is a bigint type. */
189
- export const isBigint = (x): x is BigInt => type(x) === 'bigint'
190
-
191
- /** Check if value is NaN based on `Number.isNaN`. */
192
- export const isNaN = (x): x is typeof NaN => Number.isNaN(x)
193
-
194
- /** Check if value is a Promise type. */
195
- export const isPromise = (x): x is Promise<any> => type(x) === 'Promise'
196
-
197
- /** Check if value is a function type. */
198
- export const isFunction = (x): x is Function => x?.constructor === Function
199
-
200
- /** Check if value is an async function type. */
201
- export const isAsyncFunction = (x) => x?.constructor.name === 'AsyncFunction'
202
-
203
- /** Check if value is a generator function type. */
204
- export const isGenerator = (x): x is Generator => {
205
- return x?.constructor.constructor?.name === 'GeneratorFunction'
206
- }
207
-
208
- /** Check if value is `null` or `undefined`. */
209
- export const isNull = (x): x is null | undefined => x == null
210
-
211
- /** Check if value === `undefined`. */
212
- export function isUndefined(o) {
213
- return typeof o === 'undefined'
214
- }
215
-
216
- /** Check if value is not `null` or `undefined`. */
217
- export const notNull = (x) => x != null
218
-
219
- /** Returns `true` for objects without length or falsy values. */
220
- export const isEmpty = (x) => (len(x) === 0 ? true : !x)
221
-
222
- /** Check if value is a `RegExp` type */
223
- export const isRegExp = (x): x is RegExp => x instanceof RegExp
224
-
225
- /** Check if value is a `Symbol` type */
226
- export const isSymbol = (x): x is symbol => type(x) === 'symbol'
227
-
228
- /** Check if value is a `Set` type. */
229
- export const isSet = <T>(x): x is Set<T> => x instanceof Set
230
-
231
- /** Check if value is a `Map` type. */
232
- export const isMap = <K, V>(x): x is Map<K, V> => x instanceof Map
233
-
234
- /** Check if value is a `WeakSet` type. */
235
- export const isWeakSet = <T extends object>(x): x is WeakSet<T> => x instanceof WeakSet
236
-
237
- /** Check if value is a `WeakMap` type. */
238
- export const isWeakMap = <K extends object, V>(x): x is WeakMap<K, V> => x instanceof WeakMap
239
-
240
- /**
241
- * Returns the number of elements in a collection type.
242
- *
243
- * If `value.length` or `value.size()` is defined, this will be returned.
244
- * If `value` is an `Object`, it returns the number of keys.
245
- * @param value
246
- * @returns The number of elements in the collection or `undefined`.
247
- */
248
- export function len(value) {
249
- if (value == null) return
250
- if (isNumber(value.length)) {
251
- return value.length
252
- }
253
- if (isFunction(value.size)) {
254
- return value.size()
255
- }
256
- if (isNumber(value.size)) {
257
- return value.size
258
- }
259
- if (isObject(value)) {
260
- return Object.keys(value).length
261
- }
262
- }
263
-
264
- /**
265
- * Generates a unique ID using random numbers. If a prefix is given, the ID is appended to it and returned as a string.
266
- * @param {string} [pre=''] The id prefix.
267
- * @returns {number|string} Returns the numeric or string ID.
268
- * @example
269
- ```js
270
- uniqueId()
271
- // => 3445556877
272
-
273
- uniqueId('user_')
274
- // => 'user_1033763188'
275
- ```
276
- */
277
- export const uniqueId = (pre: string = '') =>
278
- // @ts-expect-error
279
- (pre || 0) + ((Math.random() * 1e10) >>> 0)
280
-
281
- /**
282
- * Generates a monotonically increasing, pseudo-random based uuid-v4 string. These are sortable, url-friendly and are 100% unique if the IDs are generated more than 1 millisecond apart. If two IDs are generated at the same millisecond, the chance of collision is still pretty low (1 in 10^15).
283
- * @returns Returns a GUID formatted string.
284
- * @example
285
- ```js
286
- uuid()
287
- // => '183f8ef3-b8f0-4000-81f5-89234c836d00'
288
- ```
289
- */
290
- export const uuid = () => {
291
- const u = Date.now().toString(16) + Math.random().toString(16) + '0'.repeat(16)
292
- return [u.substr(0, 8), u.substr(8, 4), '4000-8' + u.substr(13, 3), u.substr(16, 12)].join('-')
293
- }
294
-
295
- /**
296
- * Checks if `obj.key` is a function, and calls it with any given `args`.
297
- * @param {*} obj
298
- * @param {PropertyKey} key
299
- * @param {...any[]} args
300
- * @return `obj.key(...args)` or `undefined`.
301
- */
302
- export function call(obj: any, key: PropertyKey, ...args: any[]) {
303
- if (isFunction(get(key, obj))) {
304
- return obj[key](...args)
305
- }
306
- }
307
-
308
- /** Convert number to unicode character */
309
- export const chr = (x: number) => String.fromCodePoint(x)
310
-
311
- /** Convert character to Unicode code point */
312
- export const ord = (x: string) => x.charCodeAt(0)
313
-
314
- /**
315
- * Returns an array of the own enumerable property names of `object`.
316
- * @param object The given object.
317
- * @returns The array of object keys.
318
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys Object.keys()}
319
- */
320
- export const keys = (object: Object) => Object.keys(object)
321
-
322
- /**
323
- * Returns an array of the own enumerable property values of `object`.
324
- * @param object The given object.
325
- * @returns The array of object keys.
326
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values Object.values()}
327
- */
328
- export const values = (object) => Object.values(object)
329
-
330
- /**
331
- * Check if a given property is present in a given object.
332
- * @param obj The object to check.
333
- * @param attr A property key name.
334
- * @returns `true` if the object has the property name.
335
- */
336
- export const has = (obj, attr: PropertyKey) => obj && attr in obj
337
-
338
- /**
339
- * Check if the attribute is present in the object or return a default value instead.
340
- * @param {PropertyKey} key
341
- * @param {*} obj
342
- * @param {*} [value=undefined]
343
- * @return The property value or default value.
344
- */
345
- export function get(key: PropertyKey | PropertyKey[], obj, value: any = undefined) {
346
- if (obj == null) return value
347
-
348
- let paths = Array.isArray(key) ? key : [key]
349
- if (typeof key === 'string') {
350
- paths = key.split('.')
351
- }
352
-
353
- try {
354
- let result = obj
355
- for (const k of paths) {
356
- result = result[k]
357
- }
358
- return result === undefined ? value : result
359
- } catch (error) {
360
- return value
361
- }
362
- }
363
-
364
- /**
365
- * Deletes a given property key from an object.
366
- * @param attr The property name.
367
- * @param x The given object.
368
- * @returns The modified object.
369
- */
370
- export function del(attr: PropertyKey, x) {
371
- if (x != null) delete x[attr]
372
- return x
373
- }
374
-
375
- /**
376
- * Adds a property to an object, or modifies the existing value.
377
- * @param attr The name or Symbol of the property to be defined or modified.
378
- * @param obj The container object.
379
- * @param value The value associated with the property
380
- * @param {boolean} [writable=false] If `true` the value may be changed later. Defaults to `false`.
381
- * @param {boolean} [enumerable=false] If `true` this property shows up during enumeration of the properties in the object. Defaults to `false`.
382
- * @returns
383
- */
384
- export function set(attr: PropertyKey, obj, value, writable = false, enumerable = false) {
385
- return Object.defineProperty(obj, attr, {
386
- value,
387
- enumerable,
388
- writable
389
- })
390
- }
391
-
392
- export const HASH_KEY = Symbol.for('HASH_KEY')
393
-
394
- /**
395
- * Return a hash value for a given object. The hash will be the same for subsequent invocations.
396
- * @param obj The given object.
397
- * @returns The hash value.
398
- */
399
- export function hash(obj) {
400
- if (typeof obj === 'string') {
401
- return hashCode(obj)
402
- }
403
-
404
- if (typeof obj === 'object') {
405
- if (get(HASH_KEY, obj) == null) {
406
- return obj[HASH_KEY]
407
- }
408
- obj[HASH_KEY] = uniqueId()
409
- return obj[HASH_KEY]
410
- }
411
-
412
- return obj
413
- }
414
-
415
- /**
416
- * A hash value generator for strings.
417
- * @param {string} str The given string.
418
- * @returns {number} The hash value of the string.
419
- * @see {@link http://isthe.com/chongo/tech/comp/fnv/ FNV hash}
420
- */
421
- export function hashCode(str: string) {
422
- const FNV1_32A_INIT = 0x811c9dc5
423
- let hval = FNV1_32A_INIT
424
- for (let i = 0; i < str.length; ++i) {
425
- hval ^= str.charCodeAt(i)
426
- hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24)
427
- }
428
- return hval >>> 0
429
- }
430
-
431
- /**
432
- * Converts a number to a binary string.
433
- * @param n The given number.
434
- * @returns The binary string representation of `n`.
435
- */
436
- export const bin = (n: number) => n.toString(2)
437
-
438
- /**
439
- * Converts a number to a hexadecimal string.
440
- * @param n The given number.
441
- * @returns The hexadecimal string representation of `n`.
442
- */
443
- export const hex = (n: number) => n.toString(16)
444
-
445
- /**
446
- * Converts a number to an octal string.
447
- * @param n The given number.
448
- * @returns The octal string representation of `n`.
449
- */
450
- export const oct = (n: number) => n.toString(8)
451
-
452
- /**
453
- * Returns a floating point number constructed from a number or string `x`.
454
- * @param x The number or string.
455
- * @returns A floating point number parsed from the given value or `NaN`.
456
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat parseFloat}
457
- */
458
- export const float = (x) => parseFloat(x)
459
-
460
- /**
461
- * Returns an integer number constructed from a number or string `x`.
462
- * @param x The number or string.
463
- * @returns An integer number parsed from the given value or `NaN`.
464
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt parseInt}
465
- */
466
- export const int = (x, base = 10) => parseInt(x, base)
467
-
468
- /**
469
- * Converts the value to an array using `Array.from()`.
470
- * @param value
471
- * @returns A new array value.
472
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from Array.from()}
473
- */
474
- export const list = (value?) => (value ? Array.from(value) : [])
475
-
476
- /**
477
- * Retrieve the next item from the iterator by calling it's `next()` method.
478
- * @param iter The iterator.
479
- * @returns The next value from the iterator.
480
- */
481
- export const next = (iter: Iterator<any> | Generator) => iter.next().value
@@ -1,16 +0,0 @@
1
- /**
2
- * Returns a new Date from the given arguments.
3
- * @param {string | number | Date} date The date value
4
- * @param {?boolean} [utc=false] Interprets the given value as a UTC date
5
- * @returns {Date} The new date object
6
- */
7
- export declare function getDate(date: string | number | Date, utc?: boolean): Date;
8
- /**
9
- * Formats a date using a formatting string in the {@link https://strftime.org/ strftime} format, in any given locale.
10
- * @param {string} fmt The format string to apply
11
- * @param {number | Date} date The date value
12
- * @param {?string} locale The locale to use when formatting (default is system locale).
13
- * @returns {string} The string representation of date
14
- * @see {@link https://strftime.org/ strftime format}
15
- */
16
- export declare function format(fmt: string, date: number | Date, locale?: any): string;