From 1c2c18b65d6980518a2ed95d8c00c24a3669e5f4 Mon Sep 17 00:00:00 2001 From: ztimson Date: Mon, 10 Mar 2025 09:50:16 -0400 Subject: [PATCH] Added camelCase function --- package.json | 2 +- src/string.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ade85b1..098ed24 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ztimson/utils", - "version": "0.23.14", + "version": "0.23.15", "description": "Utility library", "author": "Zak Timson", "license": "MIT", diff --git a/src/string.ts b/src/string.ts index fd0033e..bffd510 100644 --- a/src/string.ts +++ b/src/string.ts @@ -18,6 +18,16 @@ export const SYMBOL_LIST = '~`!@#$%^&*()_-+={[}]|\\:;"\'<,>.?/'; */ export const CHAR_LIST = LETTER_LIST + LETTER_LIST.toLowerCase() + NUMBER_LIST + SYMBOL_LIST; +/** + * Converts text to camel case + */ +export function camelCase(text?: string) { + if(!text) return ''; + text = text.replaceAll(/^[0-9]+/g, '') + .replaceAll(/[^a-zA-Z0-9]+(\w?)/g, (...args) => args[1]?.toUpperCase() || ''); + return text[0].toLowerCase() + text.slice(1); +} + /** * Convert number of bytes into a human-readable size *