@oscarpalmer/atoms 0.100.0 → 0.102.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/array/get.cjs +29 -0
- package/dist/array/get.js +25 -0
- package/dist/array/index.cjs +2 -0
- package/dist/array/index.js +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.js +1 -0
- package/dist/internal/function.cjs +22 -20
- package/dist/internal/function.js +22 -20
- package/package.json +4 -4
- package/src/array/get.ts +69 -0
- package/src/array/index.ts +1 -0
- package/src/internal/function.ts +34 -30
- package/types/array/get.d.cts +31 -0
- package/types/array/get.d.ts +25 -0
- package/types/array/index.d.cts +23 -0
- package/types/array/index.d.ts +1 -0
- package/types/index.d.cts +23 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const internal_is = require('../internal/is.cjs');
|
|
6
|
+
|
|
7
|
+
function getArray(value, indiced) {
|
|
8
|
+
if (Array.isArray(value)) {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
if (internal_is.isPlainObject(value)) {
|
|
12
|
+
if (indiced !== true) {
|
|
13
|
+
return Object.values(value);
|
|
14
|
+
}
|
|
15
|
+
const keys = Object.keys(value);
|
|
16
|
+
const { length } = keys;
|
|
17
|
+
const array = [];
|
|
18
|
+
for (let index = 0; index < length; index += 1) {
|
|
19
|
+
const key = keys[index];
|
|
20
|
+
if (!Number.isNaN(Number(key))) {
|
|
21
|
+
array.push(value[key]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return array;
|
|
25
|
+
}
|
|
26
|
+
return [value];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.getArray = getArray;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isPlainObject } from '../internal/is.js';
|
|
2
|
+
|
|
3
|
+
function getArray(value, indiced) {
|
|
4
|
+
if (Array.isArray(value)) {
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
if (isPlainObject(value)) {
|
|
8
|
+
if (indiced !== true) {
|
|
9
|
+
return Object.values(value);
|
|
10
|
+
}
|
|
11
|
+
const keys = Object.keys(value);
|
|
12
|
+
const { length } = keys;
|
|
13
|
+
const array = [];
|
|
14
|
+
for (let index = 0; index < length; index += 1) {
|
|
15
|
+
const key = keys[index];
|
|
16
|
+
if (!Number.isNaN(Number(key))) {
|
|
17
|
+
array.push(value[key]);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return array;
|
|
21
|
+
}
|
|
22
|
+
return [value];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { getArray };
|
package/dist/array/index.cjs
CHANGED
|
@@ -10,6 +10,7 @@ const array_exists = require('./exists.cjs');
|
|
|
10
10
|
const array_filter = require('./filter.cjs');
|
|
11
11
|
const array_find = require('./find.cjs');
|
|
12
12
|
const array_flatten = require('./flatten.cjs');
|
|
13
|
+
const array_get = require('./get.cjs');
|
|
13
14
|
const array_groupBy = require('./group-by.cjs');
|
|
14
15
|
const array_indexOf = require('./index-of.cjs');
|
|
15
16
|
const array_insert = require('./insert.cjs');
|
|
@@ -30,6 +31,7 @@ exports.exists = array_exists.exists;
|
|
|
30
31
|
exports.filter = array_filter.filter;
|
|
31
32
|
exports.find = array_find.find;
|
|
32
33
|
exports.flatten = array_flatten.flatten;
|
|
34
|
+
exports.getArray = array_get.getArray;
|
|
33
35
|
exports.groupBy = array_groupBy.groupBy;
|
|
34
36
|
exports.indexOf = array_indexOf.indexOf;
|
|
35
37
|
exports.insert = array_insert.insert;
|
package/dist/array/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { exists } from './exists.js';
|
|
|
6
6
|
export { filter } from './filter.js';
|
|
7
7
|
export { find } from './find.js';
|
|
8
8
|
export { flatten } from './flatten.js';
|
|
9
|
+
export { getArray } from './get.js';
|
|
9
10
|
export { groupBy } from './group-by.js';
|
|
10
11
|
export { indexOf } from './index-of.js';
|
|
11
12
|
export { insert } from './insert.js';
|
package/dist/index.cjs
CHANGED
|
@@ -10,6 +10,7 @@ const array_exists = require('./array/exists.cjs');
|
|
|
10
10
|
const array_filter = require('./array/filter.cjs');
|
|
11
11
|
const array_find = require('./array/find.cjs');
|
|
12
12
|
const array_flatten = require('./array/flatten.cjs');
|
|
13
|
+
const array_get = require('./array/get.cjs');
|
|
13
14
|
const array_groupBy = require('./array/group-by.cjs');
|
|
14
15
|
const array_indexOf = require('./array/index-of.cjs');
|
|
15
16
|
const array_insert = require('./array/insert.cjs');
|
|
@@ -61,6 +62,7 @@ exports.exists = array_exists.exists;
|
|
|
61
62
|
exports.filter = array_filter.filter;
|
|
62
63
|
exports.find = array_find.find;
|
|
63
64
|
exports.flatten = array_flatten.flatten;
|
|
65
|
+
exports.getArray = array_get.getArray;
|
|
64
66
|
exports.groupBy = array_groupBy.groupBy;
|
|
65
67
|
exports.indexOf = array_indexOf.indexOf;
|
|
66
68
|
exports.insert = array_insert.insert;
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { exists } from './array/exists.js';
|
|
|
6
6
|
export { filter } from './array/filter.js';
|
|
7
7
|
export { find } from './array/find.js';
|
|
8
8
|
export { flatten } from './array/flatten.js';
|
|
9
|
+
export { getArray } from './array/get.js';
|
|
9
10
|
export { groupBy } from './array/group-by.js';
|
|
10
11
|
export { indexOf } from './array/index-of.js';
|
|
11
12
|
export { insert } from './array/insert.js';
|
|
@@ -2,28 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
function calculate() {
|
|
6
|
+
return new Promise((resolve) => {
|
|
7
|
+
const values = [];
|
|
8
|
+
let last;
|
|
9
|
+
function step(now) {
|
|
10
|
+
if (last != null) {
|
|
11
|
+
values.push(now - last);
|
|
12
|
+
}
|
|
13
|
+
last = now;
|
|
14
|
+
if (values.length >= 10) {
|
|
15
|
+
const median = values.sort().slice(2, -2).reduce((first, second) => first + second, 0) / (values.length - 4);
|
|
16
|
+
resolve(median);
|
|
17
|
+
} else {
|
|
18
|
+
requestAnimationFrame(step);
|
|
19
|
+
}
|
|
19
20
|
}
|
|
20
|
-
last = now;
|
|
21
21
|
requestAnimationFrame(step);
|
|
22
|
-
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function noop() {
|
|
23
25
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
exports.milliseconds =
|
|
27
|
-
|
|
26
|
+
exports.milliseconds = 1e3 / 60;
|
|
27
|
+
calculate().then((value) => {
|
|
28
|
+
exports.milliseconds = value;
|
|
29
|
+
});
|
|
28
30
|
|
|
29
31
|
exports.noop = noop;
|
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
function calculate() {
|
|
2
|
+
return new Promise((resolve) => {
|
|
3
|
+
const values = [];
|
|
4
|
+
let last;
|
|
5
|
+
function step(now) {
|
|
6
|
+
if (last != null) {
|
|
7
|
+
values.push(now - last);
|
|
8
|
+
}
|
|
9
|
+
last = now;
|
|
10
|
+
if (values.length >= 10) {
|
|
11
|
+
const median = values.sort().slice(2, -2).reduce((first, second) => first + second, 0) / (values.length - 4);
|
|
12
|
+
resolve(median);
|
|
13
|
+
} else {
|
|
14
|
+
requestAnimationFrame(step);
|
|
15
|
+
}
|
|
15
16
|
}
|
|
16
|
-
last = now;
|
|
17
17
|
requestAnimationFrame(step);
|
|
18
|
-
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function noop() {
|
|
19
21
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
let milliseconds = 1e3 / 60;
|
|
23
|
+
calculate().then((value) => {
|
|
24
|
+
milliseconds = value;
|
|
25
|
+
});
|
|
24
26
|
|
|
25
27
|
export { milliseconds, noop };
|
package/package.json
CHANGED
|
@@ -11,15 +11,15 @@
|
|
|
11
11
|
"@biomejs/biome": "^1.9",
|
|
12
12
|
"@rollup/plugin-node-resolve": "^16",
|
|
13
13
|
"@rollup/plugin-typescript": "^12.1",
|
|
14
|
-
"@types/node": "^
|
|
15
|
-
"@vitest/coverage-istanbul": "^3.
|
|
14
|
+
"@types/node": "^24",
|
|
15
|
+
"@vitest/coverage-istanbul": "^3.2",
|
|
16
16
|
"dts-bundle-generator": "^9.5",
|
|
17
17
|
"glob": "^11",
|
|
18
18
|
"jsdom": "^26.1",
|
|
19
19
|
"tslib": "^2.8",
|
|
20
20
|
"typescript": "^5.8",
|
|
21
21
|
"vite": "^6.3",
|
|
22
|
-
"vitest": "^3.
|
|
22
|
+
"vitest": "^3.2"
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
25
|
"./package.json": "./package.json",
|
|
@@ -202,5 +202,5 @@
|
|
|
202
202
|
},
|
|
203
203
|
"type": "module",
|
|
204
204
|
"types": "./types/index.d.cts",
|
|
205
|
-
"version": "0.
|
|
205
|
+
"version": "0.102.0"
|
|
206
206
|
}
|
package/src/array/get.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {isPlainObject} from '../internal/is';
|
|
2
|
+
import type {PlainObject} from '../models';
|
|
3
|
+
|
|
4
|
+
type NumericalKeys<Value> = {
|
|
5
|
+
[Key in keyof Value]: Key extends number
|
|
6
|
+
? Key
|
|
7
|
+
: Key extends `${number}`
|
|
8
|
+
? Key
|
|
9
|
+
: never;
|
|
10
|
+
}[keyof Value];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Get an array from a value
|
|
14
|
+
*/
|
|
15
|
+
export function getArray<Item>(value: Item[]): Item[];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get an array from an object
|
|
19
|
+
*/
|
|
20
|
+
export function getArray<Value extends PlainObject>(
|
|
21
|
+
value: Value,
|
|
22
|
+
): Array<Value[keyof Value]>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Get an array from an object, where only values with numeric keys will be included
|
|
26
|
+
*/
|
|
27
|
+
export function getArray<Value extends PlainObject>(
|
|
28
|
+
value: Value,
|
|
29
|
+
indiced: true,
|
|
30
|
+
): Array<Value[NumericalKeys<Value>]>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Get an array from a value
|
|
34
|
+
*/
|
|
35
|
+
export function getArray<Item>(value: Item): Item[];
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Get an array from a value
|
|
39
|
+
*/
|
|
40
|
+
export function getArray(value: unknown): unknown[];
|
|
41
|
+
|
|
42
|
+
export function getArray(value: unknown, indiced?: unknown): unknown[] {
|
|
43
|
+
if (Array.isArray(value)) {
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (isPlainObject(value)) {
|
|
48
|
+
if (indiced !== true) {
|
|
49
|
+
return Object.values(value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const keys = Object.keys(value);
|
|
53
|
+
const {length} = keys;
|
|
54
|
+
|
|
55
|
+
const array: unknown[] = [];
|
|
56
|
+
|
|
57
|
+
for (let index = 0; index < length; index += 1) {
|
|
58
|
+
const key = keys[index];
|
|
59
|
+
|
|
60
|
+
if (!Number.isNaN(Number(key))) {
|
|
61
|
+
array.push(value[key]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return array;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return [value];
|
|
69
|
+
}
|
package/src/array/index.ts
CHANGED
package/src/internal/function.ts
CHANGED
|
@@ -1,40 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
function calculate(): Promise<number> {
|
|
2
|
+
return new Promise(resolve => {
|
|
3
|
+
const values: number[] = [];
|
|
4
|
+
|
|
5
|
+
let last: DOMHighResTimeStamp | undefined;
|
|
6
|
+
|
|
7
|
+
function step(now: DOMHighResTimeStamp): void {
|
|
8
|
+
if (last != null) {
|
|
9
|
+
values.push(now - last);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
last = now;
|
|
13
|
+
|
|
14
|
+
if (values.length >= 10) {
|
|
15
|
+
const median =
|
|
16
|
+
values
|
|
17
|
+
.sort()
|
|
18
|
+
.slice(2, -2)
|
|
19
|
+
.reduce((first, second) => first + second, 0) /
|
|
20
|
+
(values.length - 4);
|
|
21
|
+
|
|
22
|
+
resolve(median);
|
|
23
|
+
} else {
|
|
24
|
+
requestAnimationFrame(step);
|
|
25
|
+
}
|
|
22
26
|
}
|
|
23
27
|
|
|
24
|
-
last = now;
|
|
25
|
-
|
|
26
28
|
requestAnimationFrame(step);
|
|
27
|
-
}
|
|
29
|
+
});
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
/**
|
|
33
|
+
* A function that does nothing, which can be useful, I guess…
|
|
34
|
+
*/
|
|
35
|
+
export function noop(): void {}
|
|
34
36
|
|
|
35
37
|
/**
|
|
36
38
|
* A calculated average of the refresh rate of the display _(in milliseconds)_
|
|
37
39
|
*/
|
|
38
|
-
export let milliseconds =
|
|
40
|
+
export let milliseconds = 1000 / 60;
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
calculate().then(value => {
|
|
43
|
+
milliseconds = value;
|
|
44
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A generic object
|
|
5
|
+
*/
|
|
6
|
+
export type PlainObject = Record<PropertyKey, unknown>;
|
|
7
|
+
export type NumericalKeys<Value> = {
|
|
8
|
+
[Key in keyof Value]: Key extends number ? Key : Key extends `${number}` ? Key : never;
|
|
9
|
+
}[keyof Value];
|
|
10
|
+
/**
|
|
11
|
+
* Get an array from a value
|
|
12
|
+
*/
|
|
13
|
+
export declare function getArray<Item>(value: Item[]): Item[];
|
|
14
|
+
/**
|
|
15
|
+
* Get an array from an object
|
|
16
|
+
*/
|
|
17
|
+
export declare function getArray<Value extends PlainObject>(value: Value): Array<Value[keyof Value]>;
|
|
18
|
+
/**
|
|
19
|
+
* Get an array from an object, where only values with numeric keys will be included
|
|
20
|
+
*/
|
|
21
|
+
export declare function getArray<Value extends PlainObject>(value: Value, indiced: true): Array<Value[NumericalKeys<Value>]>;
|
|
22
|
+
/**
|
|
23
|
+
* Get an array from a value
|
|
24
|
+
*/
|
|
25
|
+
export declare function getArray<Item>(value: Item): Item[];
|
|
26
|
+
/**
|
|
27
|
+
* Get an array from a value
|
|
28
|
+
*/
|
|
29
|
+
export declare function getArray(value: unknown): unknown[];
|
|
30
|
+
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { PlainObject } from '../models';
|
|
2
|
+
type NumericalKeys<Value> = {
|
|
3
|
+
[Key in keyof Value]: Key extends number ? Key : Key extends `${number}` ? Key : never;
|
|
4
|
+
}[keyof Value];
|
|
5
|
+
/**
|
|
6
|
+
* Get an array from a value
|
|
7
|
+
*/
|
|
8
|
+
export declare function getArray<Item>(value: Item[]): Item[];
|
|
9
|
+
/**
|
|
10
|
+
* Get an array from an object
|
|
11
|
+
*/
|
|
12
|
+
export declare function getArray<Value extends PlainObject>(value: Value): Array<Value[keyof Value]>;
|
|
13
|
+
/**
|
|
14
|
+
* Get an array from an object, where only values with numeric keys will be included
|
|
15
|
+
*/
|
|
16
|
+
export declare function getArray<Value extends PlainObject>(value: Value, indiced: true): Array<Value[NumericalKeys<Value>]>;
|
|
17
|
+
/**
|
|
18
|
+
* Get an array from a value
|
|
19
|
+
*/
|
|
20
|
+
export declare function getArray<Item>(value: Item): Item[];
|
|
21
|
+
/**
|
|
22
|
+
* Get an array from a value
|
|
23
|
+
*/
|
|
24
|
+
export declare function getArray(value: unknown): unknown[];
|
|
25
|
+
export {};
|
package/types/array/index.d.cts
CHANGED
|
@@ -160,6 +160,29 @@ export declare function find<Item, ItemKey extends (item: Item, index: number, a
|
|
|
160
160
|
* Flatten an array _(using native `flat` and maximum depth)_
|
|
161
161
|
*/
|
|
162
162
|
export declare function flatten<Item>(array: Item[]): NestedArrayType<Item>[];
|
|
163
|
+
export type NumericalKeys<Value> = {
|
|
164
|
+
[Key in keyof Value]: Key extends number ? Key : Key extends `${number}` ? Key : never;
|
|
165
|
+
}[keyof Value];
|
|
166
|
+
/**
|
|
167
|
+
* Get an array from a value
|
|
168
|
+
*/
|
|
169
|
+
export declare function getArray<Item>(value: Item[]): Item[];
|
|
170
|
+
/**
|
|
171
|
+
* Get an array from an object
|
|
172
|
+
*/
|
|
173
|
+
export declare function getArray<Value extends PlainObject>(value: Value): Array<Value[keyof Value]>;
|
|
174
|
+
/**
|
|
175
|
+
* Get an array from an object, where only values with numeric keys will be included
|
|
176
|
+
*/
|
|
177
|
+
export declare function getArray<Value extends PlainObject>(value: Value, indiced: true): Array<Value[NumericalKeys<Value>]>;
|
|
178
|
+
/**
|
|
179
|
+
* Get an array from a value
|
|
180
|
+
*/
|
|
181
|
+
export declare function getArray<Item>(value: Item): Item[];
|
|
182
|
+
/**
|
|
183
|
+
* Get an array from a value
|
|
184
|
+
*/
|
|
185
|
+
export declare function getArray(value: unknown): unknown[];
|
|
163
186
|
/**
|
|
164
187
|
* Create a record from an array of items using a specific key
|
|
165
188
|
*/
|
package/types/array/index.d.ts
CHANGED
package/types/index.d.cts
CHANGED
|
@@ -2104,6 +2104,29 @@ export declare function find<Item, ItemKey extends (item: Item, index: number, a
|
|
|
2104
2104
|
* Flatten an array _(using native `flat` and maximum depth)_
|
|
2105
2105
|
*/
|
|
2106
2106
|
export declare function flatten<Item>(array: Item[]): NestedArrayType<Item>[];
|
|
2107
|
+
export type NumericalKeys<Value> = {
|
|
2108
|
+
[Key in keyof Value]: Key extends number ? Key : Key extends `${number}` ? Key : never;
|
|
2109
|
+
}[keyof Value];
|
|
2110
|
+
/**
|
|
2111
|
+
* Get an array from a value
|
|
2112
|
+
*/
|
|
2113
|
+
export declare function getArray<Item>(value: Item[]): Item[];
|
|
2114
|
+
/**
|
|
2115
|
+
* Get an array from an object
|
|
2116
|
+
*/
|
|
2117
|
+
export declare function getArray<Value extends PlainObject>(value: Value): Array<Value[keyof Value]>;
|
|
2118
|
+
/**
|
|
2119
|
+
* Get an array from an object, where only values with numeric keys will be included
|
|
2120
|
+
*/
|
|
2121
|
+
export declare function getArray<Value extends PlainObject>(value: Value, indiced: true): Array<Value[NumericalKeys<Value>]>;
|
|
2122
|
+
/**
|
|
2123
|
+
* Get an array from a value
|
|
2124
|
+
*/
|
|
2125
|
+
export declare function getArray<Item>(value: Item): Item[];
|
|
2126
|
+
/**
|
|
2127
|
+
* Get an array from a value
|
|
2128
|
+
*/
|
|
2129
|
+
export declare function getArray(value: unknown): unknown[];
|
|
2107
2130
|
/**
|
|
2108
2131
|
* Create a record from an array of items using a specific key
|
|
2109
2132
|
*/
|