From 447e3a195e07a74962de402684e63d1dc88e9b08 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Sat, 21 Sep 2024 01:47:43 +1000 Subject: [PATCH] [8.x] Removes kbn-std/unset as it's not used anywhere (#193298) (#193585) # Backport This will backport the following commits from `main` to `8.x`: - [Removes kbn-std/unset as it's not used anywhere (#193298)](https://github.com/elastic/kibana/pull/193298) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Rudolf Meijering --- packages/kbn-std/index.ts | 1 - packages/kbn-std/src/unset.test.ts | 94 ------------------------------ packages/kbn-std/src/unset.ts | 39 ------------- 3 files changed, 134 deletions(-) delete mode 100644 packages/kbn-std/src/unset.test.ts delete mode 100644 packages/kbn-std/src/unset.ts diff --git a/packages/kbn-std/index.ts b/packages/kbn-std/index.ts index 294c168fdd0db..82467cc93d61d 100644 --- a/packages/kbn-std/index.ts +++ b/packages/kbn-std/index.ts @@ -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 { diff --git a/packages/kbn-std/src/unset.test.ts b/packages/kbn-std/src/unset.test.ts deleted file mode 100644 index 6165423d8539e..0000000000000 --- a/packages/kbn-std/src/unset.test.ts +++ /dev/null @@ -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', - }, - }); - }); -}); diff --git a/packages/kbn-std/src/unset.ts b/packages/kbn-std/src/unset.ts deleted file mode 100644 index f18fce5175533..0000000000000 --- a/packages/kbn-std/src/unset.ts +++ /dev/null @@ -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: 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]; - } -}