@zlikemario/helper
v0.0.14
Published
A utility library with number operations and common helper functions
Maintainers
Readme
@zlikemario/helper
A utility library with number operations and common helper functions.
Installation
npm install @zlikemario/helper
# or
yarn add @zlikemario/helper
# or
pnpm add @zlikemario/helperUsage
Number Operations
import { BigNumber, isNumber, simplifyNumber } from '@zlikemario/helper/number'
// Check if a value is a number
console.log(isNumber('123')) // true
// Simplify large numbers
console.log(simplifyNumber(1234567)) // "1.2M"
// Use BigNumber for precise calculations
const result = new BigNumber('0.1').plus('0.2')
console.log(result.toString()) // "0.3"Utility Functions
import { sleep, encrypt, isEmail } from '@zlikemario/helper/utils'
// Sleep function
await sleep(1000) // Wait for 1 second
// Encrypt sensitive data
console.log(encrypt('1234567890', 2, 2)) // "12****90"
// Validate email
console.log(isEmail('[email protected]')) // trueAPI Reference
Number Module (@zlikemario/helper/number)
BigNumber- BigNumber.js instance for precise calculationsisNumber(num, isInt?)- Check if value is a numbersimplifyNumber(num, decimal?, rm?)- Simplify large numbers (1.2K, 3.4M)readabilityNumber(num)- Add thousand separatorstoPercentage(num, precision?, isHiddenUnit?)- Convert to percentageformatPrecision(num, precision?)- Format with specific precisionreadableNumber(num, decimals?)- Advanced readable formattingsum(data)- Sum array of numberssumBy(data, key)- Sum by object property or function
Utils Module (@zlikemario/helper/utils)
sleep(interval?)- Async sleep functionencrypt(text, prefix?, suffix?, placeholder?)- Mask sensitive dataisUndefined(v)- Check if value is undefinedisHasUndefined(...vs)- Check if any value is undefinedisPromise(v)- Check if value is a Promiseuint8ArrayToBase64(array)- Convert Uint8Array to Base64base64ToUint8Array(base64)- Convert Base64 to Uint8ArrayarrayBufferToBase64(buffer)- Convert ArrayBuffer to Base64isDomain(text)- Validate domain nameisEmail(text)- Validate email addresstryCatchAsync(p, catchFn?)- Async try-catch wrapperpreventTimeout(callback, options?)- Execute with timeout protection
License
MIT
