📅  最后修改于: 2023-12-03 15:02:41.184000             🧑  作者: Mango
Lil is a lightweight and easy-to-use library that provides useful helper functions to simplify everyday programming tasks in JavaScript.
You can install Lil via npm:
npm install lil-lib
capitalize(str)
: Capitalizes the first letter of a string.titleCase(str)
: Converts the string to title case.truncate(str, length, ending)
: Truncates a string to a specified length and appends an optional ending.chunk(arr, size)
: Splits an array into smaller arrays of a specified size.compact(arr)
: Removes falsy values from an array.intersection(arr1, arr2)
: Returns an array of values in both input arrays.uniq(arr)
: Removes duplicate values from an array.clamp(num, min, max)
: Restricts a number to be within a specified range.toReadable(num)
: Formats a number with comma separators to make it more readable.const Lil = require('lil-lib');
const str = 'hello world';
const arr = [0, false, null, undefined, NaN, '', 1];
console.log(Lil.capitalize(str)); // 'Hello world'
console.log(Lil.chunk(arr, 2)); // [[0, false], [null, undefined], [NaN, ''], [1]]
console.log(Lil.clamp(5, 0, 10)); // 5
console.log(Lil.toReadable(10000)); // '10,000'
Lil is a small library with big capabilities. With its easy-to-use functions and simple installation process, it can streamline your JavaScript coding and make your life easier. Give it a try and see how it can improve your workflow!