@poppinss/utils
Advanced tools
Comparing version 6.0.0-2 to 6.0.0-3
@@ -1,10 +0,18 @@ | ||
export declare class ObjectBuilder { | ||
import { OmitProperties } from './types.js'; | ||
export declare class ObjectBuilder<ReturnType extends Record<string, any>, IgnoreNull extends boolean = false> { | ||
#private; | ||
value: Record<any, any>; | ||
constructor(initialValue?: Record<any, any>, ignoreNull?: boolean); | ||
add(key: string, value: any): this; | ||
remove(key: string): this; | ||
has(key: string): boolean; | ||
get<T extends any>(key: string): T; | ||
toObject(): Record<any, any>; | ||
values: ReturnType; | ||
constructor(initialValue: ReturnType, ignoreNull?: IgnoreNull); | ||
add<Prop extends string>(key: Prop, value: undefined): this; | ||
add<Prop extends string, Value>(key: Prop, value: Value): ObjectBuilder<ReturnType & { | ||
[P in Prop]: Value; | ||
}, IgnoreNull>; | ||
remove<K extends keyof ReturnType>(key: K): this; | ||
has<K extends keyof ReturnType>(key: K): boolean; | ||
get<K extends keyof ReturnType>(key: K): ReturnType[K]; | ||
toObject(): IgnoreNull extends true ? { | ||
[K in keyof OmitProperties<ReturnType, null>]: ReturnType[K]; | ||
} : { | ||
[K in keyof ReturnType]: ReturnType[K]; | ||
}; | ||
} |
export class ObjectBuilder { | ||
#ignoreNull; | ||
value = {}; | ||
values; | ||
constructor(initialValue, ignoreNull) { | ||
this.value = initialValue !== undefined ? initialValue : {}; | ||
this.values = initialValue; | ||
this.#ignoreNull = ignoreNull === true ? true : false; | ||
@@ -15,7 +15,8 @@ } | ||
} | ||
this.value[key] = value; | ||
; | ||
this.values[key] = value; | ||
return this; | ||
} | ||
remove(key) { | ||
delete this.value[key]; | ||
delete this.values[key]; | ||
return this; | ||
@@ -27,7 +28,7 @@ } | ||
get(key) { | ||
return this.value[key]; | ||
return this.values[key]; | ||
} | ||
toObject() { | ||
return this.value; | ||
return this.values; | ||
} | ||
} |
@@ -0,1 +1,5 @@ | ||
declare type PickKeysByValue<T, V> = { | ||
[K in keyof T]: T[K] extends V ? K : never; | ||
}[keyof T]; | ||
export declare type OmitProperties<T, P> = Omit<T, PickKeysByValue<T, P>>; | ||
declare type ScanFsBaseOptions = { | ||
@@ -2,0 +6,0 @@ ignoreMissingRoot?: boolean; |
{ | ||
"name": "@poppinss/utils", | ||
"version": "6.0.0-2", | ||
"version": "6.0.0-3", | ||
"description": "Handy utilities for repetitive work", | ||
@@ -63,5 +63,5 @@ "main": "build/index.js", | ||
"@japa/spec-reporter": "^1.3.2", | ||
"@swc/core": "^1.3.10", | ||
"@swc/core": "^1.3.11", | ||
"@types/fs-extra": "^9.0.13", | ||
"@types/node": "^18.11.3", | ||
"@types/node": "^18.11.7", | ||
"c8": "^7.12.0", | ||
@@ -68,0 +68,0 @@ "del-cli": "^5.0.0", |
@@ -1038,3 +1038,3 @@ # @poppinss/utils | ||
Instead of writing conditionals, your can consider using the Object builder fluent API. | ||
Instead of writing conditionals, you can consider using the Object builder fluent API. | ||
@@ -1044,7 +1044,5 @@ ```ts | ||
// Add property if the value is not undefined. | ||
builder.add('b', b) | ||
// Get the plain object back | ||
const plainObject = builder.toObject() | ||
const plainObject = builder | ||
.add('b', b) | ||
.toObject() | ||
``` | ||
@@ -1051,0 +1049,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92956
952
1087