mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Removes kbn-std/unset as it's not used anywhere (#193298)
## Summary Removes unset as it's not used anywhere. Underscore includes an unset function which most plugins seem to prefer.
This commit is contained in:
parent
96dd4c7863
commit
bddeac062a
3 changed files with 0 additions and 134 deletions
|
@ -19,7 +19,6 @@ export type { URLMeaningfulParts } from './src/url';
|
|||
export { isRelativeUrl, modifyUrl, getUrlOrigin } from './src/url';
|
||||
export { isInternalURL } from './src/is_internal_url';
|
||||
export { parseNextURL } from './src/parse_next_url';
|
||||
export { unset } from './src/unset';
|
||||
export { getFlattenedObject } from './src/get_flattened_object';
|
||||
export { ensureNoUnsafeProperties } from './src/ensure_no_unsafe_properties';
|
||||
export {
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the "Elastic License
|
||||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
|
||||
* Public License v 1"; you may not use this file except in compliance with, at
|
||||
* your election, the "Elastic License 2.0", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import { unset } from './unset';
|
||||
|
||||
describe('unset', () => {
|
||||
it('deletes a property from an object', () => {
|
||||
const obj = {
|
||||
a: 'a',
|
||||
b: 'b',
|
||||
c: 'c',
|
||||
};
|
||||
unset(obj, 'a');
|
||||
expect(obj).toEqual({
|
||||
b: 'b',
|
||||
c: 'c',
|
||||
});
|
||||
});
|
||||
|
||||
it('does nothing if the property is not present', () => {
|
||||
const obj = {
|
||||
a: 'a',
|
||||
b: 'b',
|
||||
c: 'c',
|
||||
};
|
||||
unset(obj, 'd');
|
||||
expect(obj).toEqual({
|
||||
a: 'a',
|
||||
b: 'b',
|
||||
c: 'c',
|
||||
});
|
||||
});
|
||||
|
||||
it('handles nested paths', () => {
|
||||
const obj = {
|
||||
foo: {
|
||||
bar: {
|
||||
one: 'one',
|
||||
two: 'two',
|
||||
},
|
||||
hello: 'dolly',
|
||||
},
|
||||
some: {
|
||||
things: 'here',
|
||||
},
|
||||
};
|
||||
unset(obj, 'foo.bar.one');
|
||||
expect(obj).toEqual({
|
||||
foo: {
|
||||
bar: {
|
||||
two: 'two',
|
||||
},
|
||||
hello: 'dolly',
|
||||
},
|
||||
some: {
|
||||
things: 'here',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('does nothing if nested paths does not exist', () => {
|
||||
const obj = {
|
||||
foo: {
|
||||
bar: {
|
||||
one: 'one',
|
||||
two: 'two',
|
||||
},
|
||||
hello: 'dolly',
|
||||
},
|
||||
some: {
|
||||
things: 'here',
|
||||
},
|
||||
};
|
||||
unset(obj, 'foo.nothere.baz');
|
||||
expect(obj).toEqual({
|
||||
foo: {
|
||||
bar: {
|
||||
one: 'one',
|
||||
two: 'two',
|
||||
},
|
||||
hello: 'dolly',
|
||||
},
|
||||
some: {
|
||||
things: 'here',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the "Elastic License
|
||||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
|
||||
* Public License v 1"; you may not use this file except in compliance with, at
|
||||
* your election, the "Elastic License 2.0", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import { get } from './get';
|
||||
|
||||
/**
|
||||
* Unset a (potentially nested) key from given object.
|
||||
* This mutates the original object.
|
||||
*
|
||||
* @example
|
||||
* ```
|
||||
* unset(myObj, 'someRootProperty');
|
||||
* unset(myObj, 'some.nested.path');
|
||||
* ```
|
||||
*/
|
||||
export function unset<OBJ extends { [k: string]: any }>(obj: OBJ, atPath: string) {
|
||||
const paths = atPath
|
||||
.split('.')
|
||||
.map((s) => s.trim())
|
||||
.filter((v) => v !== '');
|
||||
if (paths.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (paths.length === 1) {
|
||||
delete obj[paths[0]];
|
||||
return;
|
||||
}
|
||||
const property = paths.pop() as string;
|
||||
const parent = get(obj, paths as any) as any;
|
||||
if (parent !== undefined) {
|
||||
delete parent[property];
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue