🤖 Merge PR #46124 Update @types/dot-object to v2.1.3 by @ricosandyca

* Update dot-object-tests.ts

* Update index.d.ts

* Update dot-object-tests.ts

* Update index.d.ts

* Add files via upload
This commit is contained in:
Rico Sandyca Novenza 2020-07-28 02:57:38 +07:00 committed by GitHub
parent 76d0ee77ba
commit 1a3510f39a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 5 deletions

View File

@ -67,9 +67,15 @@ val = dot.pick('some.nested.value', newObj, true);
// shorthand
val = dot.remove('some.nested.value', newObj);
val = dot.remove(['some.nested.value'], newObj)
// or use the alias `del`
val = dot.del('some.nested.value', newObj);
val = dot.del(['some.nested.value'], newObj);
// delete and get value of the deleted attribute
val = dot.delete('some.nested.value', newObj)
val = dot.delete(['some.nested.value'], newObj)
// convert object to dot object
var result = {};
@ -77,3 +83,21 @@ dot.dot({ test: 'something' }, result);
result = dot.dot({ test: 'something' });
var dotWithArrow = new dot('=>');
var dotWithAnotherSeparator = new dot('->', true, false)
var objWithArray = {
author: 'John Doe',
books: ['A', 'B', 'C'],
about: {
hometown: 'Sampang, Jawa Timur',
skils: ['HTML', 'CSS', 'JS', 'TS']
}
}
var defaultResult = dot.dot(objWithArray)
// set keepArray property
dot.keepArray = true
var keepArrayResult = dot.dot(objWithArray)
console.log('Default:', defaultResult)
console.log('KeepArray:', keepArrayResult)

View File

@ -1,13 +1,19 @@
// Type definitions for Dot-Object 2.1
// Project: https://github.com/rhalff/dot-object
// Definitions by: Niko Kovačič <https://github.com/nkovacic>
// Rico Sandyca <https://github.com/ricosandyca>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
declare namespace DotObject {
interface DotConstructor extends Dot {
new (separator: string): Dot;
new (
separator: string,
override?: boolean,
useArray?: boolean,
useBrackets?: boolean
): Dot;
}
interface ModifierFunctionWrapper {
@ -58,11 +64,43 @@ declare namespace DotObject {
*
* Remove value from an object using dot notation.
*
* @param {String} path
* @param {String | Array<String>} path
* @param {Object} obj
* @return {Mixed} The removed value
*/
del(path: string, obj: any): any;
del(path: string | string[], obj: any): any;
/**
*
* Delete value from an object using dot notation.
*
* @param {String | Array<String>} path
* @param {Object} obj
* @return {any} The removed value
*/
delete(path: string | string[], obj: any): any;
/**
*
* Keep array
*
* example:
*
* var obj = {
* "id": "my-id",
* "other": [1, 2, 3]
* "some": {
* "array": ["A", "B"]
* }
* }
*
* if the keepArray property is true:
*
* {
* "id": "my-id",
* "other": [1, 2, 3],
* "some.array": ["A", "B"]
* }
*/
keepArray: boolean;
/**
*
* Move a property from one place to the other.
@ -115,11 +153,11 @@ declare namespace DotObject {
*
* Remove value from an object using dot notation.
*
* @param {String} path
* @param {String | Array<String>} path
* @param {Object} obj
* @return {Mixed} The removed value
*/
remove(path: string, obj: any): any;
remove(path: string | string[], obj: any): any;
/**
*
* Replace/create with a string