@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.
@@ -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 };
@@ -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;
@@ -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 noop() {
6
- }
7
- function step(now) {
8
- if (values.length === 7) {
9
- exports.milliseconds = Math.floor(
10
- values.slice(2).reduce((first, second) => first + second) / 5 * 2
11
- ) / 2;
12
- last = void 0;
13
- values.length = 0;
14
- } else {
15
- last ??= now;
16
- const difference = now - last;
17
- if (difference > 0) {
18
- values.push(difference);
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
- const values = [];
25
- let last;
26
- exports.milliseconds = Math.floor(1e3 / 60 * 2) / 2;
27
- requestAnimationFrame(step);
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 noop() {
2
- }
3
- function step(now) {
4
- if (values.length === 7) {
5
- milliseconds = Math.floor(
6
- values.slice(2).reduce((first, second) => first + second) / 5 * 2
7
- ) / 2;
8
- last = void 0;
9
- values.length = 0;
10
- } else {
11
- last ??= now;
12
- const difference = now - last;
13
- if (difference > 0) {
14
- values.push(difference);
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
- const values = [];
21
- let last;
22
- let milliseconds = Math.floor(1e3 / 60 * 2) / 2;
23
- requestAnimationFrame(step);
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": "^22.15",
15
- "@vitest/coverage-istanbul": "^3.1",
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.1"
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.100.0"
205
+ "version": "0.102.0"
206
206
  }
@@ -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
+ }
@@ -6,6 +6,7 @@ export * from './exists';
6
6
  export * from './filter';
7
7
  export * from './find';
8
8
  export * from './flatten';
9
+ export * from './get';
9
10
  export * from './group-by';
10
11
  export * from './index-of';
11
12
  export * from './insert';
@@ -1,40 +1,44 @@
1
- /**
2
- * A function that does nothing, which can be useful, I guess…
3
- */
4
- export function noop(): void {}
5
-
6
- function step(now: DOMHighResTimeStamp): void {
7
- if (values.length === 7) {
8
- milliseconds =
9
- Math.floor(
10
- (values.slice(2).reduce((first, second) => first + second) / 5) * 2,
11
- ) / 2;
12
-
13
- last = undefined;
14
- values.length = 0;
15
- } else {
16
- last ??= now;
17
-
18
- const difference = now - last;
19
-
20
- if (difference > 0) {
21
- values.push(difference);
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
- const values: number[] = [];
33
- let last: DOMHighResTimeStamp | undefined;
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 = Math.floor((1000 / 60) * 2) / 2;
40
+ export let milliseconds = 1000 / 60;
39
41
 
40
- requestAnimationFrame(step);
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 {};
@@ -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
  */
@@ -6,6 +6,7 @@ export * from './exists';
6
6
  export * from './filter';
7
7
  export * from './find';
8
8
  export * from './flatten';
9
+ export * from './get';
9
10
  export * from './group-by';
10
11
  export * from './index-of';
11
12
  export * from './insert';
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
  */