A lightweight utility library written in TypeScript with zero dependencies, supporting ESM, CJS, and UMD formats.
API Documentation • Getting Started • Features
✨ Features
- Type-Safe: Full TypeScript support with comprehensive type definitions
- Zero Dependencies: Pure native implementation, no external libraries
- Tree Shaking: Supports selective imports for smaller bundle sizes
- Multi-Format: ESM, CJS, and UMD builds available
- Web Focused: Optimized for modern web environments
Core Utilities
Type Checking
isString,isNumber,isBoolean,isFunction,isObject,isArrayisDate,isRegExp,isUndefined,isNull,isError,isNaNisPrimitive,isSymbol,isBigInt,isPlainObjectisEmpty,isNodeList,isValidDate,typeIs
Data Structures
- Array:
arrayEach,arrayEachAsync,arrayInsertBefore,arrayRemove - Tree:
forEachDeep,mapDeep,findDeep,filterDeep,searchTreeById,flatTree,fuzzySearchTree - Object:
objectAssign,objectGet,objectHas,cloneDeep,objectPick,objectOmit
Web APIs
- DOM:
addClass,hasClass,removeClass,getStyle,setStyle - File:
chooseLocalFile,compressImg - Clipboard:
copyText,fallbackCopyText - Download:
downloadBlob,downloadURL,downloadData - Watermark:
genCanvasWM
Encoding & Validation
- Encode/Decode:
weBtoa,weAtob,b64encode,b64decode - Validation:
isEmail,isPhone,isUrl,isIDNO,isIPv4,isIPv6
Additional Utils
- Date:
formatDate,calculateDate,dateToStart,dateToEnd - String:
stringCamelCase,stringKebabCase,parseQueryParams,stringEscapeHTML - Math:
add,subtract,multiply,divide,numberAbbr - Functional:
debounce,throttle,once,wait
🚀 Installation
npm
bash
npm install sculp-jsCDN
html
<script src="https://unpkg.com/sculp-js"></script>💡 Usage
js
import { forEachDeep, cloneDeep } from 'sculp-js';
// Deep traversal of tree structures
const tree = [
{
id: 1,
name: 'Parent 1',
children: [
{ id: 11, name: 'Child 1' },
{ id: 12, name: 'Child 2', children: [{ id: 121, name: 'Grandchild 1' }] }
]
},
{ id: 2, name: 'Parent 2' }
];
const names = [];
forEachDeep(tree, item => {
names.push(item.name);
});
// names = ['Parent 1', 'Child 1', 'Child 2', 'Grandchild 1', 'Parent 2']
// Deep cloning of objects
const original = { a: 1, b: { c: 2 } };
const cloned = cloneDeep(original);📦 Module Formats
js
// ES Modules (recommended)
import { cloneDeep } from 'sculp-js';
// Individual module imports
import cloneDeep from 'sculp-js/cloneDeep';
// CommonJS
const { cloneDeep } = require('sculp-js');