ts-options-defaults
Advanced tools
Comparing version 0.0.3-7 to 0.0.10
{ | ||
"name": "ts-options-defaults", | ||
"version": "0.0.3-7", | ||
"version": "0.0.10", | ||
"license": "GPL-3.0", | ||
@@ -17,7 +17,6 @@ "files": [ | ||
"chalk": "^4.1.0", | ||
"find-up": "^4.1.0", | ||
"ts-essentials": "^7.0.0", | ||
"ts-import": "0.0.9-8", | ||
"ts-import": "0.0.10", | ||
"typescript": "^3.9.5" | ||
} | ||
} |
# ts-options-defaults | ||
`Object.assign({}, defaults, options)` and equivalent with destructing `{...defaults, ...options}` come with a pitfall of creating only a _shallow copy_. Lodash `_.merge` works on deep properties, but it merges arrays and that usually makes no sense in the context of default options (also it mutates first element; this package doesn't). This package fixes that problem - **it merges objects deeply, overrides arrays and merges class functions** plus the result remains strongly typed. | ||
`Object.assign({}, defaults, options)` and equivalent with destructing `{...defaults, ...options}` come with a pitfall of creating only a _shallow copy_. Lodash `_.merge` works on deep properties, but it merges arrays and that usually makes no sense in the context of default options (also it mutates first element; this package doesn't). **ts-options-defaults** fixes that problem - **it merges objects deeply, overrides arrays and classes** (different than Object) plus the result remains strongly typed. | ||
@@ -21,7 +21,8 @@ > Options-defaults design pattern implementation for reliable configuration. | ||
export class Something { | ||
static defaults: Required<ISomeOptions> = { | ||
static defaults = { | ||
logger: console, | ||
}; | ||
constructor(public options: IRatOptions) { | ||
options: ISomeOptions & typeof Something.defaults; | ||
constructor(options?: ISomeOptions) { | ||
this.options = defaults(Rat.defaults, options); | ||
@@ -28,0 +29,0 @@ } |
4853
6
96