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:
Rudolf Meijering 2024-09-20 15:44:52 +02:00 committed by GitHub
parent 96dd4c7863
commit bddeac062a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 0 additions and 134 deletions

View file

@ -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 {

View file

@ -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',
},
});
});
});

View file

@ -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];
}
}