Deprecated old methods
This commit is contained in:
		| @@ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
| 	"name": "@ztimson/utils", | 	"name": "@ztimson/utils", | ||||||
| 	"version": "0.22.0", | 	"version": "0.22.1", | ||||||
| 	"description": "Utility library", | 	"description": "Utility library", | ||||||
| 	"author": "Zak Timson", | 	"author": "Zak Timson", | ||||||
| 	"license": "MIT", | 	"license": "MIT", | ||||||
|   | |||||||
| @@ -29,10 +29,10 @@ export function clean<T>(obj: T, undefinedOnly = false): Partial<T> { | |||||||
|  * Should be replaced by `structuredClone` once released. |  * Should be replaced by `structuredClone` once released. | ||||||
|  * @param {T} value Object to copy |  * @param {T} value Object to copy | ||||||
|  * @returns {T} Type |  * @returns {T} Type | ||||||
|  * @deprecated Please use `structuredClone` |  | ||||||
|  */ |  */ | ||||||
| export function deepCopy<T>(value: T): T { | export function deepCopy<T>(value: T): T { | ||||||
| 	return structuredClone(value); | 	try {return structuredClone(value); } | ||||||
|  | 	catch { return JSON.parse(JSONSanitize(value)); } | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -234,10 +234,8 @@ export function JSONAttemptParse<T>(json: string): T | string { | |||||||
| export function JSONSanitize(obj: any, space?: number): string { | export function JSONSanitize(obj: any, space?: number): string { | ||||||
| 	let cache: any[] = []; | 	let cache: any[] = []; | ||||||
| 	return JSON.stringify(obj, (key, value) => { | 	return JSON.stringify(obj, (key, value) => { | ||||||
| 		if (typeof value === 'object' && value !== null) { | 		if(typeof value === 'object' && value !== null) | ||||||
| 			if (cache.includes(value)) return; | 			if(!cache.includes(value)) cache.push(value); | ||||||
| 			cache.push(value); |  | ||||||
| 		} |  | ||||||
| 		return value; | 		return value; | ||||||
| 	}, space); | 	}, space); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,5 +1,3 @@ | |||||||
| import {dotNotation, flattenObj} from './objects.ts'; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * String of all letters |  * String of all letters | ||||||
|  */ |  */ | ||||||
| @@ -44,7 +42,7 @@ export function formatBytes(bytes: number, decimals = 2) { | |||||||
| export function formatPhoneNumber(number: string) { | export function formatPhoneNumber(number: string) { | ||||||
| 	const parts = /(\+?1)?.*?(\d{3}).*?(\d{3}).*?(\d{4})/g.exec(number); | 	const parts = /(\+?1)?.*?(\d{3}).*?(\d{3}).*?(\d{4})/g.exec(number); | ||||||
| 	if(!parts) throw new Error(`Number cannot be parsed: ${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 {string} str - Value that will be injected to parent | ||||||
|  * @param {number} index - Position to inject string at |  * @param {number} index - Position to inject string at | ||||||
|  * @returns {string} - New string |  * @returns {string} - New string | ||||||
|  |  * @deprecated use `strSplice()` | ||||||
|  */ |  */ | ||||||
| export function insertAt(target: string, str: string, index: number): String { | export function insertAt(target: string, str: string, index: number): String { | ||||||
| 	return `${target.slice(0, index)}${str}${target.slice(index + 1)}`; | 	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 |  * @param {string} url URL string that will be parsed | ||||||
|  * @returns {RegExpExecArray} Parts of URL |  * @returns {RegExpExecArray} Parts of URL | ||||||
|  |  * @deprecated Use built-in URL object: `new URL('...')`; | ||||||
|  */ |  */ | ||||||
| export function parseUrl(url: string): ParsedUrl { | export function parseUrl(url: string): ParsedUrl { | ||||||
| 	const processed = new RegExp( | 	const processed = new RegExp( | ||||||
|   | |||||||
| @@ -15,6 +15,6 @@ | |||||||
|  * |  * | ||||||
|  * @return {Array<keyof T>} Available keys |  * @return {Array<keyof T>} Available keys | ||||||
|  */ |  */ | ||||||
| export function tyoeKeys<T extends object>() { | export function typeKeys<T extends object>() { | ||||||
| 	return Object.keys(<T>{}) as Array<keyof T>; | 	return Object.keys(<T>{}) as Array<keyof T>; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user