@poppinss/utils 6.0.0-2 → 6.0.1-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.
package/README.md CHANGED
@@ -1035,16 +1035,14 @@ if (b) {
1035
1035
  }
1036
1036
  ```
1037
1037
 
1038
- Instead of writing conditionals, your can consider using the Object builder fluent API.
1038
+ Instead of writing conditionals, you can consider using the Object builder fluent API.
1039
1039
 
1040
1040
  ```ts
1041
1041
  const builder = new ObjectBuilder({ a: 1 })
1042
1042
 
1043
- // Add property if the value is not undefined.
1044
- builder.add('b', b)
1045
-
1046
- // Get the plain object back
1047
- const plainObject = builder.toObject()
1043
+ const plainObject = builder
1044
+ .add('b', b)
1045
+ .toObject()
1048
1046
  ```
1049
1047
 
1050
1048
  By default, only the `undefined` values are ignored. However, you can also ignore `null` values.
@@ -1,8 +1,5 @@
1
- declare type Constructor = new (...args: any[]) => any;
2
- export declare type NormalizeConstructor<T extends Constructor> = {
3
- new (...args: any[]): InstanceType<T>;
4
- } & Omit<T, 'constructor'>;
5
- export interface UnaryFunction<T, R> {
1
+ import type { Constructor } from './types.js';
2
+ interface UnaryFunction<T, R> {
6
3
  (source: T): R;
7
4
  }
8
5
  export declare function compose<T extends Constructor, A>(superclass: T, mixin: UnaryFunction<T, A>): A;
@@ -1,10 +1,18 @@
1
- export declare class ObjectBuilder {
1
+ import { OmitProperties } from './types.js';
2
+ export declare class ObjectBuilder<ReturnType extends Record<string, any>, IgnoreNull extends boolean = false> {
2
3
  #private;
3
- value: Record<any, any>;
4
- constructor(initialValue?: Record<any, any>, ignoreNull?: boolean);
5
- add(key: string, value: any): this;
6
- remove(key: string): this;
7
- has(key: string): boolean;
8
- get<T extends any>(key: string): T;
9
- toObject(): Record<any, any>;
4
+ values: ReturnType;
5
+ constructor(initialValue: ReturnType, ignoreNull?: IgnoreNull);
6
+ add<Prop extends string>(key: Prop, value: undefined): this;
7
+ add<Prop extends string, Value>(key: Prop, value: Value): ObjectBuilder<ReturnType & {
8
+ [P in Prop]: Value;
9
+ }, IgnoreNull>;
10
+ remove<K extends keyof ReturnType>(key: K): this;
11
+ has<K extends keyof ReturnType>(key: K): boolean;
12
+ get<K extends keyof ReturnType>(key: K): ReturnType[K];
13
+ toObject(): IgnoreNull extends true ? {
14
+ [K in keyof OmitProperties<ReturnType, null>]: ReturnType[K];
15
+ } : {
16
+ [K in keyof ReturnType]: ReturnType[K];
17
+ };
10
18
  }
@@ -1,8 +1,8 @@
1
1
  export class ObjectBuilder {
2
2
  #ignoreNull;
3
- value = {};
3
+ values;
4
4
  constructor(initialValue, ignoreNull) {
5
- this.value = initialValue !== undefined ? initialValue : {};
5
+ this.values = initialValue;
6
6
  this.#ignoreNull = ignoreNull === true ? true : false;
7
7
  }
8
8
  add(key, value) {
@@ -12,20 +12,21 @@ export class ObjectBuilder {
12
12
  if (this.#ignoreNull === true && value === null) {
13
13
  return this;
14
14
  }
15
- this.value[key] = value;
15
+ ;
16
+ this.values[key] = value;
16
17
  return this;
17
18
  }
18
19
  remove(key) {
19
- delete this.value[key];
20
+ delete this.values[key];
20
21
  return this;
21
22
  }
22
23
  has(key) {
23
24
  return this.get(key) !== undefined;
24
25
  }
25
26
  get(key) {
26
- return this.value[key];
27
+ return this.values[key];
27
28
  }
28
29
  toObject() {
29
- return this.value;
30
+ return this.values;
30
31
  }
31
32
  }
@@ -1,3 +1,7 @@
1
+ declare type PickKeysByValue<T, V> = {
2
+ [K in keyof T]: T[K] extends V ? K : never;
3
+ }[keyof T];
4
+ export declare type OmitProperties<T, P> = Omit<T, PickKeysByValue<T, P>>;
1
5
  declare type ScanFsBaseOptions = {
2
6
  ignoreMissingRoot?: boolean;
3
7
  filter?: (filePath: string, index: number) => boolean;
@@ -11,4 +15,8 @@ export declare type ReadAllFilesOptions = ScanFsBaseOptions & {
11
15
  };
12
16
  export declare type JSONReplacer = (this: any, key: string, value: any) => any;
13
17
  export declare type JSONReviver = (this: any, key: string, value: any) => any;
18
+ export declare type Constructor = new (...args: any[]) => any;
19
+ export declare type NormalizeConstructor<T extends Constructor> = {
20
+ new (...args: any[]): InstanceType<T>;
21
+ } & Omit<T, 'constructor'>;
14
22
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poppinss/utils",
3
- "version": "6.0.0-2",
3
+ "version": "6.0.1-0",
4
4
  "description": "Handy utilities for repetitive work",
5
5
  "main": "build/index.js",
6
6
  "type": "module",
@@ -60,9 +60,9 @@
60
60
  "@japa/run-failed-tests": "^1.1.0",
61
61
  "@japa/runner": "^2.2.2",
62
62
  "@japa/spec-reporter": "^1.3.2",
63
- "@swc/core": "^1.3.10",
63
+ "@swc/core": "^1.3.11",
64
64
  "@types/fs-extra": "^9.0.13",
65
- "@types/node": "^18.11.3",
65
+ "@types/node": "^18.11.7",
66
66
  "c8": "^7.12.0",
67
67
  "del-cli": "^5.0.0",
68
68
  "eslint": "^8.26.0",