jxk (meaning: extreme, small, fast) zero-dependency function library, including commonly used functions
English | 中文
The jxk
library aims to provide developers with a set of handy tools that can be used in both client-side and server-side JavaScript environments. It includes functions for common tasks such as manipulating objects and arrays, string handling, type checking, and more.
To use jxk
, you can install it via npm:
pnpm add jxk
yarn add jxk
npm i jxk
Once installed, you can import the library in your project:
import jxk from 'jxk';
// Or if you are using a function:
import {
sm4
} from 'jxk';
For all functions, please visit: https://www.jixiaokang.com/jxk/
Here is a list of some of the functions included in the jxk
library:
-
browser_decode: Unescape HTML entities.
- Purpose: Converts HTML entities back to their original characters.
- Example:
browser_decode('<p>Hello</p>'); // Returns "<p>Hello</p>"
-
browser_encode: Escape HTML entities.
- Purpose: Converts special characters to HTML entities to prevent XSS attacks.
- Example:
browser_encode('<p>Hello</p>'); // Returns "<p>Hello</p>"
- sm2: SM2 cryptographic algorithm, including key pair generation, encryption, decryption, signing, and verification.
- sm3: SM3 message digest algorithm.
- sm4: SM4 encryption and decryption.
- time_date: Format dates, see documentation at date-fns.
- time_format: Format time.
- analysis_address: Province, city, and district analysis extraction.
- analysis_idcard: ID card number parsing.
-
array_chunk: Split an array into chunks of a specified size.
- Example:
array_chunk([1, 2, 3, 4, 5], 2); // Returns [[1, 2], [3, 4], [5]]
- Example:
-
array_concat: Concatenate arrays.
- Example:
array_concat([1, 2], [3, 4]); // Returns [1, 2, 3, 4]
- Example:
-
array_countOccurrences: Count occurrences of each item in an array.
- Example:
array_countOccurrences(['apple', 'banana', 'apple', 'orange', 'banana', 'banana']); // Returns { apple: 2, banana: 3, orange: 1 }
- Example:
-
array_diffBoth: Difference between two arrays.
-
array_diffFirst: Difference of the first array.
-
array_durstenfeldShuffle: Durstenfeld shuffle algorithm.
-
array_findIndex: Find index of matching item in an array.
-
array_findObj: Find matching object in an array.
-
array_findParent: Find the parent(s) of a specified child ID in an array.
-
array_findParent (another): Find the parent(s) of a specified child ID in a tree structure.
-
array_flatten: Flatten a multidimensional array into a one-dimensional array.
-
array_fromTree: Convert a tree structure to a flattened array.
-
array_groupBy: Group array data.
-
array_intersection: Compute the intersection of two arrays.
-
array_keyBy: Sort array by key.
-
array_max: Compute the maximum value in an array.
-
array_merge: Merge multiple arrays and return their union.
-
array_min: Compute the minimum value in an array.
-
array_omitBy: Exclude items with specific keys from an array.
-
array_paging: Paginate an array.
-
array_pick: Pick items with specific keys from an array.
-
array_randomItem: Randomly select an item from an array.
-
array_remove: Remove items based on elements.
-
array_sattoloShuffle: Sattolo shuffle algorithm.
-
array_shuffle: Shuffle an array randomly.
-
array_sort: Sort an array.
-
array_sumBy: Sum values in an array.
-
array_toMapByKey: Convert an array to a Map object based on a key.
-
array_toTree: Convert an array to a tree structure.
-
array_uniqWith: Deduplicate an array.
-
array_unique: Deduplicate an array.
-
array_uniqueByField: Deduplicate an object array by a specific field.
- browser_copyText: Copy text.
- Example:
browser_copyText('Hello, world!');
- Example:
- debounce: Debounces a function to prevent it from being called too often.
- throttle: Throttles a function to limit its execution frequency.
Contributions are welcome! Please read the CONTRIBUTING.md file for details on our code of conduct, how to submit pull requests, and so on.