Installation
Add the library to a Node.js project:
# Yarn
yarn add funclib
# NPM
npm install funclib
For mini-program environments:
# Yarn
yarn add funclib-mp
# NPM
npm install funclib-mp
Basic Usage
// Standard JavaScript
const lib = require('funclib');
// Mini-program variant
// const lib = require('funclib-mp');
const users = [
{ username: 'Charlie', years: 28 },
{ username: 'Diana', years: 32 }
];
lib.log(users, 'Team Members');
Core Functionality
Type Operations
typeOf: Identify JavaScript value typestypeVal: Retrieve value matching expected typeisStr: Verify string typeisNum: Verify numeric typeisBol: Verify boolean typeisFun: Verify function typeisNul: Detect null valuesisUdf: Detect undefined valuesisErr: Identify Error objectsisDat: Identify Date instancesisReg: Identify RegExp instancesisArr: Verify array typeisObj: Verify plain object type
Array Processing
array: Generate array with fixed lengthrange: Create sequential number arraytoArr: Convert value to array formatindexOf: Locate item position in collectionfind: Search collection by predicatefilter: Select items matching criteriareject: Exclude items matching criteriacontains: Check collection for matching itemdrop: Remove falsy/empty elementsflatten: Reduce array nesting levelspluck: Extract property values to new arrayuniq: Remove duplicate entrieseach/forEach: Iterate through collectionssortBy: Order object arrays by property
Object Manipulation
len: Count object propertieshas: Check property existenceget: Retrieve nested property valuesset: Assign nested property valueskeys: Get object property namespick: Create subset objectomit: Create object excluding propertiesextend: Merge object propertiesforIn: Iterate enumerable propertiesdeepCopy: Clone complex structuresisEmpty: Test for empty containersisDeepEqual: Compare nested structures
Mathematical Utilities
random: Generate bounded random numbersgid: Create random identifier stringsgcolor: Produce random color codes
Temporal Functions
interval: Configure recurring timerstimeout: Set delayed executiondefer: Postpone function invocationtime/timestamp: Get current epoch timeasUtcTime: Convert to UTC timestampasXyzTime: Apply timezone offsetfmtDate: Format localized datesfmtUtcDate: Format UTC datesfmtXyzDate: Format timezone-adjusted dates
String Handling
match: Pattern-based string searchpretty: Format structured outputescape: Encode HTML enttiiesunescape: Decode HTML entitiescapitalize: Normalize capitalizationfmtCurrency: Format monetary valuesmaskString: Obscure sensitive substringscutString: Truncate with ellipsisparseQueryStr: Decode URL parametersstringifyQueryStr: Encode parameters to URL string
Regex Toolkit
setPattern: Define custom expressionsgetPattern: Access predefined patternstestPattern: Validate against paternsmatchPattern: Extract pattern matches
Function Enhancements
rest: Capture trailing argumentsthrottle: Limit invocation frequencydebounce: Delay repeated invocations
Output Management
chalk: Style console output (server)print: Display raw values (client/server)log: Display formattted values (client/server)
DOM Interactions (Client)
fullScreen: Enable element fullscreenexitFullScreen: Disable fullscreen modecheckIsFullScreen: Verify fullscreen statefullScreenChange: Monitor fullscreen changes
File Operations (Server)
rd: Read file contentswt: Write file contentscp: Duplicate files/directoriesmv: Relocate files/directoriesrm: Delete files/directoriesmk: Create directory structuresize: Determine file dimensionsclear: Reset console displaycopyText: Transfer text to clipboard (client)
Progress Indicators (Server)
progress: Visualize operation advancementprogress.stop: Terminate visualization
Advanced Features
chain: Enable method chainingnoConflict: Resolve namespace collisionsversion: Retrieve library version