@bccampus/ui-components 0.9.10 → 0.9.11

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.
@@ -1,10 +1,13 @@
1
- const get = (object, prop) => prop.split(".").reduce((reducedObject, key) => reducedObject && key in reducedObject ? reducedObject[key] : void 0, object);
1
+ const get = (object, prop) => prop.split(".").reduce(
2
+ (reducedObject, key) => reducedObject && key in reducedObject ? reducedObject[key] : void 0,
3
+ object
4
+ );
2
5
  const set = (object, prop, value) => {
3
6
  const propChunks = prop.split(".");
4
7
  const lastChunk = propChunks.pop();
5
8
  if (!lastChunk) return object;
6
9
  const ref = propChunks.reduce((reducedObject, key) => {
7
- reducedObject[key] = {};
10
+ if (reducedObject[key] === void 0) reducedObject[key] = {};
8
11
  return reducedObject[key];
9
12
  }, object);
10
13
  ref[lastChunk] = value;
@@ -22,7 +25,10 @@ const omit = (object, props) => {
22
25
  const propChunks = prop.split(".");
23
26
  const lastChunk = propChunks.pop();
24
27
  if (lastChunk) {
25
- const ref = propChunks.reduce((reducedObject, key) => reducedObject && key in reducedObject ? reducedObject[key] : void 0, result);
28
+ const ref = propChunks.reduce(
29
+ (reducedObject, key) => reducedObject && key in reducedObject ? reducedObject[key] : void 0,
30
+ result
31
+ );
26
32
  if (ref && lastChunk in ref) delete ref[lastChunk];
27
33
  }
28
34
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bccampus/ui-components",
3
- "version": "0.9.10",
3
+ "version": "0.9.11",
4
4
  "description": "BCcampus React components",
5
5
  "type": "module",
6
6
  "exports": {
package/src/lib/object.ts CHANGED
@@ -1,48 +1,52 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
 
3
- export const get = <T extends object>(object: T, prop: string) => prop
4
- .split('.')
5
- .reduce<any>((reducedObject, key) => (reducedObject && key in reducedObject) ? reducedObject[key] : undefined, object);
3
+ export const get = <T extends object>(object: T, prop: string) =>
4
+ prop
5
+ .split(".")
6
+ .reduce<any>(
7
+ (reducedObject, key) => (reducedObject && key in reducedObject ? reducedObject[key] : undefined),
8
+ object,
9
+ );
6
10
 
7
11
  export const set = <T extends object, V>(object: T, prop: string, value: V) => {
8
- const propChunks = prop.split('.');
9
- const lastChunk = propChunks.pop();
10
- if (!lastChunk) return object;
12
+ const propChunks = prop.split(".");
13
+ const lastChunk = propChunks.pop();
14
+ if (!lastChunk) return object;
11
15
 
12
- const ref = propChunks.reduce<any>((reducedObject, key) => {
13
- reducedObject[key] = {};
14
- return reducedObject[key];
15
- }, object);
16
+ const ref = propChunks.reduce<any>((reducedObject, key) => {
17
+ if (reducedObject[key] === undefined) reducedObject[key] = {};
18
+ return reducedObject[key];
19
+ }, object);
16
20
 
17
- ref[lastChunk] = value;
21
+ ref[lastChunk] = value;
18
22
 
19
- return object;
20
- }
23
+ return object;
24
+ };
21
25
 
22
26
  export const pick = <T extends object>(object: T, props: string[]) => {
23
-
24
- return props.reduce<Record<string, unknown>>((result, key) => {
25
-
26
- set(result, key, get(object, key));
27
-
28
- return result;
29
- }, {}) as Partial<T>;
30
- }
31
-
32
- export const omit = <T extends object>(object: T, props: string[]) => {
33
- const result: Partial<T> = { ...object };
34
-
35
- props.forEach(prop => {
36
- const propChunks = prop.split('.');
37
- const lastChunk = propChunks.pop();
38
- if (lastChunk) {
39
- const ref = propChunks.reduce<any>((reducedObject, key) => (reducedObject && key in reducedObject) ? reducedObject[key] : undefined, result);
40
- if (ref && lastChunk in ref) delete ref[lastChunk];
41
- }
42
- })
27
+ return props.reduce<Record<string, unknown>>((result, key) => {
28
+ set(result, key, get(object, key));
43
29
 
44
30
  return result;
45
- }
31
+ }, {}) as Partial<T>;
32
+ };
46
33
 
47
- export const isObject = (object: unknown) => (typeof object === 'object' && !Array.isArray(object) && object !== null);
34
+ export const omit = <T extends object>(object: T, props: string[]) => {
35
+ const result: Partial<T> = { ...object };
48
36
 
37
+ props.forEach((prop) => {
38
+ const propChunks = prop.split(".");
39
+ const lastChunk = propChunks.pop();
40
+ if (lastChunk) {
41
+ const ref = propChunks.reduce<any>(
42
+ (reducedObject, key) => (reducedObject && key in reducedObject ? reducedObject[key] : undefined),
43
+ result,
44
+ );
45
+ if (ref && lastChunk in ref) delete ref[lastChunk];
46
+ }
47
+ });
48
+
49
+ return result;
50
+ };
51
+
52
+ export const isObject = (object: unknown) => typeof object === "object" && !Array.isArray(object) && object !== null;