Parsnip-Kit is a zero-dependency JavaScript utility library that supports TypeScript. It provides a collection of practical utility functions to help developers handle common programming tasks more efficiently.
Two-factor authentication was lost, forcing an account reincarnation; the Parsnip-Kit project will continue to be maintained in this repository.
npm install parsnip-kit- 🧳 Zero Dependencies: Lightweight and efficient with no external dependencies, making it suitable for projects of any size.
- 🔩 Multi-functional: Supports modules such as array, object, string, type checking, asynchronous operation, function, and statistic. Adds functions that developers have been eager for.
- 💡 Type-friendly: Written in TypeScript, providing accurate and complete type hints to enhance the development experience and code quality.
- 🚀 Modern: Built with modern JavaScript APIs, it aims to provide developers with commonly used utility functions that are not yet natively supported.
- 📦 Modular: Supports ES6 modularization and tree-shaking.
- 🛠️ Easy to Maintain: Has comprehensive unit tests and coding standards, and is equipped with automated document generation and a document site project, making it easy for subsequent expansion and maintenance.
Here's an overview of the tool functions provided by Parsnip-Kit:
- Object: For manipulating JavaScript objects, such as
cloneDeep,isEqual,getByPath. - Array: For manipulating arrays, such as
unique,intersection,lexSortandnumberSort. - Statistic: For descriptive statistics in JavaScript, including
sum,maxItemandminItem. - Number: For processing numbers, such as
range,thousandSeparatorandpercent. - Function: Functions for handling function parameters, returns, and logic, such as:
debounce,throttle,combineandcurry. - Async: Focused on asynchronous process handling, such as
concurrent,retryandasyncForEach. - String: String tool functions, such as
camelCase,snakeCaseandhtmlEncode. - Typed: For checking the type of input parameters, including
isPrimitive,isNanValueandgetTypeTag. - Random: Generates random data, including
randomNumber,randomStringandrandomFromArray.
Parsnip-Kit is designed for various JavaScript and TypeScript projects, from small tools to large applications. It aims to provide concise and efficient utility functions to save developers' time and effort.
import {
sum,
median,
average,
pairsToObject,
leftJoin,
getByPath,
omit,
pick
} from 'parsnip-kit'
const data = [
{
id: 13, name: 'Alice', email: '[email protected]',
blog: { count: 15, fans: 45 }
},
{
id: 18, name: 'Bob', email: '[email protected]',
blog: { count: 55, fans: 1546 }
},
{
id: 35, name: 'Carlin', email: '[email protected]',
blog: { count: 116, fans: 56563 }
}
]
const profile = [
{ id: 13, age: 44, nickname: 'coding neko' },
{ id: 18, age: 30, nickname: 'kurisutina' },
{ id: 35, age: 23, nickname: 'Bug Engineer' }
]
average(data, 'blog.count') // 62
sum(data, 'blog.count') // 186
median(data, 'blog.count') // 55
pairsToObject(data, 'name', 'blog.fans')
// { Alice: 45, Bob: 1546, Carlin: 56563 }
getByPath(data, '[0].email')
// '[email protected]'
omit(data[0], ['blog'])
// { id: 13, name: 'Alice', email: 'alice@example.test' }
pick(data[0], ['id', 'name', 'blog'])
// { id: 13, name: 'Alice', blog: { count: 15, fans: 45 } }
leftJoin(data, profile, 'id', 'id', (a, b) => ({...a, ...b}))
// [
// {
// id: 13, name: 'Alice', email: '[email protected]',
// age: 30, nickname: 'kurisutina',
// blog: { count: 15, fans: 45 }
// },
// {
// id: 18, name: 'Bob', email: '[email protected]',
// age: 30, nickname: 'kurisutina',
// blog: { count: 55, fans: 1546 }
// },
// {
// id: 35, name: 'Carlin', email: '[email protected]',
// age: 23, nickname: 'Bug Engineer',
// blog: { count: 116, fans: 56563 }
// }
// ]- Documentation: View Documentation to learn more about the features and usage.
- Support: Encountered issues during use? Feel free to submit Issues or Pull Requests.
Parsnip-Kit is licensed under the MIT License. See the LICENSE file for details.
Thank you for using Parsnip-Kit!