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.
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
,lexSort
andnumberSort
. - Statistic: For descriptive statistics in JavaScript, including
sum
,maxItem
andminItem
. - Number: For processing numbers, such as
range
,thousandSeparator
andpercent
. - Function: Functions for handling function parameters, returns, and logic, such as:
debounce
,throttle
,combine
andcurry
. - Async: Focused on asynchronous process handling, such as
concurrent
,retry
andasyncForEach
. - String: String tool functions, such as
camelCase
,snakeCase
andhtmlEncode
. - Typed: For checking the type of input parameters, including
isPrimitive
,isNanValue
andgetTypeTag
. - Random: Generates random data, including
randomNumber
,randomString
andrandomFromArray
.
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: 'alice@example.test',
blog: { count: 15, fans: 45 }
},
{
id: 18, name: 'Bob', email: 'bob@example.test',
blog: { count: 55, fans: 1546 }
},
{
id: 35, name: 'Carlin', email: 'carlin@example.test',
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: 'Bob - Software 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')
// 'alice@example.test'
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: 'alice@example.test',
// age: 30, nickname: 'kurisutina',
// blog: { count: 15, fans: 45 }
// },
// {
// id: 18, name: 'Bob', email: 'bob@example.test',
// age: 30, nickname: 'kurisutina',
// blog: { count: 55, fans: 1546 }
// },
// {
// id: 35, name: 'Carlin', email: 'carlin@example.test',
// age: 23, nickname: 'Bob - Software 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!