@douglasneuroinformatics/libjs 0.0.3 → 0.1.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.1.0.tgz +0 -0
- package/dist/object.d.ts +17 -0
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +28 -0
- package/dist/object.test.js +49 -1
- package/dist/string.d.ts +2 -0
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +6 -0
- package/dist/string.test.js +11 -1
- package/package.json +19 -11
|
Binary file
|
package/dist/object.d.ts
CHANGED
|
@@ -2,4 +2,21 @@ export type ReadonlyDeep<T extends object> = Readonly<{
|
|
|
2
2
|
[K in keyof T]: T[K] extends object ? ReadonlyDeep<T[K]> : T[K];
|
|
3
3
|
}>;
|
|
4
4
|
export declare function deepFreeze<T extends object>(obj: T): ReadonlyDeep<T>;
|
|
5
|
+
/**
|
|
6
|
+
* Checks if `value` is the [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
|
|
7
|
+
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
8
|
+
*/
|
|
9
|
+
export declare function isObject(value: unknown): value is object;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if `value` is object-like. A value is object-like if it's not `null`
|
|
12
|
+
* and has a `typeof` result of "object".
|
|
13
|
+
*/
|
|
14
|
+
export declare function isObjectLike(value: unknown): value is object;
|
|
15
|
+
/**
|
|
16
|
+
* Checks if `value` is a plain object. An object is plain if it is created by either
|
|
17
|
+
* `{}`, `new Object()`, or `Object.create(null)`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isPlainObject(value: unknown): value is {
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
};
|
|
5
22
|
//# sourceMappingURL=object.d.ts.map
|
package/dist/object.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI,QAAQ,CAAC;KACnD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAChE,CAAC,CAAC;AAEH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAQpE"}
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI,QAAQ,CAAC;KACnD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAChE,CAAC,CAAC;AAEH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAQpE;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAGxD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE5D;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAUjF"}
|
package/dist/object.js
CHANGED
|
@@ -7,3 +7,31 @@ export function deepFreeze(obj) {
|
|
|
7
7
|
});
|
|
8
8
|
return Object.freeze(obj);
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Checks if `value` is the [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
|
|
12
|
+
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
13
|
+
*/
|
|
14
|
+
export function isObject(value) {
|
|
15
|
+
const type = typeof value;
|
|
16
|
+
return value !== null && (type === 'object' || type === 'function');
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Checks if `value` is object-like. A value is object-like if it's not `null`
|
|
20
|
+
* and has a `typeof` result of "object".
|
|
21
|
+
*/
|
|
22
|
+
export function isObjectLike(value) {
|
|
23
|
+
return value !== null && typeof value === 'object';
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Checks if `value` is a plain object. An object is plain if it is created by either
|
|
27
|
+
* `{}`, `new Object()`, or `Object.create(null)`.
|
|
28
|
+
*/
|
|
29
|
+
export function isPlainObject(value) {
|
|
30
|
+
if (typeof value !== 'object' || value === null) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const prototype = Object.getPrototypeOf(value);
|
|
34
|
+
return ((prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) &&
|
|
35
|
+
!(Symbol.toStringTag in value) &&
|
|
36
|
+
!(Symbol.iterator in value));
|
|
37
|
+
}
|
package/dist/object.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { deepFreeze } from './object.js';
|
|
2
|
+
import { deepFreeze, isObject, isObjectLike, isPlainObject } from './object.js';
|
|
3
3
|
describe('deepFreeze', () => {
|
|
4
4
|
it('should not allow mutating a primitive value', () => {
|
|
5
5
|
const obj = deepFreeze({ foo: 1 });
|
|
@@ -23,3 +23,51 @@ describe('deepFreeze', () => {
|
|
|
23
23
|
}).toThrow();
|
|
24
24
|
});
|
|
25
25
|
});
|
|
26
|
+
describe('isObject', () => {
|
|
27
|
+
it('should return true for an object literal', () => {
|
|
28
|
+
expect(isObject({})).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
it('should return true for an array', () => {
|
|
31
|
+
expect(isObject([])).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
it('should return true for a function', () => {
|
|
34
|
+
expect(isObject(() => null)).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
it('should return false for null', () => {
|
|
37
|
+
expect(isObject(null)).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
describe('isObjectLike', () => {
|
|
41
|
+
it('should return true for an object literal', () => {
|
|
42
|
+
expect(isObjectLike({})).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
it('should return true for an array', () => {
|
|
45
|
+
expect(isObjectLike([])).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
it('should return false for a function', () => {
|
|
48
|
+
expect(isObjectLike(() => null)).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
it('should return false for null', () => {
|
|
51
|
+
expect(isObjectLike(() => null)).toBe(false);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe('isPlainObject', () => {
|
|
55
|
+
it('should return true for an object literal', () => {
|
|
56
|
+
expect(isPlainObject({ foo: null })).toBe(true);
|
|
57
|
+
});
|
|
58
|
+
it('should return true for an object created with the Object constructor', () => {
|
|
59
|
+
expect(isPlainObject(new Object())).toBe(true);
|
|
60
|
+
});
|
|
61
|
+
it('should return true for an object with a null prototype', () => {
|
|
62
|
+
expect(isPlainObject(Object.create(null))).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
it('should return false for an array', () => {
|
|
65
|
+
expect(isPlainObject([])).toBe(false);
|
|
66
|
+
});
|
|
67
|
+
it('should return false for a function', () => {
|
|
68
|
+
expect(isPlainObject(() => null)).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
it('should return false for null', () => {
|
|
71
|
+
expect(isPlainObject(() => null)).toBe(false);
|
|
72
|
+
});
|
|
73
|
+
});
|
package/dist/string.d.ts
CHANGED
|
@@ -3,4 +3,6 @@ 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
|
+
export declare function toLowerCase<T extends string>(s: T): Lowercase<T>;
|
|
7
|
+
export declare function toUpperCase<T extends string>(s: T): Uppercase<T>;
|
|
6
8
|
//# 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;AAEtD,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"}
|
|
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;AAEtD,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"}
|
package/dist/string.js
CHANGED
|
@@ -12,3 +12,9 @@ export function uncapitalize(s) {
|
|
|
12
12
|
export function capitalize(s) {
|
|
13
13
|
return (s.charAt(0).toUpperCase() + s.slice(1));
|
|
14
14
|
}
|
|
15
|
+
export function toLowerCase(s) {
|
|
16
|
+
return s.toLowerCase();
|
|
17
|
+
}
|
|
18
|
+
export function toUpperCase(s) {
|
|
19
|
+
return s.toUpperCase();
|
|
20
|
+
}
|
package/dist/string.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { camelToSnakeCase, capitalize, snakeToCamelCase, uncapitalize } from './string.js';
|
|
2
|
+
import { camelToSnakeCase, capitalize, 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');
|
|
@@ -28,3 +28,13 @@ describe('uncapitalize', () => {
|
|
|
28
28
|
expect(uncapitalize('Foo bar')).toBe('foo bar');
|
|
29
29
|
});
|
|
30
30
|
});
|
|
31
|
+
describe('toLowerCase', () => {
|
|
32
|
+
it('should convert to lower case', () => {
|
|
33
|
+
expect(toLowerCase('FOO')).toBe('foo');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
describe('toUpperCase', () => {
|
|
37
|
+
it('should convert to upper case', () => {
|
|
38
|
+
expect(toUpperCase('foo')).toBe('FOO');
|
|
39
|
+
});
|
|
40
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@douglasneuroinformatics/libjs",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"packageManager": "pnpm@8.15.3",
|
|
6
6
|
"description": "A collection of utility functions and types for Node.js and the browser",
|
|
7
7
|
"author": {
|
|
@@ -22,6 +22,15 @@
|
|
|
22
22
|
"files": [
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"build:docs": "typedoc",
|
|
28
|
+
"format": "prettier --write src",
|
|
29
|
+
"lint": "tsc --noEmit && eslint --fix src",
|
|
30
|
+
"prepare": "husky",
|
|
31
|
+
"test": "vitest run",
|
|
32
|
+
"test:coverage": "vitest run --coverage"
|
|
33
|
+
},
|
|
25
34
|
"peerDependencies": {
|
|
26
35
|
"typescript": "^5.1.0"
|
|
27
36
|
},
|
|
@@ -29,21 +38,20 @@
|
|
|
29
38
|
"type-fest": "^4.11.1"
|
|
30
39
|
},
|
|
31
40
|
"devDependencies": {
|
|
32
|
-
"@
|
|
41
|
+
"@commitlint/cli": "^19.2.1",
|
|
42
|
+
"@commitlint/config-conventional": "^19.1.0",
|
|
43
|
+
"@commitlint/types": "^19.0.3",
|
|
44
|
+
"@douglasneuroinformatics/eslint-config": "^4.2.1",
|
|
45
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
46
|
+
"@semantic-release/git": "^10.0.1",
|
|
47
|
+
"@semantic-release/npm": "^12.0.0",
|
|
33
48
|
"@vitest/coverage-v8": "^1.3.1",
|
|
34
49
|
"eslint": "^8.57.0",
|
|
35
50
|
"husky": "^9.0.11",
|
|
36
51
|
"prettier": "^3.2.5",
|
|
52
|
+
"semantic-release": "^23.0.5",
|
|
37
53
|
"typedoc": "^0.25.2",
|
|
38
54
|
"typescript": "~5.3.3",
|
|
39
55
|
"vitest": "^1.3.1"
|
|
40
|
-
},
|
|
41
|
-
"scripts": {
|
|
42
|
-
"build": "tsc",
|
|
43
|
-
"build:docs": "typedoc",
|
|
44
|
-
"format": "prettier --write src",
|
|
45
|
-
"lint": "tsc --noEmit && eslint --fix src",
|
|
46
|
-
"test": "vitest run",
|
|
47
|
-
"test:coverage": "vitest run --coverage"
|
|
48
56
|
}
|
|
49
|
-
}
|
|
57
|
+
}
|