@stacksjs/objects 0.70.88 → 0.70.91

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,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/dist/index.js ADDED
@@ -0,0 +1,2 @@
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,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};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/objects",
3
3
  "type": "module",
4
- "version": "0.70.88",
4
+ "version": "0.70.91",
5
5
  "description": "The Stacks objects.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [
@@ -51,11 +51,11 @@
51
51
  "prepublishOnly": "bun run build"
52
52
  },
53
53
  "devDependencies": {
54
- "@stacksjs/collections": "0.70.88",
54
+ "@stacksjs/collections": "0.70.91",
55
55
  "better-dx": "^0.2.16",
56
- "@stacksjs/types": "0.70.88",
57
- "@stacksjs/utils": "0.70.88",
58
- "@stacksjs/validation": "0.70.88"
56
+ "@stacksjs/types": "0.70.91",
57
+ "@stacksjs/utils": "0.70.91",
58
+ "@stacksjs/validation": "0.70.91"
59
59
  },
60
60
  "sideEffects": false
61
61
  }