magic-utils-yonava 1.0.2 → 1.0.4
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/clone.d.ts +9 -0
- package/dist/clone.js +15 -0
- package/dist/clone.test.d.ts +1 -0
- package/dist/clone.test.js +42 -0
- package/dist/colors.d.ts +522 -0
- package/{src/colors.ts → dist/colors.js} +224 -274
- package/dist/ctx/index.d.ts +10 -0
- package/dist/ctx/index.js +19 -0
- package/dist/debounce.d.ts +9 -0
- package/{src/debounce.ts → dist/debounce.js} +6 -6
- package/dist/debugging.d.ts +2 -0
- package/dist/debugging.js +21 -0
- package/dist/deepDelta/delta.test.d.ts +1 -0
- package/dist/deepDelta/delta.test.js +114 -0
- package/dist/deepDelta/index.d.ts +8 -0
- package/dist/deepDelta/index.js +40 -0
- package/dist/deepMerge.d.ts +16 -0
- package/dist/deepMerge.js +32 -0
- package/dist/deepMerge.test.d.ts +1 -0
- package/dist/deepMerge.test.js +68 -0
- package/dist/fps.d.ts +6 -0
- package/dist/fps.js +51 -0
- package/dist/fracDecConverter/index.d.ts +9 -0
- package/dist/fracDecConverter/index.js +34 -0
- package/dist/hashing.d.ts +2 -0
- package/dist/hashing.js +7 -0
- package/dist/id.d.ts +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/localStorage.d.ts +37 -0
- package/dist/localStorage.js +22 -0
- package/dist/math.d.ts +60 -0
- package/{src/math.ts → dist/math.js} +28 -32
- package/dist/math.test.d.ts +1 -0
- package/dist/math.test.js +42 -0
- package/{src/maybeGetter/index.ts → dist/maybeGetter/index.d.ts} +3 -18
- package/dist/maybeGetter/index.js +15 -0
- package/dist/mouse.d.ts +8 -0
- package/{src/mouse.ts → dist/mouse.js} +4 -4
- package/dist/random.d.ts +19 -0
- package/dist/random.js +21 -0
- package/dist/sets.d.ts +8 -0
- package/{src/sets.ts → dist/sets.js} +2 -2
- package/dist/string.d.ts +21 -0
- package/{src/string.ts → dist/string.js} +11 -11
- package/dist/string.test.d.ts +1 -0
- package/dist/string.test.js +14 -0
- package/{src/types.ts → dist/types.d.ts} +13 -38
- package/dist/types.js +1 -0
- package/dist/utils/clone.d.ts +9 -0
- package/dist/utils/clone.js +15 -0
- package/dist/utils/clone.test.d.ts +1 -0
- package/dist/utils/clone.test.js +42 -0
- package/dist/utils/colors.d.ts +522 -0
- package/dist/utils/colors.js +517 -0
- package/dist/utils/ctx/index.d.ts +10 -0
- package/dist/utils/ctx/index.js +19 -0
- package/dist/utils/debounce.d.ts +9 -0
- package/dist/utils/debounce.js +15 -0
- package/dist/utils/debugging.d.ts +2 -0
- package/dist/utils/debugging.js +21 -0
- package/dist/utils/deepDelta/delta.test.d.ts +1 -0
- package/dist/utils/deepDelta/delta.test.js +114 -0
- package/dist/utils/deepDelta/index.d.ts +8 -0
- package/dist/utils/deepDelta/index.js +40 -0
- package/dist/utils/deepMerge.d.ts +16 -0
- package/dist/utils/deepMerge.js +32 -0
- package/dist/utils/deepMerge.test.d.ts +1 -0
- package/dist/utils/deepMerge.test.js +68 -0
- package/dist/utils/fps.d.ts +6 -0
- package/dist/utils/fps.js +51 -0
- package/dist/utils/fracDecConverter/index.d.ts +9 -0
- package/dist/utils/fracDecConverter/index.js +34 -0
- package/dist/utils/hashing.d.ts +2 -0
- package/dist/utils/hashing.js +7 -0
- package/dist/utils/id.d.ts +5 -0
- package/dist/utils/id.js +5 -0
- package/dist/utils/localStorage.d.ts +37 -0
- package/dist/utils/localStorage.js +22 -0
- package/dist/utils/math.d.ts +60 -0
- package/dist/utils/math.js +89 -0
- package/dist/utils/math.test.d.ts +1 -0
- package/dist/utils/math.test.js +42 -0
- package/dist/utils/maybeGetter/index.d.ts +26 -0
- package/dist/utils/maybeGetter/index.js +15 -0
- package/dist/utils/mouse.d.ts +8 -0
- package/dist/utils/mouse.js +8 -0
- package/dist/utils/random.d.ts +19 -0
- package/dist/utils/random.js +21 -0
- package/dist/utils/sets.d.ts +8 -0
- package/dist/utils/sets.js +10 -0
- package/dist/utils/string.d.ts +21 -0
- package/dist/utils/string.js +31 -0
- package/dist/utils/string.test.d.ts +1 -0
- package/dist/utils/string.test.js +14 -0
- package/dist/utils/types.d.ts +54 -0
- package/dist/utils/types.js +1 -0
- package/package.json +4 -1
- package/src/clone.test.ts +0 -47
- package/src/clone.ts +0 -15
- package/src/ctx/index.ts +0 -20
- package/src/debugging.ts +0 -23
- package/src/deepDelta/delta.test.ts +0 -129
- package/src/deepDelta/index.ts +0 -48
- package/src/deepMerge.test.ts +0 -89
- package/src/deepMerge.ts +0 -37
- package/src/fps.ts +0 -64
- package/src/fracDecConverter/index.ts +0 -36
- package/src/hashing.ts +0 -9
- package/src/localStorage.ts +0 -49
- package/src/math.test.ts +0 -57
- package/src/random.ts +0 -27
- package/src/string.test.ts +0 -17
- package/tsconfig.json +0 -20
- /package/{src/id.ts → dist/id.js} +0 -0
package/src/localStorage.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
type LocalStorageGetter = (...args: any[]) => string;
|
|
4
|
-
type LocalStorageRecord = Record<string, string | LocalStorageGetter>;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* a registry for all localStorage keys this application uses
|
|
8
|
-
*/
|
|
9
|
-
export const localKeys = {
|
|
10
|
-
/** nodes in graph product */
|
|
11
|
-
nodes: (key: string) => `nodes-${key}` as const,
|
|
12
|
-
/** edges in graph product */
|
|
13
|
-
edges: (key: string) => `edges-${key}` as const,
|
|
14
|
-
/** graph product simulation speed */
|
|
15
|
-
simulationPlaybackSpeed: 'simulation-playback-speed',
|
|
16
|
-
/** graph theme set by user - {@link Graph.preferredTheme} */
|
|
17
|
-
preferredTheme: 'preferred-theme',
|
|
18
|
-
} as const satisfies LocalStorageRecord;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* all return values of localStorage are, by default, string.
|
|
22
|
-
* this type allows string to be narrowed to types such as 'true' | 'false'
|
|
23
|
-
*/
|
|
24
|
-
type TypeOverride = {};
|
|
25
|
-
|
|
26
|
-
type LocalObj = typeof localKeys;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @example
|
|
30
|
-
* type T = TypeOrReturnType<number> // number
|
|
31
|
-
* type TFunc = TypeOrReturnType<() => number> // number
|
|
32
|
-
*/
|
|
33
|
-
type TypeOrReturnType<T> = T extends (...args: any[]) => infer U ? U : T;
|
|
34
|
-
|
|
35
|
-
type LocalKeys = TypeOrReturnType<LocalObj[keyof LocalObj]>;
|
|
36
|
-
type LocalType<T extends LocalKeys> = T extends keyof TypeOverride
|
|
37
|
-
? TypeOverride[T]
|
|
38
|
-
: string;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* perform **type safe** localStorage actions
|
|
42
|
-
*/
|
|
43
|
-
export const local = {
|
|
44
|
-
get: <T extends LocalKeys>(key: T) => localStorage.getItem(key),
|
|
45
|
-
set: <T extends LocalKeys, K extends LocalType<T>>(key: T, value: K) =>
|
|
46
|
-
localStorage.setItem(key, value),
|
|
47
|
-
remove: <T extends LocalKeys>(key: T) => localStorage.removeItem(key),
|
|
48
|
-
clear: localStorage.clear,
|
|
49
|
-
};
|
package/src/math.test.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
average,
|
|
5
|
-
gcd,
|
|
6
|
-
getPrimeFactors,
|
|
7
|
-
lowestPrimeFactor,
|
|
8
|
-
roundToNearestN,
|
|
9
|
-
} from './math';
|
|
10
|
-
|
|
11
|
-
describe('roundToNearestN', () => {
|
|
12
|
-
test('rounds a number to the nearest multiple of n', () => {
|
|
13
|
-
const roundToNearest5 = roundToNearestN(5);
|
|
14
|
-
expect(roundToNearest5(13)).toBe(15);
|
|
15
|
-
expect(roundToNearest5(12)).toBe(10);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe('getPrimeFactors', () => {
|
|
20
|
-
test('returns the prime factors of a number', () => {
|
|
21
|
-
expect(getPrimeFactors(12)).toEqual([2, 2, 3]);
|
|
22
|
-
expect(getPrimeFactors(15)).toEqual([3, 5]);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('edge case: 1', () => {
|
|
26
|
-
expect(getPrimeFactors(1)).toEqual([]);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('lowestPrimeFactor', () => {
|
|
31
|
-
test('returns the lowest prime factor of a number', () => {
|
|
32
|
-
expect(lowestPrimeFactor(12)).toBe(2);
|
|
33
|
-
expect(lowestPrimeFactor(15)).toBe(3);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('edge case: 1', () => {
|
|
37
|
-
expect(lowestPrimeFactor(1)).toBe(1);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('gcd', () => {
|
|
42
|
-
test('returns the greatest common divisor of two numbers', () => {
|
|
43
|
-
expect(gcd(12, 15)).toBe(3);
|
|
44
|
-
expect(gcd(12, 18)).toBe(6);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
describe('average', () => {
|
|
49
|
-
test('returns the average of a list of numbers', () => {
|
|
50
|
-
expect(average([1, 2, 3, 4, 5])).toBe(3);
|
|
51
|
-
expect(average([1, 2, 3, 4, 5, 6])).toBe(3.5);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('edge case: empty list', () => {
|
|
55
|
-
expect(average([])).toBe(0);
|
|
56
|
-
});
|
|
57
|
-
});
|
package/src/random.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* given two numbers, this function returns a random number between them (inclusive)
|
|
3
|
-
*
|
|
4
|
-
* @param min - the lowest number
|
|
5
|
-
* @param max - the highest number
|
|
6
|
-
* @returns a random number between min and max
|
|
7
|
-
*/
|
|
8
|
-
export const getRandomInRange = (min: number, max: number) =>
|
|
9
|
-
Math.round(Math.random() * (max - min) + min);
|
|
10
|
-
|
|
11
|
-
export const getRandomPointOnCanvas = (
|
|
12
|
-
canvas: HTMLCanvasElement,
|
|
13
|
-
buffer = 50,
|
|
14
|
-
) => ({
|
|
15
|
-
x: getRandomInRange(buffer, canvas.width - buffer),
|
|
16
|
-
y: getRandomInRange(buffer, canvas.height - buffer),
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* get a random element from an array
|
|
21
|
-
*
|
|
22
|
-
* @param array
|
|
23
|
-
* @returns random element from given array
|
|
24
|
-
*/
|
|
25
|
-
export const getRandomElement = <T>(array: ArrayLike<T>) => {
|
|
26
|
-
return array[Math.floor(Math.random() * array.length)];
|
|
27
|
-
};
|
package/src/string.test.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { camelCaseToTitleCase, capitalize } from './string';
|
|
4
|
-
|
|
5
|
-
describe('capitalize', () => {
|
|
6
|
-
test('capitalizes the first letter of a string', () => {
|
|
7
|
-
expect(capitalize('hello')).toBe('Hello');
|
|
8
|
-
expect(capitalize('this is one string')).toBe('This is one string');
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
describe('camelCaseToTitleCase', () => {
|
|
13
|
-
test('converts camelCase to title case', () => {
|
|
14
|
-
expect(camelCaseToTitleCase('camelCase')).toBe('Camel Case');
|
|
15
|
-
expect(camelCaseToTitleCase('thisIsOneString')).toBe('This Is One String');
|
|
16
|
-
});
|
|
17
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"outDir": "./dist",
|
|
4
|
-
"rootDir": "./src",
|
|
5
|
-
|
|
6
|
-
"target": "ES2022",
|
|
7
|
-
"module": "ESNext",
|
|
8
|
-
"lib": ["ES2023", "DOM"],
|
|
9
|
-
"types": ["node"],
|
|
10
|
-
"moduleResolution": "node",
|
|
11
|
-
"allowJs": false,
|
|
12
|
-
"strict": true,
|
|
13
|
-
"esModuleInterop": true,
|
|
14
|
-
"forceConsistentCasingInFileNames": true,
|
|
15
|
-
"resolveJsonModule": true,
|
|
16
|
-
"skipLibCheck": true,
|
|
17
|
-
"declaration": true,
|
|
18
|
-
},
|
|
19
|
-
"include": ["src/**/*"],
|
|
20
|
-
}
|
|
File without changes
|