0.0.3 • Published 10 months ago
@ezjs/util v0.0.3
@ezjs/util
Many convenient utility function packages that are
ez
to use
All our utilities are designed with asynchronous programming in mind, ensuring they work seamlessly in both synchronous and asynchronous environments. This allows for easy integration into various programming paradigms and application architectures.
Installation
# npm
npm install @ezjs/util
# yarn
yarn add @ezjs/util
# pnpm
pnpm install @ezjs/util
Usage
import { ConvertUtil } from "@ezjs/util";
console.log(ConvertUtil.strToNum("1")); // 1
Utilities
ConvertUtil
numToBool
: Convert number to booleanstrToBool
: Convert string to booleanstrToNum
: Convert string to numberstrToDate
: Convert string to datedateToStr
: Convert date to stringbase64Encode
: Encode string to base64base64Decode
: Decode base64 to string
FileUtil
readFile
: Asynchronously read a filewriteFile
: Asynchronously write data to a fileappendFile
: Asynchronously append data to a filedeleteFile
: Asynchronously delete a filecopyFile
: Asynchronously copy a filemoveFile
: Asynchronously move a filelistFiles
: Asynchronously list files in a directory
RandomUtil
generateRandomString
: Generate a random stringgenerateRandomNumber
: Generate a random number within a rangegenerateUUID
: Generate a UUID (Universally Unique Identifier)shuffleArray
: Randomly shuffle an arraypickRandomElement
: Pick a random element from an array
ErrorUtil
createCustomError
: Create a custom error with additional propertieshandleAsyncError
: Wrapper for handling asynchronous errorslogError
: Log error details with optional metadata
ConfigUtil
loadConfig
: Load configuration from a file or environment variablesvalidateConfig
: Validate configuration against a schemamergeConfigs
: Merge multiple configuration objectsgetConfigValue
: Safely retrieve a configuration value with fallback
ApiUtil
fetchWithRetry
: Fetch data with automatic retries on failurehandleApiResponse
: Handle API responses with error checkingbuildQueryString
: Build a URL query string from an objectparseJsonSafely
: Safely parse JSON with error handling
Authors
- _jujoycode - Developer
Version History
0.0.1
- Initial release with the following utilities:
- ConvertUtil
- FileUtil
- RandomUtil
- ErrorUtil
- ConfigUtil
- ApiUtil
License
This project is licensed under the MIT License