@naman_deep_singh/js-extensions
v1.0.0
Published
Universal JavaScript prototype extensions for common development utilities
Maintainers
Readme
@naman_deep_singh/js-extensions
Universal JavaScript prototype extensions for common development utilities. Works in both Node.js and browser environments.
Installation
npm install @naman_deep_singh/js-extensions
# or
pnpm add @naman_deep_singh/js-extensionsUsage
Initialize All Extensions
import { initExtensions } from '@naman_deep_singh/js-extensions';
// Initialize all extensions
initExtensions();
// Now use the extensions
"hello world".toCapitalize(); // "Hello world"
[1, 2, 2, 3].unique(); // [1, 2, 3]Selective Extensions
import { extend } from '@naman_deep_singh/js-extensions';
// Only extend strings
extend.string();
// Only extend arrays and objects
initExtensions({ array: true, object: true, string: false, number: false });String Extensions
toCapitalize()- Capitalize first lettertoCamelCase()- Convert to camelCasetoKebabCase()- Convert to kebab-casetoSnakeCase()- Convert to snake_casetruncate(length, suffix?)- Truncate with optional suffixisEmail()- Check if valid emailisUrl()- Check if valid URLremoveWhitespace()- Remove all whitespacereverse()- Reverse string
Array Extensions
unique()- Remove duplicatesshuffle()- Randomly shuffle arraychunk(size)- Split into chunksgroupBy(keyFn)- Group by key functionsum()- Sum numeric valuesaverage()- Calculate averagecompact()- Remove falsy valuespluck(key)- Extract property values
Object Extensions
isEmpty()- Check if object is emptypick(keys)- Pick specific keysomit(keys)- Omit specific keysdeepClone()- Deep clone objectmerge(other)- Merge with another object
Number Extensions
toPercent(decimals?)- Convert to percentage stringtoCurrency(currency?, locale?)- Format as currencyclamp(min, max)- Clamp between min/maxisEven()- Check if evenisOdd()- Check if oddisPrime()- Check if prime numberfactorial()- Calculate factorial
Browser Usage
<script src="path/to/js-extensions.js"></script>
<script>
// Extensions are automatically initialized
console.log("hello".toCapitalize()); // "Hello"
</script>