atomic-fns 0.3.3 → 0.3.4
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 +17 -3
- package/core/collections/LRUCache.d.ts +22 -1
- package/core/collections/LRUCache.js +22 -1
- package/core/collections/LRUCache.ts +22 -1
- package/core/collections/SortedMap.d.ts +1 -1
- package/core/collections/SortedMap.js +1 -1
- package/core/collections/SortedMap.ts +1 -1
- package/core/collections/SortedSet.d.ts +6 -0
- package/core/collections/SortedSet.js +6 -0
- package/core/collections/SortedSet.ts +6 -0
- package/core/collections/SortedTree.d.ts +3 -3
- package/core/collections/SortedTree.js +3 -3
- package/core/collections/SortedTree.ts +3 -3
- package/core/collections/index.d.ts +2 -0
- package/core/collections/index.js +7 -5
- package/core/collections/index.ts +7 -5
- package/core/functools/index.d.ts +2 -2
- package/core/functools/index.ts +6 -3
- package/core/globals/index.d.ts +22 -3
- package/core/globals/index.js +28 -5
- package/core/globals/index.ts +39 -6
- package/core/i18n/date/format.d.ts +16 -0
- package/core/i18n/date/format.js +307 -0
- package/core/i18n/date/format.ts +343 -0
- package/core/i18n/date/index.d.ts +223 -0
- package/core/i18n/date/index.js +387 -0
- package/core/i18n/date/index.ts +471 -0
- package/core/i18n/date/test.html +67 -0
- package/core/i18n/index.d.ts +7 -0
- package/core/i18n/index.js +7 -0
- package/core/i18n/index.ts +8 -0
- package/core/index.d.ts +1 -0
- package/core/index.js +1 -0
- package/core/index.ts +1 -0
- package/core/operators/index.d.ts +1 -1
- package/core/operators/index.js +35 -5
- package/core/operators/index.ts +34 -6
- package/package.json +11 -11
- package/tests/globals.spec.ts +9 -9
- package/tsconfig.json +2 -1
- package/core/datetime/index.d.ts +0 -45
- package/core/datetime/index.js +0 -71
- package/core/datetime/index.ts +0 -128
package/core/operators/index.ts
CHANGED
|
@@ -66,7 +66,7 @@ export function compare(x, y): number {
|
|
|
66
66
|
* @returns {boolean} `true` if `x` and `y` are equal or `false` otherwise.
|
|
67
67
|
*/
|
|
68
68
|
export function eq(x, y) {
|
|
69
|
-
return x
|
|
69
|
+
return Object.is(x, y) || call(x, 'eq', y) != null
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
@@ -245,10 +245,11 @@ export function shallowEqual(obj, other) {
|
|
|
245
245
|
* @param other
|
|
246
246
|
* @returns `true` if the objects are considered equal.
|
|
247
247
|
*/
|
|
248
|
-
export function deepEqual(obj, other, checker = eq) {
|
|
248
|
+
export function deepEqual(obj, other, checker = eq, seen = new WeakSet()) {
|
|
249
249
|
if (checker(obj, other)) return true
|
|
250
|
-
|
|
251
250
|
if (!obj || !other) return false
|
|
251
|
+
if (obj.prototype !== other.prototype) return false
|
|
252
|
+
if (seen.has(obj) && seen.has(other)) return false
|
|
252
253
|
|
|
253
254
|
if (Array.isArray(obj)) {
|
|
254
255
|
// compare the arrays
|
|
@@ -259,18 +260,45 @@ export function deepEqual(obj, other, checker = eq) {
|
|
|
259
260
|
return false
|
|
260
261
|
}
|
|
261
262
|
}
|
|
263
|
+
|
|
262
264
|
return true
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (obj instanceof Set) {
|
|
268
|
+
if (obj.size !== other.size) return false
|
|
269
|
+
for (const value of obj.values()) {
|
|
270
|
+
if (!other.has(value)) return false
|
|
271
|
+
}
|
|
272
|
+
return true
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (obj instanceof Map) {
|
|
276
|
+
// compare keys and values
|
|
277
|
+
if (obj.size !== other.size) return false
|
|
278
|
+
seen.add(obj)
|
|
279
|
+
seen.add(other)
|
|
280
|
+
for (const key of obj.keys()) {
|
|
281
|
+
if (!other.has(key)) return false
|
|
282
|
+
if (!deepEqual(obj.get(key), other.get(key), checker, seen)) {
|
|
283
|
+
return false
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return true
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (isObject(obj)) {
|
|
290
|
+
// compare the object own enumerable keys
|
|
265
291
|
const objKeys = Object.keys(obj)
|
|
266
292
|
const otherKeys = Object.keys(other)
|
|
267
293
|
|
|
268
294
|
if (objKeys.length !== otherKeys.length) return false
|
|
269
295
|
|
|
296
|
+
seen.add(obj)
|
|
297
|
+
seen.add(other)
|
|
270
298
|
for (const key of objKeys) {
|
|
271
299
|
if (
|
|
272
300
|
!Object.prototype.hasOwnProperty.call(other, key) ||
|
|
273
|
-
!deepEqual(obj[key], other[key], checker)
|
|
301
|
+
!deepEqual(obj[key], other[key], checker, seen)
|
|
274
302
|
) {
|
|
275
303
|
return false
|
|
276
304
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atomic-fns",
|
|
3
3
|
"description": "Like Lodash, but for ESNext and with types. Stop shipping code built for browsers from 2015.",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.4",
|
|
5
5
|
"main": "core/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "core/index.d.ts",
|
|
8
8
|
"module": "core/index.js",
|
|
9
9
|
"sideEffects": false,
|
|
10
|
+
"scripts": {
|
|
11
|
+
"prepublishOnly": "npm test",
|
|
12
|
+
"test": "NODE_OPTIONS=--loader=ts-node/esm jasmine --config=jasmine.json",
|
|
13
|
+
"tsc": "tsc -p ./tsconfig.xo.json --declaration",
|
|
14
|
+
"tsc:w": "tsc -p ./tsconfig.xo.json --declaration --watch",
|
|
15
|
+
"lint": "eslint core/**/*.ts",
|
|
16
|
+
"lint:fix": "eslint core/**/*.ts --fix",
|
|
17
|
+
"build": "npm run lint:fix && npm run tsc && npm run docs",
|
|
18
|
+
"docs": "typedoc"
|
|
19
|
+
},
|
|
10
20
|
"devDependencies": {
|
|
11
21
|
"@types/jasmine": "^4.3.0",
|
|
12
22
|
"@typescript-eslint/eslint-plugin": "^5.39.0",
|
|
@@ -27,16 +37,6 @@
|
|
|
27
37
|
"typedoc": "^0.23.16",
|
|
28
38
|
"typescript": "^4.8.4"
|
|
29
39
|
},
|
|
30
|
-
"scripts": {
|
|
31
|
-
"prepublishOnly": "npm test",
|
|
32
|
-
"test": "NODE_OPTIONS=--loader=ts-node/esm jasmine --config=jasmine.json",
|
|
33
|
-
"tsc": "tsc -p ./tsconfig.xo.json --declaration",
|
|
34
|
-
"tsc:w": "tsc -p ./tsconfig.xo.json --declaration --watch",
|
|
35
|
-
"lint": "eslint core/**/*.ts",
|
|
36
|
-
"lint:fix": "eslint core/**/*.ts --fix",
|
|
37
|
-
"build": "npm run lint:fix && npm run tsc && npm run docs",
|
|
38
|
-
"docs": "typedoc"
|
|
39
|
-
},
|
|
40
40
|
"lint-staged": {
|
|
41
41
|
"*.ts": "eslint --fix"
|
|
42
42
|
},
|
package/tests/globals.spec.ts
CHANGED
|
@@ -12,11 +12,11 @@ import {
|
|
|
12
12
|
hex,
|
|
13
13
|
isArray,
|
|
14
14
|
isArrayLike,
|
|
15
|
-
|
|
15
|
+
isAsyncFunction,
|
|
16
16
|
isBigint,
|
|
17
17
|
isBool,
|
|
18
18
|
isEmpty,
|
|
19
|
-
|
|
19
|
+
isFunction,
|
|
20
20
|
isNaN,
|
|
21
21
|
isNull,
|
|
22
22
|
isNumber,
|
|
@@ -114,15 +114,15 @@ describe('globals', () => {
|
|
|
114
114
|
assert(!isArrayLike(''))
|
|
115
115
|
})
|
|
116
116
|
|
|
117
|
-
it('
|
|
118
|
-
assert(
|
|
119
|
-
assert(!
|
|
117
|
+
it('isFunction', () => {
|
|
118
|
+
assert(isFunction(_))
|
|
119
|
+
assert(!isFunction([]))
|
|
120
120
|
})
|
|
121
121
|
|
|
122
|
-
it('
|
|
123
|
-
assert(
|
|
124
|
-
assert(
|
|
125
|
-
assert(!
|
|
122
|
+
it('isAsyncFunction', () => {
|
|
123
|
+
assert(isAsyncFunction(async function () {}))
|
|
124
|
+
assert(isAsyncFunction(async () => {}))
|
|
125
|
+
assert(!isAsyncFunction(_))
|
|
126
126
|
})
|
|
127
127
|
|
|
128
128
|
it('isNaN', () => {
|
package/tsconfig.json
CHANGED
|
@@ -110,6 +110,7 @@
|
|
|
110
110
|
"./core/collections/index.ts",
|
|
111
111
|
"./core/datetime/index.ts",
|
|
112
112
|
"./core/functools/index.ts",
|
|
113
|
+
"./core/i18n/index.ts",
|
|
113
114
|
"./core/itertools/index.ts",
|
|
114
115
|
"./core/math/index.ts",
|
|
115
116
|
"./core/operators/index.ts",
|
|
@@ -122,4 +123,4 @@
|
|
|
122
123
|
"excludeExternals": true,
|
|
123
124
|
"excludePrivate": true,
|
|
124
125
|
}
|
|
125
|
-
}
|
|
126
|
+
}
|
package/core/datetime/index.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This module includes classes and functions to work with Date types.
|
|
3
|
-
*
|
|
4
|
-
* @module Date
|
|
5
|
-
*/
|
|
6
|
-
export declare const MINUTE_SECONDS = 60;
|
|
7
|
-
export declare const HOUR_SECONDS: number;
|
|
8
|
-
export declare const DAY_SECONDS: number;
|
|
9
|
-
export declare const WEEK_SECONDS: number;
|
|
10
|
-
export declare const MILLISECONDS = 1000;
|
|
11
|
-
export declare const MINUTE_MILLISECONDS: number;
|
|
12
|
-
export declare const HOUR_MILLISECONDS: number;
|
|
13
|
-
export declare const DAY_MILLISECONDS: number;
|
|
14
|
-
export declare const WEEK_MILLISECONDS: number;
|
|
15
|
-
export declare const MS = "millisecond";
|
|
16
|
-
export declare const S = "second";
|
|
17
|
-
export declare const MIN = "minute";
|
|
18
|
-
export declare const H = "hour";
|
|
19
|
-
export declare const D = "day";
|
|
20
|
-
export declare const W = "week";
|
|
21
|
-
export declare const M = "month";
|
|
22
|
-
export declare const Q = "quarter";
|
|
23
|
-
export declare const Y = "year";
|
|
24
|
-
export declare const DATE = "date";
|
|
25
|
-
export declare const FORMAT_DEFAULT = "YYYY-MM-DDTHH:mm:ssZ";
|
|
26
|
-
export declare const INVALID_DATE_STRING = "Invalid Date";
|
|
27
|
-
export declare const REGEX_PARSE: RegExp;
|
|
28
|
-
export declare const REGEX_FORMAT: RegExp;
|
|
29
|
-
export declare const now: number;
|
|
30
|
-
export declare type DatetimeOptions = {
|
|
31
|
-
year: number;
|
|
32
|
-
month?: number;
|
|
33
|
-
day?: number;
|
|
34
|
-
hour?: number;
|
|
35
|
-
minute?: number;
|
|
36
|
-
second?: number;
|
|
37
|
-
millisecond?: number;
|
|
38
|
-
locale?: string;
|
|
39
|
-
utc?: boolean;
|
|
40
|
-
};
|
|
41
|
-
export declare class Datetime {
|
|
42
|
-
#private;
|
|
43
|
-
constructor(opts?: string | number | Date | DatetimeOptions);
|
|
44
|
-
format(locale?: string, opts?: Intl.DateTimeFormatOptions): string;
|
|
45
|
-
}
|
package/core/datetime/index.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This module includes classes and functions to work with Date types.
|
|
3
|
-
*
|
|
4
|
-
* @module Date
|
|
5
|
-
*/
|
|
6
|
-
import { get } from '../globals';
|
|
7
|
-
// Constants
|
|
8
|
-
export const MINUTE_SECONDS = 60;
|
|
9
|
-
export const HOUR_SECONDS = MINUTE_SECONDS * 60;
|
|
10
|
-
export const DAY_SECONDS = HOUR_SECONDS * 24;
|
|
11
|
-
export const WEEK_SECONDS = DAY_SECONDS * 7;
|
|
12
|
-
export const MILLISECONDS = 1e3;
|
|
13
|
-
export const MINUTE_MILLISECONDS = MINUTE_SECONDS * MILLISECONDS;
|
|
14
|
-
export const HOUR_MILLISECONDS = HOUR_SECONDS * MILLISECONDS;
|
|
15
|
-
export const DAY_MILLISECONDS = DAY_SECONDS * MILLISECONDS;
|
|
16
|
-
export const WEEK_MILLISECONDS = WEEK_SECONDS * MILLISECONDS;
|
|
17
|
-
// English locales
|
|
18
|
-
export const MS = 'millisecond';
|
|
19
|
-
export const S = 'second';
|
|
20
|
-
export const MIN = 'minute';
|
|
21
|
-
export const H = 'hour';
|
|
22
|
-
export const D = 'day';
|
|
23
|
-
export const W = 'week';
|
|
24
|
-
export const M = 'month';
|
|
25
|
-
export const Q = 'quarter';
|
|
26
|
-
export const Y = 'year';
|
|
27
|
-
export const DATE = 'date';
|
|
28
|
-
export const FORMAT_DEFAULT = 'YYYY-MM-DDTHH:mm:ssZ';
|
|
29
|
-
export const INVALID_DATE_STRING = 'Invalid Date';
|
|
30
|
-
// regex
|
|
31
|
-
export const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/;
|
|
32
|
-
export const REGEX_FORMAT = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g;
|
|
33
|
-
export const now = new Date().getTime();
|
|
34
|
-
function parseDate(date) {
|
|
35
|
-
if (date === null)
|
|
36
|
-
return new Date(NaN);
|
|
37
|
-
if (!date)
|
|
38
|
-
return new Date();
|
|
39
|
-
if (date instanceof Date)
|
|
40
|
-
return new Date(date);
|
|
41
|
-
const utc = date.utc;
|
|
42
|
-
if (typeof date === 'string' && !/Z$/i.test(date)) {
|
|
43
|
-
const d = date.match(REGEX_PARSE);
|
|
44
|
-
if (d) {
|
|
45
|
-
const m = d[2] - 1 || 0;
|
|
46
|
-
const ms = (d[7] || '0').slice(0, 3);
|
|
47
|
-
if (utc) {
|
|
48
|
-
return new Date(Date.UTC(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms));
|
|
49
|
-
}
|
|
50
|
-
return new Date(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return new Date(date);
|
|
54
|
-
}
|
|
55
|
-
export class Datetime {
|
|
56
|
-
#date = new Date(); // defaults to now
|
|
57
|
-
#UTC = false; // use current locale by default
|
|
58
|
-
constructor(opts) {
|
|
59
|
-
this.#date = parseDate(opts);
|
|
60
|
-
this.#UTC = get('utc', opts, false);
|
|
61
|
-
// this.init()
|
|
62
|
-
}
|
|
63
|
-
// Display
|
|
64
|
-
// Format
|
|
65
|
-
format(locale, opts) {
|
|
66
|
-
if (opts && opts.timeZone === undefined && this.#UTC) {
|
|
67
|
-
opts.timeZone = 'utc';
|
|
68
|
-
}
|
|
69
|
-
return this.#date.toLocaleDateString(locale, opts);
|
|
70
|
-
}
|
|
71
|
-
}
|
package/core/datetime/index.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This module includes classes and functions to work with Date types.
|
|
3
|
-
*
|
|
4
|
-
* @module Date
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { get } from '../globals'
|
|
8
|
-
|
|
9
|
-
// Constants
|
|
10
|
-
export const MINUTE_SECONDS = 60
|
|
11
|
-
export const HOUR_SECONDS = MINUTE_SECONDS * 60
|
|
12
|
-
export const DAY_SECONDS = HOUR_SECONDS * 24
|
|
13
|
-
export const WEEK_SECONDS = DAY_SECONDS * 7
|
|
14
|
-
|
|
15
|
-
export const MILLISECONDS = 1e3
|
|
16
|
-
export const MINUTE_MILLISECONDS = MINUTE_SECONDS * MILLISECONDS
|
|
17
|
-
export const HOUR_MILLISECONDS = HOUR_SECONDS * MILLISECONDS
|
|
18
|
-
export const DAY_MILLISECONDS = DAY_SECONDS * MILLISECONDS
|
|
19
|
-
export const WEEK_MILLISECONDS = WEEK_SECONDS * MILLISECONDS
|
|
20
|
-
|
|
21
|
-
// English locales
|
|
22
|
-
export const MS = 'millisecond'
|
|
23
|
-
export const S = 'second'
|
|
24
|
-
export const MIN = 'minute'
|
|
25
|
-
export const H = 'hour'
|
|
26
|
-
export const D = 'day'
|
|
27
|
-
export const W = 'week'
|
|
28
|
-
export const M = 'month'
|
|
29
|
-
export const Q = 'quarter'
|
|
30
|
-
export const Y = 'year'
|
|
31
|
-
export const DATE = 'date'
|
|
32
|
-
|
|
33
|
-
export const FORMAT_DEFAULT = 'YYYY-MM-DDTHH:mm:ssZ'
|
|
34
|
-
|
|
35
|
-
export const INVALID_DATE_STRING = 'Invalid Date'
|
|
36
|
-
|
|
37
|
-
// regex
|
|
38
|
-
export const REGEX_PARSE =
|
|
39
|
-
/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/
|
|
40
|
-
export const REGEX_FORMAT =
|
|
41
|
-
/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g
|
|
42
|
-
|
|
43
|
-
export const now = new Date().getTime()
|
|
44
|
-
|
|
45
|
-
export type DatetimeOptions = {
|
|
46
|
-
year: number
|
|
47
|
-
month?: number
|
|
48
|
-
day?: number
|
|
49
|
-
hour?: number
|
|
50
|
-
minute?: number
|
|
51
|
-
second?: number
|
|
52
|
-
millisecond?: number
|
|
53
|
-
locale?: string
|
|
54
|
-
utc?: boolean
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function parseDate(date) {
|
|
58
|
-
if (date === null) return new Date(NaN)
|
|
59
|
-
if (!date) return new Date()
|
|
60
|
-
if (date instanceof Date) return new Date(date)
|
|
61
|
-
const utc = date.utc
|
|
62
|
-
if (typeof date === 'string' && !/Z$/i.test(date)) {
|
|
63
|
-
const d = date.match(REGEX_PARSE) as any
|
|
64
|
-
if (d) {
|
|
65
|
-
const m = d[2] - 1 || 0
|
|
66
|
-
const ms = (d[7] || '0').slice(0, 3)
|
|
67
|
-
if (utc) {
|
|
68
|
-
return new Date(Date.UTC(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms))
|
|
69
|
-
}
|
|
70
|
-
return new Date(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms)
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return new Date(date)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export class Datetime {
|
|
77
|
-
#date = new Date() // defaults to now
|
|
78
|
-
#UTC = false // use current locale by default
|
|
79
|
-
|
|
80
|
-
constructor(opts?: string | number | Date | DatetimeOptions) {
|
|
81
|
-
this.#date = parseDate(opts)
|
|
82
|
-
this.#UTC = get('utc', opts, false)
|
|
83
|
-
// this.init()
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Display
|
|
87
|
-
// Format
|
|
88
|
-
format(locale?: string, opts?: Intl.DateTimeFormatOptions) {
|
|
89
|
-
if (opts && opts.timeZone === undefined && this.#UTC) {
|
|
90
|
-
opts.timeZone = 'utc'
|
|
91
|
-
}
|
|
92
|
-
return this.#date.toLocaleDateString(locale, opts)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Time from now
|
|
96
|
-
// Time from X
|
|
97
|
-
// Difference
|
|
98
|
-
|
|
99
|
-
// Parsing
|
|
100
|
-
// Parse String + Date Format
|
|
101
|
-
// Parse String + Time Format
|
|
102
|
-
// Parse String + Format + locale
|
|
103
|
-
|
|
104
|
-
// Getter/Setters
|
|
105
|
-
// Hour/Minute/Second/Millis
|
|
106
|
-
// Day of Month
|
|
107
|
-
// Day of Week
|
|
108
|
-
// Day of Year
|
|
109
|
-
// Week of Year
|
|
110
|
-
// Days in Month
|
|
111
|
-
// Weeks in Year
|
|
112
|
-
// max of two dates
|
|
113
|
-
// min of two dates
|
|
114
|
-
|
|
115
|
-
// Manipulate
|
|
116
|
-
// Add
|
|
117
|
-
// Subtract
|
|
118
|
-
// Start of Time
|
|
119
|
-
// End of Time
|
|
120
|
-
|
|
121
|
-
// Query
|
|
122
|
-
// Is Before
|
|
123
|
-
// Is Same
|
|
124
|
-
// Is After
|
|
125
|
-
// Is Between
|
|
126
|
-
// Is Leap Year
|
|
127
|
-
// Is a Date
|
|
128
|
-
}
|