@douglasneuroinformatics/libjs 0.0.2 → 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/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
@@ -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
+ }
@@ -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
@@ -1,4 +1,8 @@
1
1
  import type { CamelCase, 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
+ export declare function uncapitalize<T extends string>(s: T): Uncapitalize<T>;
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>;
4
8
  //# sourceMappingURL=string.d.ts.map
@@ -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"}
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
@@ -6,3 +6,15 @@ export function snakeToCamelCase(s) {
6
6
  .toLowerCase()
7
7
  .replace(/([-_][a-z])/g, (group) => group.toUpperCase().replace('-', '').replace('_', ''));
8
8
  }
9
+ export function uncapitalize(s) {
10
+ return (s.charAt(0).toLowerCase() + s.slice(1));
11
+ }
12
+ export function capitalize(s) {
13
+ return (s.charAt(0).toUpperCase() + s.slice(1));
14
+ }
15
+ export function toLowerCase(s) {
16
+ return s.toLowerCase();
17
+ }
18
+ export function toUpperCase(s) {
19
+ return s.toUpperCase();
20
+ }
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { camelToSnakeCase, snakeToCamelCase } 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');
@@ -14,3 +14,27 @@ describe('snakeToCamelCase', () => {
14
14
  expect(camelToSnakeCase('')).toBe('');
15
15
  });
16
16
  });
17
+ describe('capitalize', () => {
18
+ it('should convert the first letter of the string to a capital letter', () => {
19
+ expect(capitalize('foo')).toBe('Foo');
20
+ expect(capitalize('FOO')).toBe('FOO');
21
+ expect(capitalize('foo bar')).toBe('Foo bar');
22
+ });
23
+ });
24
+ describe('uncapitalize', () => {
25
+ it('should convert the first letter of the string to a lowercase letter', () => {
26
+ expect(uncapitalize('Foo')).toBe('foo');
27
+ expect(uncapitalize('foo')).toBe('foo');
28
+ expect(uncapitalize('Foo bar')).toBe('foo bar');
29
+ });
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,9 +1,13 @@
1
1
  {
2
2
  "name": "@douglasneuroinformatics/libjs",
3
3
  "type": "module",
4
- "version": "0.0.2",
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
+ "author": {
8
+ "name": "Douglas Neuroinformatics",
9
+ "email": "support@douglasneuroinformatics.ca"
10
+ },
7
11
  "license": "LGPL-3.0",
8
12
  "homepage": "https://github.com/DouglasNeuroInformatics/libjs/#readme",
9
13
  "repository": {
@@ -23,6 +27,7 @@
23
27
  "build:docs": "typedoc",
24
28
  "format": "prettier --write src",
25
29
  "lint": "tsc --noEmit && eslint --fix src",
30
+ "prepare": "husky",
26
31
  "test": "vitest run",
27
32
  "test:coverage": "vitest run --coverage"
28
33
  },
@@ -33,10 +38,18 @@
33
38
  "type-fest": "^4.11.1"
34
39
  },
35
40
  "devDependencies": {
36
- "@douglasneuroinformatics/eslint-config": "^4.0.0",
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",
37
48
  "@vitest/coverage-v8": "^1.3.1",
38
49
  "eslint": "^8.57.0",
50
+ "husky": "^9.0.11",
39
51
  "prettier": "^3.2.5",
52
+ "semantic-release": "^23.0.5",
40
53
  "typedoc": "^0.25.2",
41
54
  "typescript": "~5.3.3",
42
55
  "vitest": "^1.3.1"