ts-options-defaults
Advanced tools
Comparing version 0.0.43 to 0.0.71-0
{ | ||
"name": "ts-options-defaults", | ||
"version": "0.0.43", | ||
"description": "Options-defaults design pattern implementation for reliable configuration.", | ||
"version": "0.0.71-0", | ||
"description": "Options-defaults design pattern implementation for reliable configuration. It merges objects deeply, overrides arrays and classes (different than Object) and the result remains strongly typed.", | ||
"keywords": [ | ||
@@ -20,8 +20,8 @@ "defaults", | ||
"devDependencies": { | ||
"@radrat-node/execute": "0.0.43", | ||
"@radrat-scripts/package": "0.0.43", | ||
"@radrat/cli": "0.0.64", | ||
"@radrat-scripts/package": "0.0.70", | ||
"@radrat-scripts/readme": "0.0.71-0", | ||
"@radrat/cli": "0.0.71-0", | ||
"@types/node": "^14.6.0", | ||
"typescript": "^3.9.7" | ||
"typescript": "^4.0.2" | ||
} | ||
} |
@@ -1,13 +0,22 @@ | ||
# ts-options-defaults | ||
<p align="center"> | ||
<h1>ts-options-defaults</h1> | ||
<div>Options-defaults design pattern implementation for reliable configuration. It merges objects deeply, overrides arrays and classes (different than Object) and the result remains strongly typed.</div> | ||
</p> | ||
`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. | ||
## Table of contents | ||
> Options-defaults design pattern implementation for reliable configuration. | ||
1. [Getting Started](#getting-started) | ||
# Usage | ||
2. [Usage](#usage) | ||
3. [Features](#features) | ||
## Getting Started | ||
`npm i ts-options-defaults` | ||
# Design pattern | ||
## Usage | ||
### Design pattern | ||
```ts | ||
@@ -32,6 +41,6 @@ import { defaults } from 'ts-options-defaults'; | ||
# Behavior | ||
### Behavior | ||
```ts | ||
import { defaults } from '../src'; | ||
import { defaults } from 'ts-options-defaults'; | ||
@@ -97,1 +106,8 @@ class TestLogger { | ||
``` | ||
## Features | ||
**Beats alternatives** - better alternative to `{...defaults, ...options}` destructing and lodash `_.defaults` or `_.merge` | ||
**Secure** - immune to prototype pollution attack | ||
**Simple** - just 40 lines of clean TypeScript code | ||
**Strongly typed** - result remains strongly typed |
5387
112