Utilizing the Funclib Utility Library in JavaScript and Mini-programs

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 types
  • typeVal: Retrieve value matching expected type
  • isStr: Verify string type
  • isNum: Verify numeric type
  • isBol: Verify boolean type
  • isFun: Verify function type
  • isNul: Detect null values
  • isUdf: Detect undefined values
  • isErr: Identify Error objects
  • isDat: Identify Date instances
  • isReg: Identify RegExp instances
  • isArr: Verify array type
  • isObj: Verify plain object type

Array Processing

  • array: Generate array with fixed length
  • range: Create sequential number array
  • toArr: Convert value to array format
  • indexOf: Locate item position in collection
  • find: Search collection by predicate
  • filter: Select items matching criteria
  • reject: Exclude items matching criteria
  • contains: Check collection for matching item
  • drop: Remove falsy/empty elements
  • flatten: Reduce array nesting levels
  • pluck: Extract property values to new array
  • uniq: Remove duplicate entries
  • each/forEach: Iterate through collections
  • sortBy: Order object arrays by property

Object Manipulation

  • len: Count object properties
  • has: Check property existence
  • get: Retrieve nested property values
  • set: Assign nested property values
  • keys: Get object property names
  • pick: Create subset object
  • omit: Create object excluding properties
  • extend: Merge object properties
  • forIn: Iterate enumerable properties
  • deepCopy: Clone complex structures
  • isEmpty: Test for empty containers
  • isDeepEqual: Compare nested structures

Mathematical Utilities

  • random: Generate bounded random numbers
  • gid: Create random identifier strings
  • gcolor: Produce random color codes

Temporal Functions

  • interval: Configure recurring timers
  • timeout: Set delayed execution
  • defer: Postpone function invocation
  • time/timestamp: Get current epoch time
  • asUtcTime: Convert to UTC timestamp
  • asXyzTime: Apply timezone offset
  • fmtDate: Format localized dates
  • fmtUtcDate: Format UTC dates
  • fmtXyzDate: Format timezone-adjusted dates

String Handling

  • match: Pattern-based string search
  • pretty: Format structured output
  • escape: Encode HTML enttiies
  • unescape: Decode HTML entities
  • capitalize: Normalize capitalization
  • fmtCurrency: Format monetary values
  • maskString: Obscure sensitive substrings
  • cutString: Truncate with ellipsis
  • parseQueryStr: Decode URL parameters
  • stringifyQueryStr: Encode parameters to URL string

Regex Toolkit

  • setPattern: Define custom expressions
  • getPattern: Access predefined patterns
  • testPattern: Validate against paterns
  • matchPattern: Extract pattern matches

Function Enhancements

  • rest: Capture trailing arguments
  • throttle: Limit invocation frequency
  • debounce: 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 fullscreen
  • exitFullScreen: Disable fullscreen mode
  • checkIsFullScreen: Verify fullscreen state
  • fullScreenChange: Monitor fullscreen changes

File Operations (Server)

  • rd: Read file contents
  • wt: Write file contents
  • cp: Duplicate files/directories
  • mv: Relocate files/directories
  • rm: Delete files/directories
  • mk: Create directory structure
  • size: Determine file dimensions
  • clear: Reset console display
  • copyText: Transfer text to clipboard (client)

Progress Indicators (Server)

  • progress: Visualize operation advancement
  • progress.stop: Terminate visualization

Advanced Features

  • chain: Enable method chaining
  • noConflict: Resolve namespace collisions
  • version: Retrieve library version

Tags: javascript utility library funclib frontend mini-program

Posted on Tue, 20 Oct 2026 16:55:25 +0000 by azaidi