utilium 2.5.9 → 2.6.1

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/objects.d.ts CHANGED
@@ -19,7 +19,7 @@ export declare function isObject(value: unknown): value is object;
19
19
  export type DeepAssign<To extends object, From extends object> = {
20
20
  [K in keyof To | keyof From]: K extends keyof To ? K extends keyof From ? To[K] extends object ? From[K] extends object ? Expand<DeepAssign<To[K], From[K]>> : never : From[K] extends object ? never : From[K] : To[K] : From[K & keyof From];
21
21
  };
22
- export declare function deepAssign<To extends object, From extends object>(to: To, from: From): DeepAssign<To, From>;
22
+ export declare function deepAssign<To extends object, From extends object>(to: To, from: From, treatArraysAsPrimitives?: boolean): DeepAssign<To, From>;
23
23
  /**
24
24
  * Entries of T
25
25
  */
@@ -69,6 +69,18 @@ export declare function bindFunctions<T extends object, This = any>(fns: T, this
69
69
  export type Mutable<T> = {
70
70
  -readonly [P in keyof T]: T[P];
71
71
  };
72
+ /**
73
+ * Makes all properties in T readonly recursively
74
+ */
75
+ export type ReadonlyRecursive<T> = T extends object ? {
76
+ readonly [K in keyof T]: ReadonlyRecursive<T[K]>;
77
+ } : T;
78
+ /**
79
+ * Makes all properties in T mutable recursively
80
+ */
81
+ export type MutableRecursive<T> = T extends object ? {
82
+ -readonly [P in keyof T]: MutableRecursive<T[P]>;
83
+ } : T;
72
84
  /**
73
85
  * Makes properties with keys assignable to K in T required
74
86
  * @see https://stackoverflow.com/a/69328045/17637456
@@ -136,3 +148,4 @@ export type Never<T> = {
136
148
  * All of the properties in T or none of them
137
149
  */
138
150
  export type AllOrNone<T> = T | Never<T>;
151
+ export type Filter<Key, Arr extends readonly any[]> = Arr extends readonly [infer L, ...infer R] ? L extends Key ? Filter<Key, R> : [L, ...Filter<Key, R>] : [];
package/dist/objects.js CHANGED
@@ -35,7 +35,7 @@ export function assignWithDefaults(to, from, defaults = to) {
35
35
  export function isObject(value) {
36
36
  return Object(value) === value;
37
37
  }
38
- export function deepAssign(to, from) {
38
+ export function deepAssign(to, from, treatArraysAsPrimitives = false) {
39
39
  const keys = new Set([
40
40
  ...Object.keys(to),
41
41
  ...Object.keys(from),
@@ -48,7 +48,8 @@ export function deepAssign(to, from) {
48
48
  to[key] = value;
49
49
  continue;
50
50
  }
51
- if (!isObject(to[key]) && Object(value) !== value) {
51
+ if ((!isObject(to[key]) && Object(value) !== value)
52
+ || (treatArraysAsPrimitives && Array.isArray(value) && !Array.isArray(to[key]))) {
52
53
  to[key] = value;
53
54
  continue;
54
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utilium",
3
- "version": "2.5.9",
3
+ "version": "2.6.1",
4
4
  "description": "Typescript utilities",
5
5
  "funding": {
6
6
  "type": "individual",