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
@@ -3,12 +3,13 @@
3
3
  *
4
4
  * @module Globals
5
5
  */
6
+ export * from './decimal.js';
6
7
  /** This is just a noop function. */
7
8
  export declare const noop: () => void;
8
9
  /**
9
10
  * A generic function type with arbitrary arguments and return.
10
11
  */
11
- export declare type Function<T = any> = (...args: any) => T;
12
+ export declare type Function<TReturn = any> = (...args: any) => TReturn;
12
13
  /**
13
14
  * An iteratee function used for collection methods.
14
15
  * @see {@link Collections.filter}
@@ -22,8 +23,8 @@ export declare type Function<T = any> = (...args: any) => T;
22
23
  * @see {@link Collections.sortedUniq}
23
24
  * @see {@link Collections.groupBy}
24
25
  */
25
- export declare type Iteratee<T = any, K = any> = (value: T, key?: K, arr?: any) => any;
26
- export declare type Predicate<T = any> = (value: T) => any;
26
+ export declare type Iteratee<T = any, K = any, TResult = any> = (value: T, key?: K, arr?: any) => TResult;
27
+ export declare type Predicate<T = any, TReturn = any> = (value: T) => TReturn;
27
28
  /** A function that always returns `true`. */
28
29
  export declare const True: () => boolean;
29
30
  /** A function that always returns `false`. */
