From bda5d9dce98a00de5db099118881127b603dae3b Mon Sep 17 00:00:00 2001 From: beefchimi Date: Sun, 28 Apr 2024 13:36:59 -0400 Subject: [PATCH] :hammer_and_wrench: [Utilities] Remove all utilities that are replaced by beeftools --- src/index.ts | 1 - src/utilities/general.ts | 25 ------------ src/utilities/index.ts | 1 - src/utilities/network.ts | 2 +- src/utilities/regexp.ts | 2 +- src/utilities/tests/general.test.ts | 59 ----------------------------- src/utilities/url.ts | 3 +- 7 files changed, 4 insertions(+), 89 deletions(-) delete mode 100644 src/utilities/general.ts delete mode 100644 src/utilities/tests/general.test.ts diff --git a/src/index.ts b/src/index.ts index 63a5af9..da61073 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,7 +14,6 @@ export {socialitePrefix} from './prefixes'; export {Socialite} from './socialite'; export { - objFilterNullish, filterNetworkProperties, mergeRegExp, getDiscordPreferredUrl, diff --git a/src/utilities/general.ts b/src/utilities/general.ts deleted file mode 100644 index 6d7667f..0000000 --- a/src/utilities/general.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type {BasicObject} from '../types'; - -export function arrayDedupe(...arrays: T[]) { - // Not recursive (will not dedupe nested arrays). - return [...new Set([...arrays.flat()])]; -} - -export const typedObjectKeys = Object.keys as ( - obj: T, -) => Array; - -export function objFilterNullish(obj = {}): T { - const keys = typedObjectKeys(obj); - - // NOTE: This filter function is not recursive! - return keys.reduce((accumulator, current) => { - return obj[current] == null - ? accumulator - : { - ...accumulator, - [current]: obj[current], - }; - // eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter, @typescript-eslint/consistent-type-assertions - }, {} as T); -} diff --git a/src/utilities/index.ts b/src/utilities/index.ts index 6436bfe..a58cf2b 100644 --- a/src/utilities/index.ts +++ b/src/utilities/index.ts @@ -1,4 +1,3 @@ -export {objFilterNullish} from './general'; export {filterNetworkProperties} from './network'; export {mergeRegExp} from './regexp'; export { diff --git a/src/utilities/network.ts b/src/utilities/network.ts index c0f9a4b..68bf36f 100644 --- a/src/utilities/network.ts +++ b/src/utilities/network.ts @@ -1,9 +1,9 @@ +import {arrayDedupe, typedObjectKeys} from 'beeftools'; import type { SocialiteNetwork, NetworkSubset, SocialiteNetworkProperties, } from '../types'; -import {arrayDedupe, typedObjectKeys} from './general'; export function filterNetworkProperties( network: SocialiteNetwork, diff --git a/src/utilities/regexp.ts b/src/utilities/regexp.ts index bf4cc6d..de6952e 100644 --- a/src/utilities/regexp.ts +++ b/src/utilities/regexp.ts @@ -1,5 +1,5 @@ +import {arrayDedupe} from 'beeftools'; import type {MergedRegExp} from '../types'; -import {arrayDedupe} from './general'; export function mergeRegExp(...expressions: RegExp[]): MergedRegExp { const source = expressions.map((exp) => exp.source).join(''); diff --git a/src/utilities/tests/general.test.ts b/src/utilities/tests/general.test.ts deleted file mode 100644 index 5393ef3..0000000 --- a/src/utilities/tests/general.test.ts +++ /dev/null @@ -1,59 +0,0 @@ -import {describe, it, expect} from 'vitest'; - -import {arrayDedupe, objFilterNullish, typedObjectKeys} from '../general'; - -describe('General utilities', () => { - describe('arrayDedupe()', () => { - it('removes duplicates within a single array', async () => { - const result = arrayDedupe([1, 2, 3, 1, 2, 3]); - expect(result).toStrictEqual([1, 2, 3]); - }); - - it('removes duplicates across multiple arrays', async () => { - const result = arrayDedupe([1, 2, 3], [3, 2, 1], [4, 2, 0]); - expect(result).toStrictEqual([1, 2, 3, 4, 0]); - }); - }); - - describe('objFilterNullish()', () => { - it('returns an object with all null and undefined entries removed', async () => { - const mockObj = { - foo: 1, - bar: 2, - beef: true, - chimi: false, - ear: null, - wurm: undefined, - chicken: 0, - friendship: Infinity, - }; - - const result = objFilterNullish(mockObj); - - expect(result).toStrictEqual({ - foo: 1, - bar: 2, - beef: true, - chimi: false, - chicken: 0, - friendship: Infinity, - }); - }); - }); - - describe('typedObjectKeys()', () => { - it('returns the equivalent of Object.keys()', async () => { - const mockObj = { - foo: 1, - bar: 'two', - beef: false, - chimi: null, - earwurm: undefined, - }; - const result = typedObjectKeys(mockObj); - - expect(result).toStrictEqual(['foo', 'bar', 'beef', 'chimi', 'earwurm']); - expect(result).toStrictEqual(Object.keys(mockObj)); - }); - }); -}); diff --git a/src/utilities/url.ts b/src/utilities/url.ts index c656800..39c9d2f 100644 --- a/src/utilities/url.ts +++ b/src/utilities/url.ts @@ -1,10 +1,11 @@ +import {objFilterNullish} from 'beeftools'; + import {discordPreferredUrls, profileReplacement, urlRegExp} from '../capture'; import type { DiscordUrlCriteria, UrlGroupSubset, ParsedUrlGroups, } from '../types'; -import {objFilterNullish} from './general'; function updateGroupsWithSubdomain(groups: UrlGroupSubset): UrlGroupSubset { const {domain} = groups;