From 6e05fd9e16acd6a0faf138e50268b0049fa09425 Mon Sep 17 00:00:00 2001 From: Damon Date: Thu, 9 Jun 2022 16:18:21 +0200 Subject: [PATCH] Remove unused getObjectArrayMemoString --- .../get-object-array-memo-string.test.ts | 61 ------------------- .../get-object-array-memo-string.ts | 31 ---------- .../lib/get-object-array-memo-string/index.ts | 1 - .../get-object-array-memo-string.test.ts | 38 ------------ .../get-object-array-memo-string/index.ts | 3 - 5 files changed, 134 deletions(-) delete mode 100644 packages/lib/get-object-array-memo-string/get-object-array-memo-string.test.ts delete mode 100644 packages/lib/get-object-array-memo-string/get-object-array-memo-string.ts delete mode 100644 packages/lib/get-object-array-memo-string/index.ts delete mode 100644 packages/lib/object/get-object-array-memo-string/get-object-array-memo-string.test.ts delete mode 100644 packages/lib/object/get-object-array-memo-string/index.ts diff --git a/packages/lib/get-object-array-memo-string/get-object-array-memo-string.test.ts b/packages/lib/get-object-array-memo-string/get-object-array-memo-string.test.ts deleted file mode 100644 index f547c74ad..000000000 --- a/packages/lib/get-object-array-memo-string/get-object-array-memo-string.test.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { getObjectArrayMemoString } from './get-object-array-memo-string' - -describe('getObjectArrayMemoString', () => { - it('should return an empty string if given an undefined value', () => { - expect(getObjectArrayMemoString(undefined)).toBe('') - }) - - it('should return an empty string if the array is empty', () => { - expect(getObjectArrayMemoString([])).toBe('') - }) - - it('should return a string from the ids in the array', () => { - const results = [ - { - id: 'one', - }, - { - id: 'two', - }, - { - id: 'three', - }, - ] - expect(getObjectArrayMemoString(results)).toBe('one,two,three') - }) - - it('should use empty strings if it cannot find ids in the array', () => { - const results = [ - { - foo: 'bar', - }, - { - foo: 'bar', - }, - ] - expect(getObjectArrayMemoString(results)).toBe(',') - }) - - it('should return a string of nested ids when fields have their own lists', () => { - const results = [ - { - id: 'one', - list: [ - { - id: 'a', - }, - { - id: 'b', - }, - ], - }, - { - id: 'two', - }, - { - id: 'three', - }, - ] - expect(getObjectArrayMemoString(results)).toBe('one,one.a,one.b,two,three') - }) -}) diff --git a/packages/lib/get-object-array-memo-string/get-object-array-memo-string.ts b/packages/lib/get-object-array-memo-string/get-object-array-memo-string.ts deleted file mode 100644 index 232da643a..000000000 --- a/packages/lib/get-object-array-memo-string/get-object-array-memo-string.ts +++ /dev/null @@ -1,31 +0,0 @@ -type WithId = { - id: unknown -} - -export const getObjectArrayMemoString = ( - results: unknown, - prefix = '' -): string => { - if (!results) return '' - if (Array.isArray(results)) { - return results - .map((result) => getObjectArrayMemoString(result, prefix)) - .join(',') - } - if (typeof results === 'object') { - const objectId = (results as WithId).id || '' - return Object.values(results) - .reduce( - (state, value) => { - if (!Array.isArray(value)) return [`${prefix}${state}`] - return [ - ...state, - getObjectArrayMemoString(value, `${prefix}${objectId}.`), - ] - }, - [objectId] - ) - .join(',') - } - return `${prefix}${results}` -} diff --git a/packages/lib/get-object-array-memo-string/index.ts b/packages/lib/get-object-array-memo-string/index.ts deleted file mode 100644 index b81d5e2b1..000000000 --- a/packages/lib/get-object-array-memo-string/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './get-object-array-memo-string' diff --git a/packages/lib/object/get-object-array-memo-string/get-object-array-memo-string.test.ts b/packages/lib/object/get-object-array-memo-string/get-object-array-memo-string.test.ts deleted file mode 100644 index 76b5cde04..000000000 --- a/packages/lib/object/get-object-array-memo-string/get-object-array-memo-string.test.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { getObjectArrayMemoString } from '.' - -describe('getObjectArrayMemoString', () => { - it('should return null passed value is not an array', () => { - expect(getObjectArrayMemoString(undefined)).toBe(null) - }) - - it('should return an empty string if the array is empty', () => { - expect(getObjectArrayMemoString([])).toBe('') - }) - - it('should return a string from the ids in the array', () => { - const results = [ - { - id: 'one', - }, - { - id: 'two', - }, - { - id: 'three', - }, - ] - expect(getObjectArrayMemoString(results)).toBe('one,two,three') - }) - - it('should use empty strings if it cannot find ids in the array', () => { - const results = [ - { - foo: 'bar', - }, - { - foo: 'bar', - }, - ] - expect(getObjectArrayMemoString(results)).toBe(',') - }) -}) diff --git a/packages/lib/object/get-object-array-memo-string/index.ts b/packages/lib/object/get-object-array-memo-string/index.ts deleted file mode 100644 index a9ec48c75..000000000 --- a/packages/lib/object/get-object-array-memo-string/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -//eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types -export const getObjectArrayMemoString = (results: any): string => - results && Array.isArray(results) ? results.map((r) => r.id).join(',') : null