parsnip-kit
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Parsnip-Kit

TypeScript Vite MIT License

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.

API Document Npm

Language Versions

Installation

npm install parsnip-kit

Features

  1. 🧳 Zero Dependencies: Lightweight and efficient with no external dependencies, making it suitable for projects of any size.
  2. 🔩 Multi-functional: Supports modules such as array, object, string, type checking, asynchronous operation, function, and statistic. Adds functions that developers have been eager for.
  3. 💡 Type-friendly: Written in TypeScript, providing accurate and complete type hints to enhance the development experience and code quality.
  4. 🚀 Modern: Built with modern JavaScript APIs, it aims to provide developers with commonly used utility functions that are not yet natively supported.
  5. 📦 Modular: Supports ES6 modularization and tree-shaking.
  6. 🛠️ 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.

Overview

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 and numberSort.
  • Statistic: For descriptive statistics in JavaScript, including sum, maxItem and minItem.
  • Number: For processing numbers, such as range, thousandSeparator and percent.
  • Function: Functions for handling function parameters, returns, and logic, such as: debounce, throttle, combine and curry.
  • Async: Focused on asynchronous process handling, such as concurrent, retry and asyncForEach.
  • String: String tool functions, such as camelCase, snakeCase and htmlEncode.
  • Typed: For checking the type of input parameters, including isPrimitive, isNanValue and getTypeTag.
  • Random: Generates random data, including randomNumber, randomString and randomFromArray.

Use Cases

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 & Support

License

Parsnip-Kit is licensed under the MIT License. See the LICENSE file for details.


Thank you for using Parsnip-Kit!

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.0.23latest

Version History

VersionDownloads (Last 7 Days)Published
0.0.23
0.0.1-beta0
0.0.11

Package Sidebar

Install

npm i parsnip-kit

Weekly Downloads

4

Version

0.0.2

License

MIT

Unpacked Size

307 kB

Total Files

139

Last publish

Collaborators

  • kokoro-ame