@nejs/basic-extensions 2.9.0 → 2.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@nejs/basic-extensions.bundle.2.11.0.js +19 -0
- package/dist/@nejs/basic-extensions.bundle.2.11.0.js.map +7 -0
- package/dist/cjs/array.extensions.js +174 -0
- package/dist/cjs/array.extensions.js.map +1 -1
- package/dist/cjs/big.int.extension.js +1 -0
- package/dist/cjs/big.int.extension.js.map +1 -1
- package/dist/cjs/classes/descriptor.d.ts +67 -155
- package/dist/cjs/classes/descriptor.js +185 -278
- package/dist/cjs/classes/descriptor.js.map +1 -1
- package/dist/cjs/classes/index.d.ts +1 -0
- package/dist/cjs/classes/index.js +3 -0
- package/dist/cjs/classes/index.js.map +1 -1
- package/dist/cjs/classes/iterable.d.ts +44 -0
- package/dist/cjs/classes/iterable.js +64 -0
- package/dist/cjs/classes/iterable.js.map +1 -1
- package/dist/cjs/classes/param.parser.d.ts +10 -10
- package/dist/cjs/classes/property.d.ts +86 -0
- package/dist/cjs/classes/property.js +284 -0
- package/dist/cjs/classes/property.js.map +1 -0
- package/dist/cjs/classes/symkeys.d.ts +68 -11
- package/dist/cjs/classes/symkeys.js +103 -17
- package/dist/cjs/classes/symkeys.js.map +1 -1
- package/dist/cjs/classes/type.d.ts +4 -4
- package/dist/cjs/function.extensions.js +1 -0
- package/dist/cjs/function.extensions.js.map +1 -1
- package/dist/cjs/global.this.js +29 -0
- package/dist/cjs/global.this.js.map +1 -1
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/json.extensions.js +19 -18
- package/dist/cjs/json.extensions.js.map +1 -1
- package/dist/cjs/map.extensions.js +1 -0
- package/dist/cjs/map.extensions.js.map +1 -1
- package/dist/cjs/number.extension.js +1 -0
- package/dist/cjs/number.extension.js.map +1 -1
- package/dist/cjs/object.extensions.d.ts +0 -29
- package/dist/cjs/object.extensions.js +218 -255
- package/dist/cjs/object.extensions.js.map +1 -1
- package/dist/cjs/set.extensions.js +1 -0
- package/dist/cjs/set.extensions.js.map +1 -1
- package/dist/cjs/string.extensions.js +474 -469
- package/dist/cjs/string.extensions.js.map +1 -1
- package/dist/cjs/symbol.extensions.js +387 -32
- package/dist/cjs/symbol.extensions.js.map +1 -1
- package/dist/cjs/utils/copy.object.d.ts +408 -0
- package/dist/cjs/utils/copy.object.js +720 -0
- package/dist/cjs/utils/copy.object.js.map +1 -0
- package/dist/cjs/utils/descriptor.utils.d.ts +146 -0
- package/dist/cjs/utils/descriptor.utils.js +614 -0
- package/dist/cjs/utils/descriptor.utils.js.map +1 -0
- package/dist/cjs/utils/index.d.ts +60 -0
- package/dist/cjs/utils/index.js +52 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/toolkit.d.ts +1898 -0
- package/dist/cjs/utils/toolkit.js +1378 -0
- package/dist/cjs/utils/toolkit.js.map +1 -0
- package/dist/mjs/array.extensions.js +174 -0
- package/dist/mjs/array.extensions.js.map +1 -1
- package/dist/mjs/big.int.extension.js +1 -0
- package/dist/mjs/big.int.extension.js.map +1 -1
- package/dist/mjs/classes/descriptor.d.ts +67 -155
- package/dist/mjs/classes/descriptor.js +185 -278
- package/dist/mjs/classes/descriptor.js.map +1 -1
- package/dist/mjs/classes/index.d.ts +1 -0
- package/dist/mjs/classes/index.js +3 -0
- package/dist/mjs/classes/index.js.map +1 -1
- package/dist/mjs/classes/iterable.d.ts +44 -0
- package/dist/mjs/classes/iterable.js +64 -0
- package/dist/mjs/classes/iterable.js.map +1 -1
- package/dist/mjs/classes/param.parser.d.ts +10 -10
- package/dist/mjs/classes/property.d.ts +86 -0
- package/dist/mjs/classes/property.js +280 -0
- package/dist/mjs/classes/property.js.map +1 -0
- package/dist/mjs/classes/symkeys.d.ts +68 -11
- package/dist/mjs/classes/symkeys.js +103 -17
- package/dist/mjs/classes/symkeys.js.map +1 -1
- package/dist/mjs/classes/type.d.ts +4 -4
- package/dist/mjs/function.extensions.js +1 -0
- package/dist/mjs/function.extensions.js.map +1 -1
- package/dist/mjs/global.this.js +6 -0
- package/dist/mjs/global.this.js.map +1 -1
- package/dist/mjs/index.d.ts +3 -0
- package/dist/mjs/index.js +5 -0
- package/dist/mjs/index.js.map +1 -1
- package/dist/mjs/json.extensions.js +19 -18
- package/dist/mjs/json.extensions.js.map +1 -1
- package/dist/mjs/map.extensions.js +1 -0
- package/dist/mjs/map.extensions.js.map +1 -1
- package/dist/mjs/number.extension.js +1 -0
- package/dist/mjs/number.extension.js.map +1 -1
- package/dist/mjs/object.extensions.d.ts +0 -29
- package/dist/mjs/object.extensions.js +215 -251
- package/dist/mjs/object.extensions.js.map +1 -1
- package/dist/mjs/set.extensions.js +1 -0
- package/dist/mjs/set.extensions.js.map +1 -1
- package/dist/mjs/string.extensions.js +474 -469
- package/dist/mjs/string.extensions.js.map +1 -1
- package/dist/mjs/symbol.extensions.js +387 -32
- package/dist/mjs/symbol.extensions.js.map +1 -1
- package/dist/mjs/utils/copy.object.d.ts +408 -0
- package/dist/mjs/utils/copy.object.js +702 -0
- package/dist/mjs/utils/copy.object.js.map +1 -0
- package/dist/mjs/utils/descriptor.utils.d.ts +146 -0
- package/dist/mjs/utils/descriptor.utils.js +606 -0
- package/dist/mjs/utils/descriptor.utils.js.map +1 -0
- package/dist/mjs/utils/index.d.ts +60 -0
- package/dist/mjs/utils/index.js +36 -0
- package/dist/mjs/utils/index.js.map +1 -0
- package/dist/mjs/utils/toolkit.d.ts +1898 -0
- package/dist/mjs/utils/toolkit.js +1373 -0
- package/dist/mjs/utils/toolkit.js.map +1 -0
- package/package.json +29 -37
- package/repl.bootstrap.js +12 -1
- package/src/array.extensions.js +191 -1
- package/src/big.int.extension.js +3 -1
- package/src/classes/descriptor.js +206 -305
- package/src/classes/index.js +4 -0
- package/src/classes/iterable.js +74 -0
- package/src/classes/property.js +333 -0
- package/src/classes/symkeys.js +120 -19
- package/src/function.extensions.js +2 -0
- package/src/global.this.js +8 -0
- package/src/index.js +6 -0
- package/src/json.extensions.js +18 -19
- package/src/map.extensions.js +3 -1
- package/src/number.extension.js +3 -1
- package/src/object.extensions.js +240 -277
- package/src/set.extensions.js +3 -1
- package/src/string.extensions.js +512 -506
- package/src/symbol.extensions.js +413 -30
- package/src/utils/copy.object.js +780 -0
- package/src/utils/descriptor.utils.js +707 -0
- package/src/utils/index.js +74 -0
- package/src/utils/toolkit.js +1473 -0
- package/tests/arrayextensions.test.js +2 -0
- package/tests/index.test.js +1 -0
- package/tests/newClasses/asyncIterable.test.js +2 -0
- package/tests/newClasses/deferred.test.js +5 -3
- package/tests/newClasses/descriptor.test.js +6 -8
- package/tests/newClasses/iterable.test.js +2 -0
- package/tests/newClasses/refmap.test.js +2 -1
- package/tests/newClasses/refset.test.js +2 -0
- package/tests/objectextensions.test.js +2 -0
- package/tests/setextensions.test.js +2 -0
- package/tests/stringextensions.test.js +1 -0
- package/tests/utils/toolkit.test.js +223 -0
- package/tsconfig.base.json +1 -1
- package/vitest.config.js +7 -0
- package/dist/@nejs/basic-extensions.bundle.2.8.0.js +0 -19
- package/dist/@nejs/basic-extensions.bundle.2.8.0.js.map +0 -7
- package/docs/assets/anchor.js +0 -350
- package/docs/assets/bass-addons.css +0 -12
- package/docs/assets/bass.css +0 -544
- package/docs/assets/fonts/EOT/SourceCodePro-Bold.eot +0 -0
- package/docs/assets/fonts/EOT/SourceCodePro-Regular.eot +0 -0
- package/docs/assets/fonts/LICENSE.txt +0 -93
- package/docs/assets/fonts/OTF/SourceCodePro-Bold.otf +0 -0
- package/docs/assets/fonts/OTF/SourceCodePro-Regular.otf +0 -0
- package/docs/assets/fonts/TTF/SourceCodePro-Bold.ttf +0 -0
- package/docs/assets/fonts/TTF/SourceCodePro-Regular.ttf +0 -0
- package/docs/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff +0 -0
- package/docs/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff +0 -0
- package/docs/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff +0 -0
- package/docs/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff +0 -0
- package/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 +0 -0
- package/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 +0 -0
- package/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 +0 -0
- package/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 +0 -0
- package/docs/assets/fonts/source-code-pro.css +0 -23
- package/docs/assets/github.css +0 -123
- package/docs/assets/site.js +0 -168
- package/docs/assets/split.css +0 -15
- package/docs/assets/split.js +0 -782
- package/docs/assets/style.css +0 -147
- package/docs/index.html +0 -35485
package/tests/index.test.js
CHANGED
|
@@ -2,6 +2,8 @@ const { Extensions } = require('../../dist/cjs/index.js')
|
|
|
2
2
|
const AsyncIterable = Extensions.AsyncIterable.class
|
|
3
3
|
const Iterable = Extensions.Iterable.class
|
|
4
4
|
|
|
5
|
+
import { describe, test, expect } from 'vitest';
|
|
6
|
+
|
|
5
7
|
describe('AsyncIterable', () => {
|
|
6
8
|
test('should create an async iterable from an array of promises', async () => {
|
|
7
9
|
const promises = [Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)];
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const { Extensions } = require('../../dist/cjs/index.js')
|
|
2
2
|
const Deferred = Extensions.Deferred.class
|
|
3
3
|
|
|
4
|
+
import { describe, beforeEach, test, expect, vi } from 'vitest';
|
|
5
|
+
|
|
4
6
|
describe('Deferred', () => {
|
|
5
7
|
let deferred;
|
|
6
8
|
|
|
@@ -31,7 +33,7 @@ describe('Deferred', () => {
|
|
|
31
33
|
|
|
32
34
|
test('should call then with the resolved value', async () => {
|
|
33
35
|
const value = 'resolved value';
|
|
34
|
-
const onFulfilled =
|
|
36
|
+
const onFulfilled = vi.fn();
|
|
35
37
|
deferred.resolve(value);
|
|
36
38
|
await deferred.then(onFulfilled);
|
|
37
39
|
expect(onFulfilled).toHaveBeenCalledWith(value);
|
|
@@ -39,14 +41,14 @@ describe('Deferred', () => {
|
|
|
39
41
|
|
|
40
42
|
test('should call catch with the rejection reason', async () => {
|
|
41
43
|
const reason = 'rejected reason';
|
|
42
|
-
const onRejected =
|
|
44
|
+
const onRejected = vi.fn();
|
|
43
45
|
deferred.reject(reason);
|
|
44
46
|
await deferred.catch(onRejected);
|
|
45
47
|
expect(onRejected).toHaveBeenCalledWith(reason);
|
|
46
48
|
});
|
|
47
49
|
|
|
48
50
|
test('should call finally regardless of resolution or rejection', async () => {
|
|
49
|
-
const onFinally =
|
|
51
|
+
const onFinally = vi.fn();
|
|
50
52
|
deferred.resolve('resolved value');
|
|
51
53
|
await deferred.finally(onFinally);
|
|
52
54
|
expect(onFinally).toHaveBeenCalled();
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const { Extensions } = require('../../dist/cjs/index.js')
|
|
2
2
|
const Descriptor = Extensions.Descriptor.class
|
|
3
3
|
|
|
4
|
+
import { describe, beforeEach, test, expect } from 'vitest';
|
|
5
|
+
|
|
4
6
|
describe('Descriptor', () => {
|
|
5
7
|
describe('constructor', () => {
|
|
6
8
|
test('should create a Descriptor from a property descriptor', () => {
|
|
@@ -55,10 +57,6 @@ describe('Descriptor', () => {
|
|
|
55
57
|
const desc = new Descriptor({ value: 10 });
|
|
56
58
|
expect(desc.isDescriptor).toBe(true);
|
|
57
59
|
});
|
|
58
|
-
|
|
59
|
-
test('should throw an error for invalid descriptors', () => {
|
|
60
|
-
expect(() => new Descriptor({})).toThrow()
|
|
61
|
-
});
|
|
62
60
|
});
|
|
63
61
|
|
|
64
62
|
describe('getters and setters', () => {
|
|
@@ -177,8 +175,8 @@ describe('Descriptor', () => {
|
|
|
177
175
|
const descriptor = Descriptor.accessor(getter, setter);
|
|
178
176
|
expect(descriptor.get).toBe(getter);
|
|
179
177
|
expect(descriptor.set).toBe(setter);
|
|
180
|
-
expect(descriptor.enumerable).toBe(
|
|
181
|
-
expect(descriptor.configurable).toBe(
|
|
178
|
+
expect(descriptor.enumerable).toBe(true);
|
|
179
|
+
expect(descriptor.configurable).toBe(true);
|
|
182
180
|
});
|
|
183
181
|
|
|
184
182
|
// Additional tests for variations in enumerable and configurable
|
|
@@ -190,8 +188,8 @@ describe('Descriptor', () => {
|
|
|
190
188
|
const descriptor = Descriptor.data(value);
|
|
191
189
|
expect(descriptor.value).toBe(value);
|
|
192
190
|
expect(descriptor.writable).toBe(true);
|
|
193
|
-
expect(descriptor.enumerable).toBe(
|
|
194
|
-
expect(descriptor.configurable).toBe(
|
|
191
|
+
expect(descriptor.enumerable).toBe(true);
|
|
192
|
+
expect(descriptor.configurable).toBe(true);
|
|
195
193
|
});
|
|
196
194
|
|
|
197
195
|
// Additional tests for variations in writable, enumerable, and configurable
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const { Extensions } = require('../../dist/cjs/index.js')
|
|
2
2
|
const Iterable = Extensions.Iterable.class
|
|
3
3
|
|
|
4
|
+
import { describe, test, expect } from 'vitest';
|
|
5
|
+
|
|
4
6
|
describe('Iterable', () => {
|
|
5
7
|
test('should create an iterable from an array', () => {
|
|
6
8
|
const array = [1, 2, 3];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { Classes } = require('../../dist/cjs/index.js')
|
|
2
2
|
const { RefMap } = Classes
|
|
3
3
|
|
|
4
|
+
import { describe, beforeEach, test, expect, vi } from 'vitest';
|
|
4
5
|
|
|
5
6
|
describe('RefMap', () => {
|
|
6
7
|
let refMap;
|
|
@@ -61,7 +62,7 @@ describe('RefMap', () => {
|
|
|
61
62
|
|
|
62
63
|
// Test forEach method
|
|
63
64
|
test('forEach should iterate over values', () => {
|
|
64
|
-
const mockCallback =
|
|
65
|
+
const mockCallback = vi.fn();
|
|
65
66
|
const obj = {};
|
|
66
67
|
refMap.set('key', obj);
|
|
67
68
|
refMap.forEach(mockCallback);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const { Patches } = require('../dist/cjs/index.js')
|
|
2
2
|
const ObjectExtensions = Patches.get(Object)
|
|
3
3
|
|
|
4
|
+
import { describe, beforeAll, afterAll, test, expect } from 'vitest';
|
|
5
|
+
|
|
4
6
|
// Apply and revert the patch in the setup and teardown of the tests
|
|
5
7
|
beforeAll(() => {
|
|
6
8
|
ObjectExtensions.apply()
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { Patches } = require('../dist/cjs/index.js')
|
|
2
2
|
const StringExtensions = Patches.get(String)
|
|
3
3
|
const StringPrototypeExtensions = Patches.get(String.prototype)
|
|
4
|
+
import { describe, beforeAll, test, expect } from 'vitest';
|
|
4
5
|
|
|
5
6
|
describe('StringExtensions', () => {
|
|
6
7
|
beforeAll(() => {
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { is, si, has, as } from '../../dist/cjs/index.js';
|
|
3
|
+
|
|
4
|
+
describe('is utility functions', () => {
|
|
5
|
+
it('should correctly identify types', () => {
|
|
6
|
+
expect(is.a(42, 'number')).toBe(true);
|
|
7
|
+
expect(is.a(new Date(), Date)).toBe(true);
|
|
8
|
+
expect(is.a('string', Number)).toBe(false);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should correctly identify accessor descriptors', () => {
|
|
12
|
+
expect(is.accessorDescriptor({ get: () => 42, set: () => {} })).toBe(true);
|
|
13
|
+
expect(is.accessorDescriptor({ value: 42, writable: true })).toBe(false);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should correctly identify arrays', () => {
|
|
17
|
+
expect(is.array([1, 2, 3])).toBe(true);
|
|
18
|
+
expect(is.array('string')).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should correctly identify bigints', () => {
|
|
22
|
+
expect(is.bigint(123n)).toBe(true);
|
|
23
|
+
expect(is.bigint(123)).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should correctly identify booleans', () => {
|
|
27
|
+
expect(is.boolean(true)).toBe(true);
|
|
28
|
+
expect(is.boolean(false)).toBe(true);
|
|
29
|
+
expect(is.boolean(1)).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should correctly identify functions', () => {
|
|
33
|
+
expect(is.function(function() {})).toBe(true);
|
|
34
|
+
expect(is.function(123)).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should correctly identify iterables', () => {
|
|
38
|
+
expect(is.iterable([1, 2, 3])).toBe(true);
|
|
39
|
+
expect(is.iterable('string')).toBe(true);
|
|
40
|
+
expect(is.iterable(123)).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should correctly identify nullish values', () => {
|
|
44
|
+
expect(is.nullish(null)).toBe(true);
|
|
45
|
+
expect(is.nullish(undefined)).toBe(true);
|
|
46
|
+
expect(is.nullish('value')).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should correctly identify numbers', () => {
|
|
50
|
+
expect(is.number(123)).toBe(true);
|
|
51
|
+
expect(is.number('123')).toBe(false);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should correctly identify objects', () => {
|
|
55
|
+
expect(is.object({})).toBe(true);
|
|
56
|
+
expect(is.object(null)).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should correctly identify strings', () => {
|
|
60
|
+
expect(is.string('hello')).toBe(true);
|
|
61
|
+
expect(is.string(123)).toBe(false);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should correctly identify symbols', () => {
|
|
65
|
+
expect(is.symbol(Symbol('foo'))).toBe(true);
|
|
66
|
+
expect(is.symbol('foo')).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should correctly identify true values', () => {
|
|
70
|
+
expect(is.true(true)).toBe(true);
|
|
71
|
+
expect(is.true(false)).toBe(false);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should correctly identify truthy values', () => {
|
|
75
|
+
expect(is.truthy(1)).toBe(true);
|
|
76
|
+
expect(is.truthy('hello')).toBe(true);
|
|
77
|
+
expect(is.truthy(0)).toBe(false);
|
|
78
|
+
expect(is.truthy('')).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('si utility functions', () => {
|
|
83
|
+
it('should return thenValue or elseValue based on condition', () => {
|
|
84
|
+
expect(si.a(42, 'number', 'yes', 'no')).toBe('yes');
|
|
85
|
+
expect(si.a('string', Number, 'yes', 'no')).toBe('no');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should correctly identify falsy values and return thenValue or elseValue', () => {
|
|
89
|
+
expect(si.falsy(0, 'yes', 'no')).toBe('yes');
|
|
90
|
+
expect(si.falsy(1, 'yes', 'no')).toBe('no');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should correctly identify functions and return thenValue or elseValue', () => {
|
|
94
|
+
expect(si.function(function() {}, 'yes', 'no')).toBe('yes');
|
|
95
|
+
expect(si.function(123, 'yes', 'no')).toBe('no');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should correctly identify iterables and return thenValue or elseValue', () => {
|
|
99
|
+
expect(si.iterable([1, 2, 3], 'yes', 'no')).toBe('yes');
|
|
100
|
+
expect(si.iterable(123, 'yes', 'no')).toBe('no');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('should correctly identify nullish values and return thenValue or elseValue', () => {
|
|
104
|
+
expect(si.nullish(null, 'yes', 'no')).toBe('yes');
|
|
105
|
+
expect(si.nullish('value', 'yes', 'no')).toBe('no');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should correctly identify numbers and return thenValue or elseValue', () => {
|
|
109
|
+
expect(si.number(123, 'yes', 'no')).toBe('yes');
|
|
110
|
+
expect(si.number('123', 'yes', 'no')).toBe('no');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should correctly identify objects and return thenValue or elseValue', () => {
|
|
114
|
+
expect(si.object({}, 'yes', 'no')).toBe('yes');
|
|
115
|
+
expect(si.object(null, 'yes', 'no')).toBe('no');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should correctly identify symbols and return thenValue or elseValue', () => {
|
|
119
|
+
expect(si.symbol(Symbol('foo'), 'yes', 'no')).toBe('yes');
|
|
120
|
+
expect(si.symbol('foo', 'yes', 'no')).toBe('no');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should correctly identify true values and return thenValue or elseValue', () => {
|
|
124
|
+
expect(si.true(true, 'yes', 'no')).toBe('yes');
|
|
125
|
+
expect(si.true(false, 'yes', 'no')).toBe('no');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should correctly identify truthy values and return thenValue or elseValue', () => {
|
|
129
|
+
expect(si.truthy(1, 'yes', 'no')).toBe('yes');
|
|
130
|
+
expect(si.truthy(0, 'yes', 'no')).toBe('no');
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe('has utility functions', () => {
|
|
135
|
+
it('should correctly identify if an object has a key', () => {
|
|
136
|
+
expect(has(new Map([['key', 'value']]), 'key')).toBe(true);
|
|
137
|
+
expect(has({}, 'key')).toBe(false);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should correctly identify if an object has all keys', () => {
|
|
141
|
+
expect(has.all(new Map([['key1', 'value1'], ['key2', 'value2']]), ['key1', 'key2'])).toBe(true);
|
|
142
|
+
expect(has.all({}, ['key1', 'key2'])).toBe(false);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('should correctly identify if an object has some keys', () => {
|
|
146
|
+
expect(has.some(new Map([['key1', 'value1'], ['key2', 'value2']]), ['key1'])).toBe(true);
|
|
147
|
+
expect(has.some({}, ['key1', 'key2'])).toBe(false);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('should correctly identify if an object has a prototype', () => {
|
|
151
|
+
expect(has.prototype(function() {})).toBe(true);
|
|
152
|
+
expect(has.prototype(() => {})).toBe(false);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('should correctly identify if an object has a custom string tag', () => {
|
|
156
|
+
const obj = { [Symbol.toStringTag]: 'CustomObject' };
|
|
157
|
+
expect(has.stringTag(obj)).toBe(true);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('should correctly identify if an object has a custom toPrimitive method', () => {
|
|
161
|
+
const obj = { [Symbol.toPrimitive]: () => 42 };
|
|
162
|
+
expect(has.toPrimitive(obj)).toBe(true);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('should correctly identify if an object has a custom valueOf method', () => {
|
|
166
|
+
const obj = { valueOf: () => 42 };
|
|
167
|
+
expect(has.valueOfFn(obj)).toBe(true);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe('as utility functions', () => {
|
|
172
|
+
it('should correctly convert values to arrays', () => {
|
|
173
|
+
expect(as.array([1, 2, 3])).toEqual([1, 2, 3]);
|
|
174
|
+
expect(as.array('string')).toEqual(['s', 't', 'r', 'i', 'n', 'g']);
|
|
175
|
+
expect(as.array(123)).toBe(undefined);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('should correctly convert values to objects', () => {
|
|
179
|
+
expect(as.object({ key: 'value' })).toEqual({ key: 'value' });
|
|
180
|
+
expect(typeof as.object('string')).toBe('object');
|
|
181
|
+
expect(as.object(null)).toEqual({});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('should correctly convert values to strings', () => {
|
|
185
|
+
expect(as.string(null)).toBe('null');
|
|
186
|
+
expect(as.string(123)).toBe('123');
|
|
187
|
+
const obj = { [Symbol.toPrimitive]: () => 'custom' };
|
|
188
|
+
expect(as.string(obj)).toBe('custom');
|
|
189
|
+
expect(as.string(Symbol('mySymbol'), { description: true })).toBe('mySymbol');
|
|
190
|
+
expect(as.string([], { stringTag: true })).toBe('');
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('should correctly convert values to integer strings', () => {
|
|
194
|
+
expect(as.integerString(123.456)).toBe('123');
|
|
195
|
+
expect(as.integerString('0.789')).toBe('0');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('should correctly convert values to number strings', () => {
|
|
199
|
+
expect(as.numberString(' 123.456abc ')).toBe('123.456');
|
|
200
|
+
expect(as.numberString('-0.789xyz')).toBe('-0.789');
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('should correctly convert values to numbers', () => {
|
|
204
|
+
expect(as.number('123.456abc')).toBe(123.456);
|
|
205
|
+
expect(as.number('-0.789xyz')).toBe(-0.789);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('should correctly convert values to bigints', () => {
|
|
209
|
+
expect(as.bigint('123.456abc')).toBe(123n);
|
|
210
|
+
expect(as.bigint('0.789xyz')).toBe(0n);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('should correctly convert values to booleans', () => {
|
|
214
|
+
expect(as.boolean('yes')).toBe(true);
|
|
215
|
+
expect(as.boolean('no')).toBe(false);
|
|
216
|
+
expect(as.boolean(1)).toBe(true);
|
|
217
|
+
expect(as.boolean(0)).toBe(false);
|
|
218
|
+
expect(as.boolean('true')).toBe(true);
|
|
219
|
+
expect(as.boolean('false')).toBe(false);
|
|
220
|
+
expect(as.boolean({})).toBe(true);
|
|
221
|
+
expect(as.boolean(null)).toBe(false);
|
|
222
|
+
});
|
|
223
|
+
});
|
package/tsconfig.base.json
CHANGED