@douglasneuroinformatics/libjs 0.0.1 → 0.0.2

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.
@@ -25,3 +25,4 @@ export declare function yearsPassed(date: Date): number;
25
25
  * ```
26
26
  */
27
27
  export declare function sleep(seconds: number): Promise<unknown>;
28
+ //# sourceMappingURL=datetime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datetime.d.ts","sourceRoot":"","sources":["../src/datetime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAEnD;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE9C;AAED;;;;;;GAMG;AACH,wBAAsB,KAAK,CAAC,OAAO,EAAE,MAAM,oBAE1C"}
package/dist/datetime.js CHANGED
@@ -29,5 +29,5 @@ export function yearsPassed(date) {
29
29
  * ```
30
30
  */
31
31
  export async function sleep(seconds) {
32
- return new Promise((resolve) => setTimeout(resolve, seconds / 1000));
32
+ return new Promise((resolve) => setTimeout(resolve, seconds * 1000));
33
33
  }
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=datetime.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datetime.test.d.ts","sourceRoot":"","sources":["../src/datetime.test.ts"],"names":[],"mappings":""}
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { toBasicISOString, yearsPassed } from './datetime.js';
2
+ import { sleep, toBasicISOString, yearsPassed } from './datetime.js';
3
3
  describe('toBasicISOString', () => {
4
4
  it('should return a string of the format yyyy-mm-dd', () => {
5
5
  expect(toBasicISOString(new Date(2000, 0, 1))).toBe('2000-01-01');
@@ -17,3 +17,11 @@ describe('yearsPassed', () => {
17
17
  expect(yearsPassed(date)).toBe(1);
18
18
  });
19
19
  });
20
+ describe('sleep', () => {
21
+ it('should wait for at least the specified time', async () => {
22
+ const start = Date.now();
23
+ await sleep(0.2);
24
+ const end = Date.now();
25
+ expect(end - start).toBeGreaterThanOrEqual(200);
26
+ });
27
+ });
package/dist/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export * from './object.js';
3
3
  export * from './random.js';
4
4
  export * from './range.js';
5
5
  export * from './string.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
package/dist/object.d.ts CHANGED
@@ -2,3 +2,4 @@ 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
+ //# sourceMappingURL=object.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=object.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.test.d.ts","sourceRoot":"","sources":["../src/object.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { deepFreeze } from './object.js';
3
+ describe('deepFreeze', () => {
4
+ it('should not allow mutating a primitive value', () => {
5
+ const obj = deepFreeze({ foo: 1 });
6
+ expect(() => {
7
+ // @ts-expect-error - check runtime behavior
8
+ obj.foo = 2;
9
+ }).toThrow();
10
+ });
11
+ it('should not allow mutating a nested object', () => {
12
+ const obj = deepFreeze({ foo: { bar: 1 } });
13
+ expect(() => {
14
+ // @ts-expect-error - check runtime behavior
15
+ obj.foo.bar = 2;
16
+ }).toThrow();
17
+ });
18
+ it('should not allow mutating a deeply nested array', () => {
19
+ const obj = deepFreeze({ foo: { bar: [1, 2, 3] } });
20
+ expect(() => {
21
+ // @ts-expect-error - check runtime behavior
22
+ obj.foo.bar[0] = 2;
23
+ }).toThrow();
24
+ });
25
+ });
package/dist/random.d.ts CHANGED
@@ -4,3 +4,4 @@ export declare function randomInt(min: number, max: number): number;
4
4
  export declare function randomDate(start: Date, end: Date): Date;
5
5
  /** Returns a random value from the array */
6
6
  export declare function randomValue<T>(arr: T[]): T;
7
+ //# sourceMappingURL=random.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,UAKjD;AAED,uEAAuE;AACvE,wBAAgB,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,QAKhD;AAED,4CAA4C;AAC5C,wBAAgB,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAKtC"}
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=random.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"random.test.d.ts","sourceRoot":"","sources":["../src/random.test.ts"],"names":[],"mappings":""}
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { randomDate, randomInt } from './random.js';
2
+ import { randomDate, randomInt, randomValue } from './random.js';
3
3
  describe('randomInt', () => {
4
4
  it('should return an integer value within the range', () => {
5
5
  const min = 5;
@@ -37,3 +37,17 @@ describe('randomDate', () => {
37
37
  expect(() => randomDate(new Date(), new Date(2000, 0, 1))).toThrow();
38
38
  });
39
39
  });
40
+ describe('randomValue', () => {
41
+ it('should throw if given an empty array', () => {
42
+ expect(() => randomValue([])).toThrow();
43
+ });
44
+ it('should return a value in the array', () => {
45
+ const arr = [-10, -20, -30];
46
+ expect(arr.includes(randomValue(arr)));
47
+ });
48
+ it('should not mutate the array', () => {
49
+ const arr = [-10, -20, -30];
50
+ randomValue(arr);
51
+ expect(arr).toMatchObject([-10, -20, -30]);
52
+ });
53
+ });
package/dist/range.d.ts CHANGED
@@ -2,3 +2,4 @@
2
2
  export declare function range(end: number): readonly number[];
3
3
  /** Return an array of integers between `start` (inclusive) and `end` (not inclusive) */
4
4
  export declare function range(start: number, end: number): readonly number[];
5
+ //# sourceMappingURL=range.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../src/range.ts"],"names":[],"mappings":"AAEA,kFAAkF;AAClF,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;AAEtD,wFAAwF;AACxF,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC"}
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=range.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"range.test.d.ts","sourceRoot":"","sources":["../src/range.test.ts"],"names":[],"mappings":""}
@@ -5,4 +5,7 @@ describe('range', () => {
5
5
  const arr = range(10);
6
6
  expect(arr.length).toBe(10);
7
7
  });
8
+ it('should throw an error if the start is equal to the end', () => {
9
+ expect(() => range(1, 1)).toThrow();
10
+ });
8
11
  });
package/dist/string.d.ts CHANGED
@@ -1,3 +1,4 @@
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
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +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 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=string.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.test.d.ts","sourceRoot":"","sources":["../src/string.test.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@douglasneuroinformatics/libjs",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
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
  "license": "LGPL-3.0",
@@ -18,6 +18,14 @@
18
18
  "files": [
19
19
  "dist"
20
20
  ],
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "build:docs": "typedoc",
24
+ "format": "prettier --write src",
25
+ "lint": "tsc --noEmit && eslint --fix src",
26
+ "test": "vitest run",
27
+ "test:coverage": "vitest run --coverage"
28
+ },
21
29
  "peerDependencies": {
22
30
  "typescript": "^5.1.0"
23
31
  },
@@ -32,13 +40,5 @@
32
40
  "typedoc": "^0.25.2",
33
41
  "typescript": "~5.3.3",
34
42
  "vitest": "^1.3.1"
35
- },
36
- "scripts": {
37
- "build": "tsc",
38
- "build:docs": "typedoc",
39
- "format": "prettier --write src",
40
- "lint": "tsc --noEmit && eslint --fix src",
41
- "test": "vitest run",
42
- "test:coverage": "vitest run --coverage"
43
43
  }
44
- }
44
+ }