atomic-fns 0.3.5 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/{core → dist}/collections/BTree.d.ts +6 -6
- package/{core → dist}/collections/BTree.js +17 -17
- package/{core → dist}/collections/Heap.d.ts +3 -3
- package/{core → dist}/collections/Heap.js +0 -0
- package/dist/collections/LRUCache.d.ts +80 -0
- package/dist/collections/LRUCache.js +126 -0
- package/{core → dist}/collections/SortedMap.d.ts +2 -2
- package/{core → dist}/collections/SortedMap.js +0 -0
- package/{core → dist}/collections/SortedSet.d.ts +3 -3
- package/{core → dist}/collections/SortedSet.js +1 -1
- package/{core → dist}/collections/SortedTree.d.ts +3 -3
- package/{core → dist}/collections/SortedTree.js +1 -1
- package/{core → dist}/collections/SplayTree.d.ts +5 -5
- package/{core → dist}/collections/SplayTree.js +0 -0
- package/{core → dist}/collections/abc.d.ts +0 -0
- package/{core → dist}/collections/abc.js +0 -0
- package/{core → dist}/collections/deque.d.ts +6 -6
- package/{core → dist}/collections/deque.js +0 -0
- package/{core → dist}/collections/frozenset.d.ts +0 -0
- package/{core → dist}/collections/frozenset.js +3 -6
- package/{core → dist}/collections/index.d.ts +4 -4
- package/{core → dist}/collections/index.js +0 -0
- package/{core → dist}/functools/index.d.ts +27 -13
- package/{core → dist}/functools/index.js +34 -12
- package/{core → dist}/globals/index.d.ts +7 -10
- package/{core → dist}/globals/index.js +7 -14
- package/dist/i18n/date/index.d.ts +204 -0
- package/dist/i18n/date/index.js +530 -0
- package/dist/i18n/date/utils.d.ts +65 -0
- package/dist/i18n/date/utils.js +312 -0
- package/dist/i18n/duration.d.ts +112 -0
- package/dist/i18n/duration.js +392 -0
- package/dist/i18n/format.d.ts +26 -0
- package/dist/i18n/format.js +495 -0
- package/{core → dist}/i18n/index.d.ts +1 -1
- package/{core → dist}/i18n/index.js +1 -1
- package/{core → dist}/index.d.ts +0 -0
- package/{core → dist}/index.js +0 -0
- package/{core → dist}/itertools/index.d.ts +27 -27
- package/{core → dist}/itertools/index.js +24 -24
- package/{core → dist}/math/index.d.ts +3 -3
- package/{core → dist}/math/index.js +0 -0
- package/{core → dist}/operators/index.d.ts +2 -2
- package/{core → dist}/operators/index.js +2 -2
- package/{core → dist}/random/index.d.ts +1 -1
- package/{core → dist}/random/index.js +3 -3
- package/package.json +28 -42
- package/.editorconfig +0 -12
- package/.esdoc.json +0 -27
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -35
- package/.firebaserc +0 -5
- package/.prettierrc +0 -19
- package/core/collections/BTree.ts +0 -1340
- package/core/collections/Heap.ts +0 -189
- package/core/collections/LRUCache.d.ts +0 -152
- package/core/collections/LRUCache.js +0 -409
- package/core/collections/LRUCache.ts +0 -486
- package/core/collections/SortedMap.ts +0 -146
- package/core/collections/SortedSet.ts +0 -110
- package/core/collections/SortedTree.ts +0 -160
- package/core/collections/SplayTree.ts +0 -354
- package/core/collections/abc.ts +0 -176
- package/core/collections/deque.ts +0 -338
- package/core/collections/frozenset.ts +0 -37
- package/core/collections/index.ts +0 -1024
- package/core/collections/test.html +0 -10
- package/core/collections/typedArrays.d.ts +0 -31
- package/core/collections/typedArrays.js +0 -143
- package/core/collections/typedArrays.ts +0 -163
- package/core/functools/index.ts +0 -260
- package/core/globals/index.ts +0 -481
- package/core/i18n/date/format.d.ts +0 -16
- package/core/i18n/date/format.js +0 -307
- package/core/i18n/date/format.ts +0 -343
- package/core/i18n/date/index.d.ts +0 -224
- package/core/i18n/date/index.js +0 -387
- package/core/i18n/date/index.ts +0 -471
- package/core/i18n/date/test.html +0 -67
- package/core/i18n/index.ts +0 -8
- package/core/index.ts +0 -8
- package/core/itertools/index.ts +0 -494
- package/core/math/index.ts +0 -152
- package/core/operators/index.ts +0 -310
- package/core/random/index.ts +0 -66
- package/firebase.json +0 -10
- package/jasmine.json +0 -14
- package/tests/BTree.spec.ts +0 -143
- package/tests/Cache.spec.ts +0 -161
- package/tests/Heap.spec.ts +0 -66
- package/tests/SortedMap.spec.ts +0 -144
- package/tests/SortedSet.spec.ts +0 -84
- package/tests/SortedTree.spec.ts +0 -164
- package/tests/SplayTree.spec.ts +0 -121
- package/tests/collections.spec.ts +0 -288
- package/tests/deque.spec.ts +0 -107
- package/tests/globals.spec.ts +0 -270
- package/tests/itertools.spec.ts +0 -266
- package/tests/math.spec.ts +0 -25
- package/tests/operators.spec.ts +0 -40
- package/tests/random.spec.ts +0 -46
- package/tsconfig.json +0 -126
- package/tsconfig.node.json +0 -18
- package/tsconfig.xo.json +0 -9
|
@@ -12,7 +12,7 @@ import { Function } from '../globals/index.js';
|
|
|
12
12
|
* @returns {Function} Returns the new bound function.
|
|
13
13
|
* @see {@link partial}
|
|
14
14
|
*/
|
|
15
|
-
export declare const bind: (fn: Function, thisArg: any, ...partials: any[]) =>
|
|
15
|
+
export declare const bind: (fn: Function, thisArg: any, ...partials: any[]) => any;
|
|
16
16
|
/**
|
|
17
17
|
* Creates a function that accepts arguments of `func` and either invokes `func` returning its result, if at least arity number of arguments have been provided, or returns a function that accepts the remaining `func` arguments, and so on. The arity of `func` may be specified if `func.length` is not sufficient.
|
|
18
18
|
* @param {Function} func The function to curry.
|
|
@@ -27,7 +27,7 @@ export declare const curry: (func: Function, arity?: number) => Function<any>;
|
|
|
27
27
|
* @param {...*} [args] The arguments to apply to `fn`.
|
|
28
28
|
* @returns {Function} Returns the new partially applied function
|
|
29
29
|
*/
|
|
30
|
-
export declare const partial: (fn: any, ...args: any[]) =>
|
|
30
|
+
export declare const partial: (fn: any, ...args: any[]) => any;
|
|
31
31
|
/**
|
|
32
32
|
* Creates a function composition from a given set of functions that will be each applied on the result of the previous one from left to right.
|
|
33
33
|
* @param {...*} [args] The set of functions to apply.
|
|
@@ -48,6 +48,14 @@ export declare const compose: (...args: any[]) => (x: any) => any;
|
|
|
48
48
|
* @return {Function} Returns the new memoized function.
|
|
49
49
|
*/
|
|
50
50
|
export declare function memoize<T>(func: Function<T>, resolver?: Function): Function<ReturnType<typeof func>>;
|
|
51
|
+
/**
|
|
52
|
+
* Can be used as a decorator on any function or method to memoize its results.
|
|
53
|
+
* **NOTE:** By default the given function is memoized using it's first argument, regardless of others.
|
|
54
|
+
* @param target
|
|
55
|
+
* @param name
|
|
56
|
+
* @param descriptor
|
|
57
|
+
* @returns A memoized version of the given function
|
|
58
|
+
*/
|
|
51
59
|
export declare function cache(target: any, name: any, descriptor: any): any;
|
|
52
60
|
/**
|
|
53
61
|
* Creates a debounced function that delays invoking `func` until after `wait` milliseconds have elapsed since the last time the debounced function was invoked. Subsequent calls to the debounced function return the result of the last successful invocation. Provide options to set the `maxWait` milliseconds, regardless of when the function was last invoked.
|
|
@@ -77,11 +85,11 @@ export declare function throttle(func: Function, wait: number): Function;
|
|
|
77
85
|
```js
|
|
78
86
|
let func = x => x
|
|
79
87
|
let single = once(func)
|
|
80
|
-
single(1) //
|
|
81
|
-
single(2) //
|
|
82
|
-
single(3) //
|
|
88
|
+
single(1) // 1
|
|
89
|
+
single(2) // 1
|
|
90
|
+
single(3) // 1
|
|
83
91
|
// ...
|
|
84
|
-
//
|
|
92
|
+
// `func` is invoked only once.
|
|
85
93
|
```
|
|
86
94
|
*/
|
|
87
95
|
export declare function once<T>(func: Function<T>): (...args: any[]) => T;
|
|
@@ -90,19 +98,25 @@ export declare type Result<T, E = any> = [Maybe<T>, Maybe<E>];
|
|
|
90
98
|
export declare type Optional<T> = Maybe<T>;
|
|
91
99
|
/**
|
|
92
100
|
* Wraps a function to catch any exceptions inside and return a `go` style error-return type {@link Result}.
|
|
93
|
-
*
|
|
101
|
+
* @template T,E
|
|
94
102
|
* @param {Function} fun The function to wrap and catch if it throws.
|
|
95
|
-
* @param {
|
|
103
|
+
* @param {Function} [onFinally] Optional callback that will be invoked with `(err?, value)` on the `finally` clause.
|
|
96
104
|
* @returns {Function} A new function that wraps `fun`.
|
|
97
|
-
* @template T,E
|
|
98
105
|
*/
|
|
99
106
|
export declare function result<T = any, E = unknown>(fun: Function<T>, onFinally?: (err: E, res: T) => any): (...args: any[]) => Result<T, E>;
|
|
100
107
|
/**
|
|
101
108
|
* Wraps a function or promise to catch any exceptions inside and return a `go` style error-return type. This is like {@link result} but it deals with async functions or promises.
|
|
102
|
-
*
|
|
103
|
-
* @param {Function|Promise} awaitable The function or promise to await.
|
|
104
|
-
* @param {?function(err: E, res: T): *} [onFinally] Optional callback that will be called on the `finally` clause if given.
|
|
105
|
-
* @returns {Function} A new function that awaits the `awaitable` param and returns a {@link Result} type.
|
|
106
109
|
* @template T,E
|
|
110
|
+
* @param {Function<T>|Promise<T>} awaitable The function or promise to await.
|
|
111
|
+
* @param {Function} [onFinally] Optional callback that will be invoked with `(err?, value)` on the `finally` clause.
|
|
112
|
+
* @returns {Function<Promise<Result<T, E>>>} A new function that awaits the `awaitable` param and returns a {@link Result} type.
|
|
107
113
|
*/
|
|
108
114
|
export declare function resultAsync<T = any, E = unknown>(awaitable: Promise<T> | Function<Promise<T>>, onFinally?: (err: E, res: T) => any): (...args: any[]) => Promise<Result<T, E>>;
|
|
115
|
+
/**
|
|
116
|
+
* Converts a function that expects a node-style callback argument like `(err, result)` to return a Promise instead.
|
|
117
|
+
* @template T
|
|
118
|
+
* @param {Function<T>} fun The given function to convert from callback style to Promise.
|
|
119
|
+
* @param {*} thisArg
|
|
120
|
+
* @returns {Function<Promise<T>>} A function that wraps `fun` and returns a Promise.
|
|
121
|
+
*/
|
|
122
|
+
export declare function promisify<T = any>(fun: Function<T>, thisArg: any): (...args: any[]) => Promise<T>;
|
|
@@ -89,7 +89,14 @@ export function memoize(func, resolver) {
|
|
|
89
89
|
return value;
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Can be used as a decorator on any function or method to memoize its results.
|
|
94
|
+
* **NOTE:** By default the given function is memoized using it's first argument, regardless of others.
|
|
95
|
+
* @param target
|
|
96
|
+
* @param name
|
|
97
|
+
* @param descriptor
|
|
98
|
+
* @returns A memoized version of the given function
|
|
99
|
+
*/
|
|
93
100
|
export function cache(target, name, descriptor) {
|
|
94
101
|
const original = descriptor.value;
|
|
95
102
|
if (typeof original === 'function') {
|
|
@@ -153,11 +160,11 @@ export function throttle(func, wait) {
|
|
|
153
160
|
```js
|
|
154
161
|
let func = x => x
|
|
155
162
|
let single = once(func)
|
|
156
|
-
single(1) //
|
|
157
|
-
single(2) //
|
|
158
|
-
single(3) //
|
|
163
|
+
single(1) // 1
|
|
164
|
+
single(2) // 1
|
|
165
|
+
single(3) // 1
|
|
159
166
|
// ...
|
|
160
|
-
//
|
|
167
|
+
// `func` is invoked only once.
|
|
161
168
|
```
|
|
162
169
|
*/
|
|
163
170
|
export function once(func) {
|
|
@@ -172,11 +179,10 @@ export function once(func) {
|
|
|
172
179
|
}
|
|
173
180
|
/**
|
|
174
181
|
* Wraps a function to catch any exceptions inside and return a `go` style error-return type {@link Result}.
|
|
175
|
-
*
|
|
182
|
+
* @template T,E
|
|
176
183
|
* @param {Function} fun The function to wrap and catch if it throws.
|
|
177
|
-
* @param {
|
|
184
|
+
* @param {Function} [onFinally] Optional callback that will be invoked with `(err?, value)` on the `finally` clause.
|
|
178
185
|
* @returns {Function} A new function that wraps `fun`.
|
|
179
|
-
* @template T,E
|
|
180
186
|
*/
|
|
181
187
|
export function result(fun, onFinally) {
|
|
182
188
|
return (...args) => {
|
|
@@ -195,11 +201,10 @@ export function result(fun, onFinally) {
|
|
|
195
201
|
}
|
|
196
202
|
/**
|
|
197
203
|
* Wraps a function or promise to catch any exceptions inside and return a `go` style error-return type. This is like {@link result} but it deals with async functions or promises.
|
|
198
|
-
*
|
|
199
|
-
* @param {Function|Promise} awaitable The function or promise to await.
|
|
200
|
-
* @param {?function(err: E, res: T): *} [onFinally] Optional callback that will be called on the `finally` clause if given.
|
|
201
|
-
* @returns {Function} A new function that awaits the `awaitable` param and returns a {@link Result} type.
|
|
202
204
|
* @template T,E
|
|
205
|
+
* @param {Function<T>|Promise<T>} awaitable The function or promise to await.
|
|
206
|
+
* @param {Function} [onFinally] Optional callback that will be invoked with `(err?, value)` on the `finally` clause.
|
|
207
|
+
* @returns {Function<Promise<Result<T, E>>>} A new function that awaits the `awaitable` param and returns a {@link Result} type.
|
|
203
208
|
*/
|
|
204
209
|
export function resultAsync(awaitable, onFinally) {
|
|
205
210
|
return async (...args) => {
|
|
@@ -217,3 +222,20 @@ export function resultAsync(awaitable, onFinally) {
|
|
|
217
222
|
return [value, err];
|
|
218
223
|
};
|
|
219
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Converts a function that expects a node-style callback argument like `(err, result)` to return a Promise instead.
|
|
227
|
+
* @template T
|
|
228
|
+
* @param {Function<T>} fun The given function to convert from callback style to Promise.
|
|
229
|
+
* @param {*} thisArg
|
|
230
|
+
* @returns {Function<Promise<T>>} A function that wraps `fun` and returns a Promise.
|
|
231
|
+
*/
|
|
232
|
+
export function promisify(fun, thisArg) {
|
|
233
|
+
const original = fun.bind(thisArg);
|
|
234
|
+
return async (...args) => {
|
|
235
|
+
return await new Promise((resolve, reject) => original(...args, (err, result) => {
|
|
236
|
+
if (err)
|
|
237
|
+
return reject(err);
|
|
238
|
+
resolve(result);
|
|
239
|
+
}));
|
|
240
|
+
};
|
|
241
|
+
}
|
|
@@ -92,7 +92,6 @@ export declare function type(value: any): any;
|
|
|
92
92
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString | Object.toString }
|
|
93
93
|
*/
|
|
94
94
|
export declare const str: (obj: any) => any;
|
|
95
|
-
export declare function hasOwnProperty(obj: any, prop: any): boolean;
|
|
96
95
|
/** Check if value is a boolean type. */
|
|
97
96
|
export declare const isBool: (x: any) => x is boolean;
|
|
98
97
|
/** Check if value is an `Error` type. */
|
|
@@ -118,8 +117,6 @@ export declare const isNumber: (x: any) => x is number;
|
|
|
118
117
|
export declare const isInteger: (x: any) => x is number;
|
|
119
118
|
/** Check if value is a bigint type. */
|
|
120
119
|
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
120
|
/** Check if value is a Promise type. */
|
|
124
121
|
export declare const isPromise: (x: any) => x is Promise<any>;
|
|
125
122
|
/** Check if value is a function type. */
|
|
@@ -129,9 +126,9 @@ export declare const isAsyncFunction: (x: any) => boolean;
|
|
|
129
126
|
/** Check if value is a generator function type. */
|
|
130
127
|
export declare const isGenerator: (x: any) => x is Generator<unknown, any, unknown>;
|
|
131
128
|
/** Check if value is `null` or `undefined`. */
|
|
132
|
-
export declare const isNull: (x: any) => x is null
|
|
129
|
+
export declare const isNull: (x: any) => x is null;
|
|
133
130
|
/** Check if value === `undefined`. */
|
|
134
|
-
export declare
|
|
131
|
+
export declare const isUndefined: (x: any) => x is undefined;
|
|
135
132
|
/** Check if value is not `null` or `undefined`. */
|
|
136
133
|
export declare const notNull: (x: any) => boolean;
|
|
137
134
|
/** Returns `true` for objects without length or falsy values. */
|
|
@@ -164,10 +161,10 @@ export declare function len(value: any): any;
|
|
|
164
161
|
* @example
|
|
165
162
|
```js
|
|
166
163
|
uniqueId()
|
|
167
|
-
//
|
|
164
|
+
// 3445556877
|
|
168
165
|
|
|
169
166
|
uniqueId('user_')
|
|
170
|
-
//
|
|
167
|
+
// 'user_1033763188'
|
|
171
168
|
```
|
|
172
169
|
*/
|
|
173
170
|
export declare const uniqueId: (pre?: string) => any;
|
|
@@ -177,7 +174,7 @@ export declare const uniqueId: (pre?: string) => any;
|
|
|
177
174
|
* @example
|
|
178
175
|
```js
|
|
179
176
|
uuid()
|
|
180
|
-
//
|
|
177
|
+
// '183f8ef3-b8f0-4000-81f5-89234c836d00'
|
|
181
178
|
```
|
|
182
179
|
*/
|
|
183
180
|
export declare const uuid: () => string;
|
|
@@ -213,7 +210,7 @@ export declare const values: (object: any) => unknown[];
|
|
|
213
210
|
* @param attr A property key name.
|
|
214
211
|
* @returns `true` if the object has the property name.
|
|
215
212
|
*/
|
|
216
|
-
export declare const has: (obj: any, attr: PropertyKey) =>
|
|
213
|
+
export declare const has: (obj: any, attr: PropertyKey) => boolean;
|
|
217
214
|
/**
|
|
218
215
|
* Check if the attribute is present in the object or return a default value instead.
|
|
219
216
|
* @param {PropertyKey} key
|
|
@@ -293,7 +290,7 @@ export declare const int: (x: any, base?: number) => number;
|
|
|
293
290
|
*/
|
|
294
291
|
export declare const list: (value?: any) => unknown[];
|
|
295
292
|
/**
|
|
296
|
-
* Retrieve the next item from the iterator by calling
|
|
293
|
+
* Retrieve the next item from the iterator by calling its `next()` method.
|
|
297
294
|
* @param iter The iterator.
|
|
298
295
|
* @returns The next value from the iterator.
|
|
299
296
|
*/
|
|
@@ -122,9 +122,6 @@ export function type(value) {
|
|
|
122
122
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString | Object.toString }
|
|
123
123
|
*/
|
|
124
124
|
export const str = (obj) => (obj != null ? obj.toString() : '');
|
|
125
|
-
export function hasOwnProperty(obj, prop) {
|
|
126
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
127
|
-
}
|
|
128
125
|
/** Check if value is a boolean type. */
|
|
129
126
|
export const isBool = (x) => type(x) === 'boolean';
|
|
130
127
|
/** Check if value is an `Error` type. */
|
|
@@ -138,7 +135,7 @@ export const isIterable = (x) => {
|
|
|
138
135
|
/** Check if value is a native `Date` type. */
|
|
139
136
|
export const isDate = (x) => x instanceof Date;
|
|
140
137
|
/** Check if value is an object type. */
|
|
141
|
-
export const isObject = (x) =>
|
|
138
|
+
export const isObject = (x) => type(x) === 'object';
|
|
142
139
|
/** Check if value is a string type. */
|
|
143
140
|
export const isString = (x) => type(x) === 'string';
|
|
144
141
|
/** Check if value is an Array type. */
|
|
@@ -154,11 +151,9 @@ export const isArrayLike = (x) => {
|
|
|
154
151
|
/** Check if value is a number type. */
|
|
155
152
|
export const isNumber = (x) => type(x) === 'number';
|
|
156
153
|
/** Check if value is an integer number type. */
|
|
157
|
-
export const isInteger = (x) => type(x) === 'number' && Math.
|
|
154
|
+
export const isInteger = (x) => type(x) === 'number' && Math.trunc(x) === x;
|
|
158
155
|
/** Check if value is a bigint type. */
|
|
159
156
|
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
157
|
/** Check if value is a Promise type. */
|
|
163
158
|
export const isPromise = (x) => type(x) === 'Promise';
|
|
164
159
|
/** Check if value is a function type. */
|
|
@@ -172,9 +167,7 @@ export const isGenerator = (x) => {
|
|
|
172
167
|
/** Check if value is `null` or `undefined`. */
|
|
173
168
|
export const isNull = (x) => x == null;
|
|
174
169
|
/** Check if value === `undefined`. */
|
|
175
|
-
export
|
|
176
|
-
return typeof o === 'undefined';
|
|
177
|
-
}
|
|
170
|
+
export const isUndefined = (x) => x === undefined;
|
|
178
171
|
/** Check if value is not `null` or `undefined`. */
|
|
179
172
|
export const notNull = (x) => x != null;
|
|
180
173
|
/** Returns `true` for objects without length or falsy values. */
|
|
@@ -222,10 +215,10 @@ export function len(value) {
|
|
|
222
215
|
* @example
|
|
223
216
|
```js
|
|
224
217
|
uniqueId()
|
|
225
|
-
//
|
|
218
|
+
// 3445556877
|
|
226
219
|
|
|
227
220
|
uniqueId('user_')
|
|
228
|
-
//
|
|
221
|
+
// 'user_1033763188'
|
|
229
222
|
```
|
|
230
223
|
*/
|
|
231
224
|
export const uniqueId = (pre = '') =>
|
|
@@ -237,7 +230,7 @@ export const uniqueId = (pre = '') =>
|
|
|
237
230
|
* @example
|
|
238
231
|
```js
|
|
239
232
|
uuid()
|
|
240
|
-
//
|
|
233
|
+
// '183f8ef3-b8f0-4000-81f5-89234c836d00'
|
|
241
234
|
```
|
|
242
235
|
*/
|
|
243
236
|
export const uuid = () => {
|
|
@@ -407,7 +400,7 @@ export const int = (x, base = 10) => parseInt(x, base);
|
|
|
407
400
|
*/
|
|
408
401
|
export const list = (value) => (value ? Array.from(value) : []);
|
|
409
402
|
/**
|
|
410
|
-
* Retrieve the next item from the iterator by calling
|
|
403
|
+
* Retrieve the next item from the iterator by calling its `next()` method.
|
|
411
404
|
* @param iter The iterator.
|
|
412
405
|
* @returns The next value from the iterator.
|
|
413
406
|
*/
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { Duration, DurationUnit, TDuration } from '../duration.js';
|
|
2
|
+
import { asDate, formatDate, strftime } from '../format.js';
|
|
3
|
+
import { DateParts, daysInMonth, daysInYear, isLeapYear, maxDate, minDate, weeksInYear } from './utils.js';
|
|
4
|
+
export { asDate, daysInMonth, daysInYear, formatDate, isLeapYear, maxDate, minDate, strftime, weeksInYear };
|
|
5
|
+
declare type DateInput = number | string | Date;
|
|
6
|
+
declare type DateLike = DateInput | DateParts | IntlDate;
|
|
7
|
+
export { DateInput, DateParts, DateLike };
|
|
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(): 366 | 365;
|
|
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(): DateParts;
|
|
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: DateParts): 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 | TDuration | Duration, 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: TDuration, exact?: boolean): Date;
|