mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
🤖 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:
parent
76d0ee77ba
commit
1a3510f39a
@ -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)
|
||||
|
||||
48
types/dot-object/index.d.ts
vendored
48
types/dot-object/index.d.ts
vendored
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user