@douglasneuroinformatics/libjs 0.5.0 → 0.7.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/douglasneuroinformatics-libjs-0.7.0.tgz +0 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/json.d.ts +3 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/json.js +23 -0
- package/dist/json.test.d.ts +2 -0
- package/dist/json.test.d.ts.map +1 -0
- package/dist/json.test.js +35 -0
- package/dist/number.test.js +3 -0
- package/dist/string.d.ts +2 -1
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +7 -0
- package/dist/string.test.js +14 -1
- package/package.json +1 -1
- package/dist/douglasneuroinformatics-libjs-0.5.0.tgz +0 -0
|
Binary file
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/json.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAeA,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,WASjD;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,WAKhD"}
|
package/dist/json.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isPlainObject } from './object.js';
|
|
2
|
+
function isSerializedSet(value) {
|
|
3
|
+
if (!isPlainObject(value)) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
return Boolean(value.__isSerializedType && value.__deserializedType === 'Set');
|
|
7
|
+
}
|
|
8
|
+
export function replacer(_, value) {
|
|
9
|
+
if (value instanceof Set) {
|
|
10
|
+
return {
|
|
11
|
+
__deserializedType: 'Set',
|
|
12
|
+
__isSerializedType: true,
|
|
13
|
+
value: Array.from(value)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
export function reviver(_, value) {
|
|
19
|
+
if (isSerializedSet(value)) {
|
|
20
|
+
return new Set(value.value);
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.test.d.ts","sourceRoot":"","sources":["../src/json.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { replacer, reviver } from './json.js';
|
|
3
|
+
describe('replacer', () => {
|
|
4
|
+
it('should serialize a Set', () => {
|
|
5
|
+
const set = new Set([1, 2, 3]);
|
|
6
|
+
expect(replacer('', set)).toEqual({
|
|
7
|
+
__deserializedType: 'Set',
|
|
8
|
+
__isSerializedType: true,
|
|
9
|
+
value: [1, 2, 3]
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
it('should return the value if it is not a Set', () => {
|
|
13
|
+
const obj = { a: 1 };
|
|
14
|
+
expect(replacer('', obj)).toBe(obj);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
describe('reviver', () => {
|
|
18
|
+
it('should deserialize a serialized set', () => {
|
|
19
|
+
const serializedSet = {
|
|
20
|
+
__deserializedType: 'Set',
|
|
21
|
+
__isSerializedType: true,
|
|
22
|
+
value: [1, 2, 3]
|
|
23
|
+
};
|
|
24
|
+
const deserializedSet = new Set([1, 2, 3]);
|
|
25
|
+
expect(reviver('', serializedSet)).toEqual(deserializedSet);
|
|
26
|
+
});
|
|
27
|
+
it('should return the value if it is not a plain object', () => {
|
|
28
|
+
const obj = new Date();
|
|
29
|
+
expect(reviver('', obj)).toBe(obj);
|
|
30
|
+
});
|
|
31
|
+
it('should return the value if it is a plain object but not a serialized set', () => {
|
|
32
|
+
const obj = { a: 1 };
|
|
33
|
+
expect(reviver('', obj)).toBe(obj);
|
|
34
|
+
});
|
|
35
|
+
});
|
package/dist/number.test.js
CHANGED
|
@@ -15,6 +15,8 @@ const NUMBER_LIKE_VALUES = [
|
|
|
15
15
|
'0.0',
|
|
16
16
|
'+0',
|
|
17
17
|
'3.14',
|
|
18
|
+
'1.',
|
|
19
|
+
'.1',
|
|
18
20
|
Number.MAX_VALUE,
|
|
19
21
|
Number.MIN_VALUE,
|
|
20
22
|
Infinity,
|
|
@@ -24,6 +26,7 @@ const NUMBER_LIKE_VALUES = [
|
|
|
24
26
|
' -Infinity '
|
|
25
27
|
];
|
|
26
28
|
const NON_NUMBER_LIKE_VALUES = [
|
|
29
|
+
'1..',
|
|
27
30
|
'--5',
|
|
28
31
|
'A5',
|
|
29
32
|
'5A',
|
package/dist/string.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { CamelCase, SnakeCase } from 'type-fest';
|
|
1
|
+
import type { CamelCase, Primitive, SnakeCase } from 'type-fest';
|
|
2
2
|
export declare function camelToSnakeCase<T extends string>(s: T): SnakeCase<T>;
|
|
3
3
|
export declare function snakeToCamelCase<T extends string>(s: T): CamelCase<T>;
|
|
4
4
|
export declare function uncapitalize<T extends string>(s: T): Uncapitalize<T>;
|
|
5
5
|
export declare function capitalize<T extends string>(s: T): Capitalize<T>;
|
|
6
6
|
export declare function toLowerCase<T extends string>(s: T): Lowercase<T>;
|
|
7
7
|
export declare function toUpperCase<T extends string>(s: T): Uppercase<T>;
|
|
8
|
+
export declare function format(s: string, ...args: Exclude<Primitive, symbol>[]): string;
|
|
8
9
|
//# sourceMappingURL=string.d.ts.map
|
package/dist/string.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEjE,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,gBAEtD;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,gBAItD;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,mBAElD;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,iBAEhD;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,gBAEjD;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,gBAEjD;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,UAKtE"}
|
package/dist/string.js
CHANGED
|
@@ -18,3 +18,10 @@ export function toLowerCase(s) {
|
|
|
18
18
|
export function toUpperCase(s) {
|
|
19
19
|
return s.toUpperCase();
|
|
20
20
|
}
|
|
21
|
+
export function format(s, ...args) {
|
|
22
|
+
for (const arg of args) {
|
|
23
|
+
s = s.replace('{}', String(arg));
|
|
24
|
+
}
|
|
25
|
+
return s;
|
|
26
|
+
}
|
|
27
|
+
console.log(format('Hello {}', 'World'));
|
package/dist/string.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { camelToSnakeCase, capitalize, snakeToCamelCase, toLowerCase, toUpperCase, uncapitalize } from './string.js';
|
|
2
|
+
import { camelToSnakeCase, capitalize, format, snakeToCamelCase, toLowerCase, toUpperCase, uncapitalize } from './string.js';
|
|
3
3
|
describe('camelToSnakeCase', () => {
|
|
4
4
|
it('should convert from camel to snake case ', () => {
|
|
5
5
|
expect(camelToSnakeCase('toSnakeCase')).toBe('to_snake_case');
|
|
@@ -38,3 +38,16 @@ describe('toUpperCase', () => {
|
|
|
38
38
|
expect(toUpperCase('foo')).toBe('FOO');
|
|
39
39
|
});
|
|
40
40
|
});
|
|
41
|
+
describe('format', () => {
|
|
42
|
+
it('should return the same string if no positional args are given', () => {
|
|
43
|
+
expect(format('Hello')).toBe('Hello');
|
|
44
|
+
expect(format('Hello {}')).toBe('Hello {}');
|
|
45
|
+
});
|
|
46
|
+
it('should insert positional arguments', () => {
|
|
47
|
+
expect(format('Hello {}', 'World')).toBe('Hello World');
|
|
48
|
+
expect(format('Hello {}. {}.', 'World', 'This function works')).toBe('Hello World. This function works.');
|
|
49
|
+
});
|
|
50
|
+
it('should ignore additional indices', () => {
|
|
51
|
+
expect(format('Hello {}{}.', 'World')).toBe('Hello World{}.');
|
|
52
|
+
});
|
|
53
|
+
});
|
package/package.json
CHANGED
|
Binary file
|