From ce40b5b1e7e947fe8a4f8e7aed73b2c505b62f8c Mon Sep 17 00:00:00 2001 From: ztimson Date: Thu, 7 Nov 2024 10:46:56 -0500 Subject: [PATCH] Deprecated old methods --- package.json | 2 +- src/objects.ts | 10 ++++------ src/string.ts | 6 +++--- src/types.ts | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index a95260c..39e74c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ztimson/utils", - "version": "0.22.0", + "version": "0.22.1", "description": "Utility library", "author": "Zak Timson", "license": "MIT", diff --git a/src/objects.ts b/src/objects.ts index c411fd4..76849a8 100644 --- a/src/objects.ts +++ b/src/objects.ts @@ -29,10 +29,10 @@ export function clean(obj: T, undefinedOnly = false): Partial { * Should be replaced by `structuredClone` once released. * @param {T} value Object to copy * @returns {T} Type - * @deprecated Please use `structuredClone` */ export function deepCopy(value: T): T { - return structuredClone(value); + try {return structuredClone(value); } + catch { return JSON.parse(JSONSanitize(value)); } } /** @@ -234,10 +234,8 @@ export function JSONAttemptParse(json: string): T | string { export function JSONSanitize(obj: any, space?: number): string { let cache: any[] = []; return JSON.stringify(obj, (key, value) => { - if (typeof value === 'object' && value !== null) { - if (cache.includes(value)) return; - cache.push(value); - } + if(typeof value === 'object' && value !== null) + if(!cache.includes(value)) cache.push(value); return value; }, space); } diff --git a/src/string.ts b/src/string.ts index b7a3963..e8e5392 100644 --- a/src/string.ts +++ b/src/string.ts @@ -1,5 +1,3 @@ -import {dotNotation, flattenObj} from './objects.ts'; - /** * String of all letters */ @@ -44,7 +42,7 @@ export function formatBytes(bytes: number, decimals = 2) { export function formatPhoneNumber(number: string) { const parts = /(\+?1)?.*?(\d{3}).*?(\d{3}).*?(\d{4})/g.exec(number); if(!parts) throw new Error(`Number cannot be parsed: ${number}`); - return `${parts[1] ?? ''} (${parts[2]}) ${parts[3]}-${parts[4]}`.trim(); + return `${parts[1] ? '+1' : ''} (${parts[2]}) ${parts[3]}-${parts[4]}`.trim(); } /** @@ -60,6 +58,7 @@ export function formatPhoneNumber(number: string) { * @param {string} str - Value that will be injected to parent * @param {number} index - Position to inject string at * @returns {string} - New string + * @deprecated use `strSplice()` */ export function insertAt(target: string, str: string, index: number): String { return `${target.slice(0, index)}${str}${target.slice(index + 1)}`; @@ -210,6 +209,7 @@ export type ParsedUrl = { * * @param {string} url URL string that will be parsed * @returns {RegExpExecArray} Parts of URL + * @deprecated Use built-in URL object: `new URL('...')`; */ export function parseUrl(url: string): ParsedUrl { const processed = new RegExp( diff --git a/src/types.ts b/src/types.ts index 4ae1f63..3ea79bb 100644 --- a/src/types.ts +++ b/src/types.ts @@ -15,6 +15,6 @@ * * @return {Array} Available keys */ -export function tyoeKeys() { +export function typeKeys() { return Object.keys({}) as Array; }