Comparing version 0.1.1 to 0.2.0
@@ -1,1 +0,2 @@ | ||
export declare function unpartial<T extends object, U, R extends object>(obj: U, src1: T, src2?: R): T & R; | ||
export declare function unpartial<T extends object>(base: T, partial: Partial<T>): T; | ||
export declare function unpartial<T extends object, R extends object = {}>(superBase: R, base: T, partial: Partial<T>): T & R; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const defaults = require("lodash.defaults"); | ||
function unpartial(obj, src1, src2) { | ||
if (src1 === undefined || src1 === null) | ||
return obj; | ||
return defaults(obj, src1, src2); | ||
function unpartial(arg1, arg2, arg3) { | ||
if (arguments.length === 3) { | ||
const superBase = arg1; | ||
const base = arg2; | ||
const partial = arg3; | ||
if (superBase === undefined || superBase === null) | ||
return superBase; | ||
if (base === undefined || base === null) | ||
return base; | ||
return defaults({}, partial, base, superBase); | ||
} | ||
else { | ||
const base = arg1; | ||
const partial = arg2; | ||
if (base === undefined || base === null) | ||
return base; | ||
return defaults({}, partial, base); | ||
} | ||
} | ||
exports.unpartial = unpartial; | ||
//# sourceMappingURL=index.js.map |
@@ -1,1 +0,2 @@ | ||
export declare function unpartial<T extends object, U, R extends object>(obj: U, src1: T, src2?: R): T & R; | ||
export declare function unpartial<T extends object>(base: T, partial: Partial<T>): T; | ||
export declare function unpartial<T extends object, R extends object = {}>(superBase: R, base: T, partial: Partial<T>): T & R; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var defaults = require("lodash.defaults"); | ||
function unpartial(obj, src1, src2) { | ||
if (src1 === undefined || src1 === null) | ||
return obj; | ||
return defaults(obj, src1, src2); | ||
function unpartial(arg1, arg2, arg3) { | ||
if (arguments.length === 3) { | ||
var superBase = arg1; | ||
var base = arg2; | ||
var partial = arg3; | ||
if (superBase === undefined || superBase === null) | ||
return superBase; | ||
if (base === undefined || base === null) | ||
return base; | ||
return defaults({}, partial, base, superBase); | ||
} | ||
else { | ||
var base = arg1; | ||
var partial = arg2; | ||
if (base === undefined || base === null) | ||
return base; | ||
return defaults({}, partial, base); | ||
} | ||
} | ||
exports.unpartial = unpartial; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "unpartial", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Unpartial a partialed object", | ||
@@ -72,2 +72,3 @@ "main": "dist-es5/index.js", | ||
"devDependencies": { | ||
"@types/lodash.defaults": "^4.2.3", | ||
"ava": "^0.22.0", | ||
@@ -74,0 +75,0 @@ "dependency-check": "^2.9.1", |
@@ -10,5 +10,5 @@ # Unpartial | ||
Unpartial a config | ||
Unpartial an interface | ||
It is very common to define a Config interface and Partial it in a function argument. | ||
It is very common to define a config interface and `Partial<>` it in a function argument. | ||
When we received the arguement, we want to merge it with our default config before using it: | ||
@@ -26,3 +26,3 @@ | ||
function foo(givenConfig: Partial<Config>) { | ||
const config = unpartial(givenConfig, defaultConfig); | ||
const config = unpartial(defaultConfig, givenConfig); | ||
// use config with type safety | ||
@@ -32,6 +32,12 @@ } | ||
It also support merging two default configs. | ||
This is useful when you are extending config from some other package/class. | ||
Code complete is avaiable as you type: | ||
```ts | ||
const config = unpartial(defaultConfig, { /* code completion here */}); | ||
``` | ||
It also supports merging two default configs. | ||
This is useful when you are extending interface from another package/class. | ||
```ts | ||
import { unpartial } from 'unpartial' | ||
@@ -46,3 +52,3 @@ | ||
function foo(givenOption: Partial<MyOption>) { | ||
const option = unpartial(givenOption, myDefaultOption, defaultOption) | ||
const option = unpartial(defaultOption, myDefaultOption, givenOption) | ||
} | ||
@@ -49,0 +55,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
10601
50
74
8