@@ -79,12 +80,12 @@ export declare class ValueError extends CustomError {
79
80
  export declare class ZeroDivisionError extends CustomError {
80
81
  }
81
82
  /**
82
- * Returns the true type of any value with correct detection for null, Array,
83
- * 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.
83
+ * Returns the true type of any value with correct detection for `null`, `Array`,
84
+ * `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.
84
85
  * @param value
85
86
  * @returns The value type.
86
87
  */
87
- export declare function type(value: any): any;
88
+ export declare function type(value: any): string;
88
89
  /**
89
90
  * Returns a string representing the object.
90
91
  * @param obj
@@ -92,7 +93,6 @@ export declare function type(value: any): any;
92
93
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString | Object.toString }
93
94
  */
94
95
  export declare const str: (obj: any) => any;
95
- export declare function hasOwnProperty(obj: any, prop: any): boolean;
96
96
  /** Check if value is a boolean type. */
97
97
  export declare const isBool: (x: any) => x is boolean;
98
98
  /** Check if value is an `Error` type. */
@@ -118,8 +118,6 @@ export declare const isNumber: (x: any) => x is number;
118
118
  export declare const isInteger: (x: any) => x is number;
119
119
  /** Check if value is a bigint type. */
120
120
  export declare const isBigint: (x: any) => x is BigInt;
121
- /** Check if value is NaN based on `Number.isNaN`. */
122
- export declare const isNaN: (x: any) => x is number;
123
121
  /** Check if value is a Promise type. */
124
122
  export declare const isPromise: (x: any) => x is Promise<any>;
125
123
  /** Check if value is a function type. */
@@ -129,9 +127,9 @@ export declare const isAsyncFunction: (x: any) => boolean;
129
127
  /** Check if value is a generator function type. */
130
128
  export declare const isGenerator: (x: any) => x is Generator<unknown, any, unknown>;
131
129
  /** Check if value is `null` or `undefined`. */
132
- export declare const isNull: (x: any) => x is null | undefined;
130
+ export declare const isNull: (x: any) => x is null;
133
131
  /** Check if value === `undefined`. */
134
- export declare function isUndefined(o: any): boolean;
132
+ export declare const isUndefined: (x: any) => x is undefined;
135
133
  /** Check if value is not `null` or `undefined`. */
136
134
  export declare const notNull: (x: any) => boolean;
137
135
  /** Returns `true` for objects without length or falsy values. */
@@ -156,7 +154,7 @@ export declare const isWeakMap: <K extends object, V>(x: any) => x is WeakMap<K,
156
154
  * @param value
157
155
  * @returns The number of elements in the collection or `undefined`.
158
156
  */
159
- export declare function len(value: any): any;
157
+ export declare function len(value: any): number;
160
158
  /**
161
159
  * Generates a unique ID using random numbers. If a prefix is given, the ID is appended to it and returned as a string.
162
160
  * @param {string} [pre=''] The id prefix.
@@ -164,20 +162,20 @@ export declare function len(value: any): any;
164
162
  * @example
165
163
  ```js
166
164
  uniqueId()
167
- // => 3445556877
165
+ // 3445556877
168
166
 
169
167
  uniqueId('user_')
170
- // => 'user_1033763188'
168
+ // 'user_1033763188'
171
169
  ```
172
170
  */
173
- export declare const uniqueId: (pre?: string) => any;
171
+ export declare const uniqueId: (pre?: string) => string;
174
172
  /**
175
173
  * 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).
176
174
  * @returns Returns a GUID formatted string.
177
175
  * @example
178
176
  ```js
179
177
  uuid()
180
- // => '183f8ef3-b8f0-4000-81f5-89234c836d00'
178
+ // '183f8ef3-b8f0-4000-81f5-89234c836d00'
181
179
  ```
182
180
  */
183
181
  export declare const uuid: () => string;
@@ -213,7 +211,7 @@ export declare const values: (object: any) => unknown[];
213
211
  * @param attr A property key name.
214
212
  * @returns `true` if the object has the property name.
215
213
  */
216
- export declare const has: (obj: any, attr: PropertyKey) => any;
214
+ export declare const has: (obj: any, attr: PropertyKey) => boolean;
217
215
  /**
218
216
  * Check if the attribute is present in the object or return a default value instead.
219
217
  * @param {PropertyKey} key
@@ -221,14 +219,15 @@ export declare const has: (obj: any, attr: PropertyKey) => any;
221
219
  * @param {*} [value=undefined]
222
220
  * @return The property value or default value.
223
221
  */
224
- export declare function get(key: PropertyKey | PropertyKey[], obj: any, value?: any): any;
222
+ export declare function get<T>(key: PropertyKey, obj: T, value?: any): any;
223
+ export declare function get<T>(key: PropertyKey[], obj: T, value?: any): any;
225
224
  /**
226
225
  * Deletes a given property key from an object.
227
226
  * @param attr The property name.
228
227
  * @param x The given object.
229
228
  * @returns The modified object.
230
229
  */
231
- export declare function del(attr: PropertyKey, x: any): any;
230
+ export declare function del<T>(attr: PropertyKey, x: T): T;
232
231
  /**
233
232
  * Adds a property to an object, or modifies the existing value.
234
233
  * @param attr The name or Symbol of the property to be defined or modified.
@@ -245,7 +244,8 @@ export declare const HASH_KEY: unique symbol;
245
244
  * @param obj The given object.
246
245
  * @returns The hash value.
247
246
  */
248
- export declare function hash(obj: any): any;
247
+ export declare function hash(obj: string): number;
248
+ export declare function hash<T>(obj: T): T;
249
249
  /**
250
250
  * A hash value generator for strings.
251
251
  * @param {string} str The given string.
@@ -277,24 +277,25 @@ export declare const oct: (n: number) => string;
277
277
  * @returns A floating point number parsed from the given value or `NaN`.
278
278
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat parseFloat}
279
279
  */
280
- export declare const float: (x: any) => number;
280
+ export declare const float: (x: string) => number;
281
281
  /**
282
282
  * Returns an integer number constructed from a number or string `x`.
283
283
  * @param x The number or string.
284
284
  * @returns An integer number parsed from the given value or `NaN`.
285
285
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt parseInt}
286
286
  */
287
- export declare const int: (x: any, base?: number) => number;
287
+ export declare const int: (x: string, base?: number) => number;
288
288
  /**
289
289
  * Converts the value to an array using `Array.from()`.
290
290
  * @param value
291
291
  * @returns A new array value.
292
292
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from Array.from()}
293
293
  */
294
- export declare const list: (value?: any) => unknown[];
294
+ export declare const list: <T>(value?: any) => T[];
295
295
  /**
296
- * Retrieve the next item from the iterator by calling it's `next()` method.
296
+ * Retrieve the next item from the iterator by calling its `next()` method.
297
297
  * @param iter The iterator.
298
298
  * @returns The next value from the iterator.
299
299
  */
300
- export declare const next: (iter: Iterator<any> | Generator) => any;
300
+ export declare function next<T>(iter: Iterator<T>): T | undefined;
301
+ export declare function next<T>(iter: Generator<any, T>): T | undefined;
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * @module Globals
5
5
  */
6
+ export * from './decimal.js';
6
7
  /** This is just a noop function. */
7
8
  export const noop = () => { };
8
9
  /** A function that always returns `true`. */
@@ -69,8 +70,8 @@ export class ValueError extends CustomError {
69
70
  export class ZeroDivisionError extends CustomError {
70
71
  }
71
72
  /**
72
- * Returns the true type of any value with correct detection for null, Array,
73
- * 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.
73
+ * Returns the true type of any value with correct detection for `null`, `Array`,
74
+ * `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.
74
75
  * @param value
75
76
  * @returns The value type.
76
77
  */
@@ -122,9 +123,6 @@ export function type(value) {
122
123
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString | Object.toString }
123
124
  */
124
125
  export const str = (obj) => (obj != null ? obj.toString() : '');
125
- export function hasOwnProperty(obj, prop) {
126
- return Object.prototype.hasOwnProperty.call(obj, prop);
127
- }
128
126
  /** Check if value is a boolean type. */
129
127
  export const isBool = (x) => type(x) === 'boolean';
130
128
  /** Check if value is an `Error` type. */
@@ -138,7 +136,7 @@ export const isIterable = (x) => {
138
136
  /** Check if value is a native `Date` type. */
139
137
  export const isDate = (x) => x instanceof Date;
140
138
  /** Check if value is an object type. */
141
- export const isObject = (x) => typeof x === 'object' && type(x) === 'object';
139
+ export const isObject = (x) => type(x) === 'object';
142
140
  /** Check if value is a string type. */
143
141
  export const isString = (x) => type(x) === 'string';
144
142
  /** Check if value is an Array type. */
@@ -154,11 +152,9 @@ export const isArrayLike = (x) => {
154
152
  /** Check if value is a number type. */
155
153
  export const isNumber = (x) => type(x) === 'number';
156
154
  /** Check if value is an integer number type. */
157
- export const isInteger = (x) => type(x) === 'number' && Math.floor(x) === x;
155
+ export const isInteger = (x) => type(x) === 'number' && Math.trunc(x) === x;
158
156
  /** Check if value is a bigint type. */
159
157
  export const isBigint = (x) => type(x) === 'bigint';
160
- /** Check if value is NaN based on `Number.isNaN`. */
161
- export const isNaN = (x) => Number.isNaN(x);
162
158
  /** Check if value is a Promise type. */
163
159
  export const isPromise = (x) => type(x) === 'Promise';
164
160
  /** Check if value is a function type. */
@@ -172,9 +168,7 @@ export const isGenerator = (x) => {
172
168
  /** Check if value is `null` or `undefined`. */
173
169
  export const isNull = (x) => x == null;
174
170
  /** Check if value === `undefined`. */
175
- export function isUndefined(o) {
176
- return typeof o === 'undefined';
177
- }
171
+ export const isUndefined = (x) => x === undefined;
178
172
  /** Check if value is not `null` or `undefined`. */
179
173
  export const notNull = (x) => x != null;
180
174
  /** Returns `true` for objects without length or falsy values. */
@@ -205,12 +199,12 @@ export function len(value) {
205
199
  if (isNumber(value.length)) {
206
200
  return value.length;
207
201
  }
208
- if (isFunction(value.size)) {
209
- return value.size();
210
- }
211
202
  if (isNumber(value.size)) {
212
203
  return value.size;
213
204
  }
205
+ if (isFunction(value.size)) {
206
+ return value.size();
207
+ }
214
208
  if (isObject(value)) {
215
209
  return Object.keys(value).length;
216
210
  }
@@ -222,10 +216,10 @@ export function len(value) {
222
216
  * @example
223
217
  ```js
224
218
  uniqueId()
225
- // => 3445556877
219
+ // 3445556877
226
220
 
227
221
  uniqueId('user_')
228
- // => 'user_1033763188'
222
+ // 'user_1033763188'
229
223
  ```
230
224
  */
231
225
  export const uniqueId = (pre = '') =>
@@ -237,7 +231,7 @@ export const uniqueId = (pre = '') =>
237
231
  * @example
238
232
  ```js
239
233
  uuid()
240
- // => '183f8ef3-b8f0-4000-81f5-89234c836d00'
234
+ // '183f8ef3-b8f0-4000-81f5-89234c836d00'
241
235
  ```
242
236
  */
243
237
  export const uuid = () => {
@@ -281,14 +275,7 @@ export const values = (object) => Object.values(object);
281
275
  * @returns `true` if the object has the property name.
282
276
  */
283
277
  export const has = (obj, attr) => obj && attr in obj;
284
- /**
285
- * Check if the attribute is present in the object or return a default value instead.
286
- * @param {PropertyKey} key
287
- * @param {*} obj
288
- * @param {*} [value=undefined]
289
- * @return The property value or default value.
290
- */
291
- export function get(key, obj, value = undefined) {
278
+ export function get(key, obj, value) {
292
279
  if (obj == null)
293
280
  return value;
294
281
  let paths = Array.isArray(key) ? key : [key];
@@ -334,11 +321,6 @@ export function set(attr, obj, value, writable = false, enumerable = false) {
334
321
  });
335
322
  }
336
323
  export const HASH_KEY = Symbol.for('HASH_KEY');
337
- /**
338
- * Return a hash value for a given object. The hash will be the same for subsequent invocations.
339
- * @param obj The given object.
340
- * @returns The hash value.
341
- */
342
324
  export function hash(obj) {
343
325
  if (typeof obj === 'string') {
344
326
  return hashCode(obj);
@@ -406,9 +388,6 @@ export const int = (x, base = 10) => parseInt(x, base);
406
388
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from Array.from()}
407
389
  */
408
390
  export const list = (value) => (value ? Array.from(value) : []);
409
- /**
410
- * Retrieve the next item from the iterator by calling it's `next()` method.
411
- * @param iter The iterator.
412
- * @returns The next value from the iterator.
413
- */
414
- export const next = (iter) => iter.next().value;
391
+ export function next(iter) {
392
+ return iter.next().value;
393
+ }
@@ -0,0 +1,24 @@
1
+ import { Decimal } from '../globals/decimal.js';
2
+ /**
3
+ * Currency represents a local currency amount that can be formatted using the `Intl` apis.
4
+ */
5
+ export declare class Currency extends Decimal {
6
+ locale: string;
7
+ currency: string;
8
+ numberFormat: Intl.NumberFormat;
9
+ options: Intl.NumberFormatOptions;
10
+ constructor(amount: any, currency: string, locale?: string, opts?: Intl.NumberFormatOptions);
11
+ clone(n: any): Currency;
12
+ negated(): Currency;
13
+ add(x: any): Currency;
14
+ sub(x: any): Currency;
15
+ div(x: any): Currency;
16
+ mul(x: any): Currency;
17
+ toDecimal(): any;
18
+ toString(): string;
19
+ format(opts?: Intl.NumberFormatOptions, locale?: string): string;
20
+ displayName(): string;
21
+ accounting(): string;
22
+ precision(digits?: number): string;
23
+ eq(x: any): any;
24
+ }
@@ -0,0 +1,85 @@
1
+ import { defaults } from '../collections/index.js';
2
+ import { isObject } from '../globals/index.js';
3
+ import { Decimal } from '../globals/decimal.js';
4
+ /**
5
+ * Currency represents a local currency amount that can be formatted using the `Intl` apis.
6
+ */
7
+ export class Currency extends Decimal {
8
+ locale;
9
+ currency;
10
+ numberFormat;
11
+ options = {
12
+ style: 'currency',
13
+ currencyDisplay: 'symbol',
14
+ maximumFractionDigits: 20
15
+ };
16
+ constructor(amount, currency, locale, opts = {}) {
17
+ super(amount);
18
+ if (isObject(locale)) {
19
+ opts = locale;
20
+ locale = undefined;
21
+ }
22
+ const systemLocale = new Intl.NumberFormat(locale, defaults(opts, { currency }, this.options));
23
+ const resolved = systemLocale.resolvedOptions();
24
+ this.numberFormat = systemLocale;
25
+ this.options.currency = currency;
26
+ this.currency = resolved.currency;
27
+ this.locale = resolved.locale;
28
+ }
29
+ // @ts-expect-error overrides
30
+ clone(n) {
31
+ return new Currency(n, this.currency, this.locale, this.options);
32
+ }
33
+ // @ts-expect-error overrides
34
+ negated() {
35
+ const n = super.negated.call(this);
36
+ return this.clone(n);
37
+ }
38
+ // @ts-expect-error overrides
39
+ add(x) {
40
+ const n = super.add.call(this.toDecimal(), x);
41
+ return this.clone(n);
42
+ }
43
+ // @ts-expect-error overrides
44
+ sub(x) {
45
+ const n = super.sub.call(this.toDecimal(), x);
46
+ return this.clone(n);
47
+ }
48
+ // @ts-expect-error overrides
49
+ div(x) {
50
+ const n = super.div.call(this.toDecimal(), x);
51
+ return this.clone(n);
52
+ }
53
+ // @ts-expect-error overrides
54
+ mul(x) {
55
+ const n = super.mul.call(this.toDecimal(), x);
56
+ return this.clone(n);
57
+ }
58
+ toDecimal() {
59
+ return super.clone.call(this);
60
+ }
61
+ toString() {
62
+ const number = this.toNumber();
63
+ return this.numberFormat.format(number);
64
+ }
65
+ format(opts = {}, locale) {
66
+ const number = this.toNumber();
67
+ opts = defaults(opts, this.options);
68
+ return new Intl.NumberFormat(locale ?? this.locale, opts).format(number);
69
+ }
70
+ displayName() {
71
+ return this.format({ currencyDisplay: 'name' });
72
+ }
73
+ accounting() {
74
+ return this.format({ currencySign: 'accounting' });
75
+ }
76
+ precision(digits) {
77
+ return this.format({ maximumFractionDigits: digits });
78
+ }
79
+ eq(x) {
80
+ if (x?.currency && x.currency !== this.currency) {
81
+ return false;
82
+ }
83
+ return super.eq.call(this, x);
84
+ }
85
+ }
@@ -0,0 +1,204 @@
1
+ import { Duration, DurationUnit, TDuration } from '../duration.js';
2
+ import { asDate, formatDate, strftime } from '../format.js';
3
+ import { DateObject, daysInMonth, daysInYear, isLeapYear, maxDate, minDate, weeksInYear } from './utils.js';
4
+ export { asDate, daysInMonth, daysInYear, formatDate, isLeapYear, maxDate, minDate, strftime, weeksInYear };
5
+ export { DateObject };
6
+ export declare type DateInput = number | string | Date;
7
+ export declare type DateLike = DateInput | IntlDate | DateObject;
8
+ /**
9
+ * Creates a date tied to a given locale (default system locale) which can be formatted in that locale's language using the native {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl Intl Apis} directly or using a formatting string.
10
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl Intl Apis}
11
+ */
12
+ export declare class IntlDate {
13
+ private _date;
14
+ readonly locale?: string;
15
+ intlRelativeFormat: Intl.RelativeTimeFormat;
16
+ /** Parses the provided value as UTC date or returns the current UTC date. */
17
+ static UTC(value?: DateLike, locale?: string): IntlDate;
18
+ /** Returns the current local date and time.*/
19
+ static now(): IntlDate;
20
+ /** Creates a new date from a Unix timestamp (seconds since the unix epoch) */
21
+ static unix(seconds: number): IntlDate;
22
+ /**
23
+ * Creates a new `IntlDate` in local time and specified locale (default is system locale).
24
+ * **Note:** The allowed values for `month` start at 1, which is different from legacy `Date`
25
+ * @param {DateLike} obj The date value (default is current local time)
26
+ * @param {Object} opts The options for this date
27
+ * @param {boolean?} opts.utc Converts input or current time to UTC
28
+ * @param {string?} opts.locale A locale string to use for this date
29
+ * @returns
30
+ */
31
+ constructor(obj?: DateLike, { locale, utc }?: any);
32
+ /** Get the date's year. */
33
+ get year(): number;
34
+ /** Get the this date's month as a number from 1 to 12, inclusive. */
35
+ get month(): number;
36
+ /** Returns the weekday as a number between 1 and 7, inclusive, where Monday is 1 and Sunday is 7. */
37
+ get dayOfWeek(): number;
38
+ /** Get the this date's current day of the month. */
39
+ get day(): number;
40
+ /** Get the this date's current hour. */
41
+ get hour(): number;
42
+ /** Get the this date's current minute. */
43
+ get minute(): number;
44
+ /** Get the this date's current second. */
45
+ get second(): number;
46
+ /** Get the this date's current millisecond. */
47
+ get millisecond(): number;
48
+ isValid(): boolean;
49
+ /** Get the number of days in this date's month. */
50
+ daysInMonth(): number;
51
+ /** Get the number of days in this date's year. */
52
+ daysInYear(): number;
53
+ dayOfYear(): number;
54
+ /** Returns `true` if this date's year is a leap year. */
55
+ isLeapYear(): boolean;
56
+ /** Gets the number of weeks according to locale in the current year. */
57
+ weeksInYear(): number;
58
+ /** Gets the number of weeks in the current year, according to ISO weeks. */
59
+ isoWeeksInYear(): number;
60
+ /** Returns the current week of the year. */
61
+ week(): any;
62
+ /** Returns the ISO week of the year. */
63
+ isoWeek(): any;
64
+ /**
65
+ * Returns a localized string representation of this date.
66
+ * @param {Intl.DateTimeFormatOptions} opts The options to use for the format
67
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat Intl.DateTimeFormat()}
68
+ */
69
+ toString(opts?: Intl.DateTimeFormatOptions): string;
70
+ /**
71
+ * Returns a localized string representation of this date, according to the given format string. Format codes use the same specification as {@link https://momentjs.com/docs/#/displaying/format/ moment}.
72
+ * @param {string} str The format string to use
73
+ * @see {@link https://momentjs.com/docs/#/displaying/format/ List of formats}
74
+ * @example
75
+ ```js
76
+ new IntlDate().format('MM/DD/YYYY') // '10/31/2022'
77
+ ```
78
+ */
79
+ format(str: string): string;
80
+ /**
81
+ * Returns a new copy of the native `Date` object used by this instance.
82
+ * @returns {Date} A new `Date` object
83
+ */
84
+ toDate(): Date;
85
+ /**
86
+ * Returns the number of seconds since the Unix Epoch (January 1, 1970 UTC).
87
+ * @see {@link IntlDate.timestamp}
88
+ * @see {@link IntlDate.unix}
89
+ * @example
90
+ ```js
91
+ new IntlDate().toSeconds() // 1318874398
92
+ ```
93
+ */
94
+ toSeconds(): number;
95
+ /**
96
+ * Returns the number of seconds since the Unix Epoch (January 1, 1970 UTC).
97
+ * @see {@link IntlDate.toSeconds}
98
+ * @see {@link IntlDate.unix}
99
+ * @example
100
+ ```js
101
+ new IntlDate().timestamp() // 1318874398
102
+ ```
103
+ */
104
+ timestamp(): number;
105
+ /**
106
+ * Returns the number of seconds since the Unix Epoch (January 1, 1970 UTC).
107
+ * @see {@link IntlDate.toSeconds}
108
+ * @see {@link IntlDate.timestamp}
109
+ * @example
110
+ ```js
111
+ new IntlDate().unix() // 1318874398
112
+ ```
113
+ */
114
+ unix(): number;
115
+ /** Formats a string to the ISO8601 standard.
116
+ * @example
117
+ ```js
118
+ new IntlDate().toISOString() // '2022-10-31T22:44:30.652Z'
119
+ ```
120
+ */
121
+ toISOString(): string;
122
+ /** Returns the date part formatted as ISO8601.
123
+ * @example
124
+ ```js
125
+ new IntlDate().toISODate() // '2022-10-31'
126
+ ```
127
+ */
128
+ toISODate(): string;
129
+ /** Returns the time part formatted as ISO8601.
130
+ * @example
131
+ ```js
132
+ new IntlDate().toISOTime() // 'T22:44:30.652Z'
133
+ ```
134
+ */
135
+ toISOTime(): string;
136
+ /**
137
+ * Returns an object containing year, month, day-of-month, hours, minutes, seconds, milliseconds.
138
+ * @returns {Object} An object like `{year, month, date, hours, minutes, seconds, ms}`
139
+ */
140
+ toObject(): DateObject;
141
+ /** Returns the number of milliseconds since the Unix Epoch (January 1, 1970 UTC) */
142
+ getTime(): number;
143
+ /** Alias of {@link IntlDate.getTime} */
144
+ valueOf(): number;
145
+ /** Returns the timezone string name */
146
+ zoneName(): string;
147
+ /** Returns the timezone GMT offset as a string */
148
+ zone(): string;
149
+ /** Returns the difference in `minutes` between this date and UTC */
150
+ utcOffset(): number;
151
+ /**
152
+ * Check if this date is before another date. The other value will be parsed as an `IntlDate` if not already so.
153
+ * @param {DateLike} other Another date or date like object
154
+ * @returns {boolean} Returns `true` if this date is before the given value
155
+ */
156
+ isBefore(other: DateLike): boolean;
157
+ /**
158
+ * Check if this date is strictly after the given `start` and before `stop` dates. The values will be parsed as an `IntlDate` if not already so.
159
+ * @param {DateLike} start The smaller date
160
+ * @param {DateLike} stop The larger date
161
+ * @returns {boolean} Returns `true` if this date is greater than `start` and less than `stop`.
162
+ */
163
+ isBetween(start: DateLike, stop: DateLike): boolean;
164
+ /**
165
+ * Check if this date is after another date. The other value will be parsed as an `IntlDate` if not already so.
166
+ * @param {DateLike} other Another date or date like object
167
+ * @returns {boolean} Returns `true` if this date is after the given value
168
+ */
169
+ isAfter(other: DateLike): boolean;
170
+ /**
171
+ * Check if this date is the same as `other`.
172
+ * @param other Another date object
173
+ * @returns {boolean} Returns `true` if this date is the same as other
174
+ */
175
+ isSame(other: Date | IntlDate): boolean;
176
+ lt(other: Date | IntlDate): boolean;
177
+ eq(other: Date | IntlDate): boolean;
178
+ compare(other: Date | IntlDate): number;
179
+ set(values: DateObject): IntlDate;
180
+ get relativeFormat(): Intl.RelativeTimeFormat;
181
+ relativeTime(n: number, unit?: Intl.RelativeTimeFormatUnit): string;
182
+ fromNow(unit?: Intl.RelativeTimeFormatUnit): string;
183
+ from(other: DateLike, unit?: Intl.RelativeTimeFormatUnit): string;
184
+ toNow(unit?: Intl.RelativeTimeFormatUnit): string;
185
+ to(other: DateLike, unit?: Intl.RelativeTimeFormatUnit): string;
186
+ diff(other: DateLike, unit?: DurationUnit, exact?: boolean): number;
187
+ add(duration: TDuration, exact?: boolean): IntlDate;
188
+ subtract(duration: TDuration, exact?: boolean): IntlDate;
189
+ startOf(unit: DurationUnit): IntlDate;
190
+ endOf(unit: DurationUnit): IntlDate;
191
+ clone(date?: DateLike): IntlDate;
192
+ static max(...args: any[]): any;
193
+ static min(...args: any[]): any;
194
+ inspect(): string;
195
+ }
196
+ export declare function addDuration(date: DateInput, duration: number | Duration | TDuration, exact?: boolean): Date;
197
+ /**
198
+ * Subtract the specified years, months, weeks, days, hours, minutes and seconds from the given date.
199
+ * @param date
200
+ * @param duration
201
+ * @param exact
202
+ * @returns
203
+ */
204
+ export declare function subDuration(date: DateInput, duration: number | Duration | TDuration, exact?: boolean): Date;