@stacksjs/objects 0.70.23 → 0.70.25

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/README.md CHANGED
@@ -29,7 +29,7 @@ const collection = collect([{
29
29
  console.log(collection.avg('pages')) // 636
30
30
  ```
31
31
 
32
- To view the full documentation, please visit [https://stacksjs.org/objects](https://stacksjs.org/objects).
32
+ To view the full documentation, please visit [<https://stacksjs.com/object>s](https://stacksjs.com/objects).
33
33
 
34
34
  ## 🧪 Testing
35
35
 
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{notNullish as F}from"@stacksjs/utils";import{isObject as G}from"@stacksjs/validation";function L(q,x){return Object.fromEntries(Object.entries(q).map(([A,z])=>x(A,z)).filter(F))}function P(q,x){return x in q}function H(q){return Object.keys(q)}function Q(q){return Object.entries(q)}function E(q,...x){if(!x.length)return q;let A=x.shift();if(A===void 0)return q;if(C(q)&&C(A))H(A).forEach((z)=>{if(C(A[z])){if(!q[z])q[z]={};E(q[z],A[z])}else q[z]=A[z]});return E(q,...x)}function C(q){return G(q)&&!Array.isArray(q)}function R(q,x,A=!1){return x.reduce((z,B)=>{if(B in q){if(!A||q[B]!==void 0)z[B]=q[B]}return z},{})}function S(q){return Object.keys(q).forEach((x)=>q[x]===void 0&&delete q[x]),q}function T(q,x){return q==null?!1:Object.prototype.hasOwnProperty.call(q,x)}export{R as objectPick,L as objectMap,H as objectKeys,Q as objectEntries,P as isKeyOf,T as hasOwnProperty,E as deepMerge,S as clearUndefined};
2
+ import{notNullish as F}from"@stacksjs/utils";import{isObject as G}from"@stacksjs/validation";function L(q,x){return Object.fromEntries(Object.entries(q).map(([A,B])=>x(A,B)).filter(F))}function P(q,x){return x in q}function H(q){return Object.keys(q)}function Q(q){return Object.entries(q)}function E(q,...x){if(!x.length)return q;let[A,...B]=x;if(A===void 0)return q;if(C(q)&&C(A))H(A).forEach((z)=>{if(C(A[z])){if(!q[z])q[z]={};E(q[z],A[z])}else q[z]=A[z]});return E(q,...B)}function C(q){return G(q)&&!Array.isArray(q)}function R(q,x,A=!1){return x.reduce((B,z)=>{if(z in q){if(!A||q[z]!==void 0)B[z]=q[z]}return B},{})}function S(q){return Object.keys(q).forEach((x)=>q[x]===void 0&&delete q[x]),q}function T(q,x){return q==null?!1:Object.prototype.hasOwnProperty.call(q,x)}export{R as objectPick,L as objectMap,H as objectKeys,Q as objectEntries,P as isKeyOf,T as hasOwnProperty,E as deepMerge,S as clearUndefined};
@@ -0,0 +1,74 @@
1
+ import type { DeepMerge } from '@stacksjs/types';
2
+ /**
3
+ * Map key/value pairs for an object, and construct a new one
4
+ *
5
+ *
6
+ * @category Object
7
+ *
8
+ * Transform:
9
+ * @example
10
+ * ```
11
+ * objectMap({ a: 1, b: 2 }, (k, v) => [k.toString().toUpperCase(), v.toString()])
12
+ * // { A: '1', B: '2' }
13
+ * ```
14
+ *
15
+ * Swap key/value:
16
+ * @example
17
+ * ```
18
+ * objectMap({ a: 1, b: 2 }, (k, v) => [v, k])
19
+ * // { 1: 'a', 2: 'b' }
20
+ * ```
21
+ *
22
+ * Filter keys:
23
+ * @example
24
+ * ```
25
+ * objectMap({ a: 1, b: 2 }, (k, v) => k === 'a' ? undefined : [k, v])
26
+ * // { b: 2 }
27
+ * ```
28
+ */
29
+ export declare function objectMap<K extends string, V, NK = K, NV = V>(obj: Record<K, V>, fn: (key: K, value: V) => [NK, NV] | undefined): Record<K, V>;
30
+ /**
31
+ * Type guard for any key, `k`.
32
+ * Marks `k` as a key of `T` if `k` is in `obj`.
33
+ *
34
+ * @category Object
35
+ * @param obj object to query for key `k`
36
+ * @param k key to check existence in `obj`
37
+ */
38
+ export declare function isKeyOf<T extends object>(obj: T, k: keyof any): k is keyof T;
39
+ /**
40
+ * Strict typed `Object.keys`
41
+ *
42
+ * @category Object
43
+ */
44
+ export declare function objectKeys<T extends object>(obj: T): void;
45
+ /**
46
+ * Strict typed `Object.entries`
47
+ *
48
+ * @category Object
49
+ */
50
+ export declare function objectEntries<T extends object>(obj: T): void;
51
+ /**
52
+ * Deep merge :P
53
+ *
54
+ * @category Object
55
+ */
56
+ export declare function deepMerge<T extends object = object, S extends object = T>(target: T, ...sources: S[]): DeepMerge<T, S>;
57
+ /**
58
+ * Create a new subset object by providing keys.
59
+ *
60
+ * @category Object
61
+ */
62
+ export declare function objectPick<O extends object, T extends keyof O>(obj: O, keys: T[], omitUndefined?: boolean): Pick<O, T>;
63
+ /**
64
+ * Clear undefined fields from an object. It mutates the object.
65
+ *
66
+ * @category Object
67
+ */
68
+ export declare function clearUndefined<T extends object>(obj: T): T;
69
+ /**
70
+ * Determines whether an object has a property with the specified name
71
+ *
72
+ * @category Object
73
+ */
74
+ export declare function hasOwnProperty<T>(obj: T, v: PropertyKey): boolean;
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@stacksjs/objects",
3
3
  "type": "module",
4
- "version": "0.70.23",
4
+ "version": "0.70.25",
5
5
  "description": "The Stacks objects.",
6
6
  "author": "Chris Breuer",
7
- "contributors": ["Chris Breuer <chris@stacksjs.org>"],
7
+ "contributors": [
8
+ "Chris Breuer <chris@stacksjs.com>"
9
+ ],
8
10
  "license": "MIT",
9
11
  "funding": "https://github.com/sponsors/chrisbbreuer",
10
12
  "homepage": "https://github.com/stacksjs/stacks/tree/main/storage/framework/core/objects#readme",
@@ -16,28 +18,40 @@
16
18
  "bugs": {
17
19
  "url": "https://github.com/stacksjs/stacks/issues"
18
20
  },
19
- "keywords": ["objects", "utilities", "functions", "stacks"],
21
+ "keywords": [
22
+ "objects",
23
+ "utilities",
24
+ "functions",
25
+ "stacks"
26
+ ],
20
27
  "exports": {
21
28
  ".": {
29
+ "bun": "./src/index.ts",
30
+ "types": "./dist/index.d.ts",
22
31
  "import": "./dist/index.js"
23
32
  },
24
33
  "./*": {
34
+ "bun": "./src/*",
25
35
  "import": "./dist/*"
26
36
  }
27
37
  },
28
38
  "module": "dist/index.js",
29
39
  "types": "dist/index.d.ts",
30
- "files": ["README.md", "dist"],
40
+ "files": [
41
+ "README.md",
42
+ "dist"
43
+ ],
31
44
  "scripts": {
32
45
  "build": "bun build.ts",
33
46
  "typecheck": "bun tsc --noEmit",
34
47
  "prepublishOnly": "bun run build"
35
48
  },
36
49
  "devDependencies": {
37
- "@stacksjs/collections": "0.70.22",
38
- "@stacksjs/development": "0.70.22",
39
- "@stacksjs/types": "0.70.22",
40
- "@stacksjs/utils": "0.70.22",
41
- "@stacksjs/validation": "0.70.22"
42
- }
50
+ "@stacksjs/collections": "0.70.23",
51
+ "better-dx": "^0.2.12",
52
+ "@stacksjs/types": "0.70.23",
53
+ "@stacksjs/utils": "0.70.23",
54
+ "@stacksjs/validation": "0.70.23"
55
+ },
56
+ "sideEffects": false
43
57
  }
package/dist/index.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import type { DeepMerge } from '@stacksjs/types';
2
-
3
- export declare function objectMap<K extends string, V, NK = K, NV = V>(obj: Record<K, V>, fn: (key: K, value: V)): Record<K, V>;
4
- export declare function isKeyOf<T extends object>(obj: T, k: keyof any): k is keyof T;
5
- export declare function objectKeys<T extends object>(obj: T): void;
6
- export declare function objectEntries<T extends object>(obj: T): void;
7
- export declare function deepMerge<T extends object = object, S extends object = T>(target: T, ...sources: S[]): DeepMerge<T, S>;
8
- declare function isMergeableObject(item: any): item is object;
9
- export declare function objectPick<O extends object, T extends keyof O>(obj: O, keys: T[], omitUndefined): Pick<O, T>;
10
- export declare function clearUndefined<T extends object>(obj: T): T;
11
- export declare function hasOwnProperty<T>(obj: T, v: PropertyKey): boolean;