The lodash method _.trim exported as a module for removing leading and trailing whitespace or specified characters from strings.
npx @tessl/cli install tessl/npm-lodash-trim@3.1.0lodash.trim is a modularized version of the lodash _.trim method, exported as a standalone Node.js module. It removes leading and trailing whitespace or specified characters from strings, providing a focused string manipulation utility without requiring the full lodash library.
npm install lodash.trimvar trim = require('lodash.trim');ESM (ES modules):
import trim from 'lodash.trim';var trim = require('lodash.trim');
// Remove whitespace
var result1 = trim(' hello world ');
// => 'hello world'
// Remove custom characters
var result2 = trim('-_-abc-_-', '_-');
// => 'abc'
// Use as callback for array operations
var cleaned = [' foo ', ' bar '].map(trim);
// => ['foo', 'bar']Removes leading and trailing whitespace or specified characters from strings.
function trim(string, chars, guard);Parameters:
string (string, optional, default: '') - The string to trimchars (string, optional, default: whitespace) - The characters to trim from both endsguard (Object, optional) - Internal parameter that enables use as a callback for functions like _.mapReturns:
string - The trimmed stringUsage Examples:
var trim = require('lodash.trim');
// Basic whitespace trimming
trim(' abc ');
// => 'abc'
// Custom character trimming
trim('-_-abc-_-', '_-');
// => 'abc'
// Use with array map (guard parameter automatically handled)
[' foo ', ' bar '].map(trim);
// => ['foo', 'bar']
// Empty string handling
trim('');
// => ''
// Null/undefined handling
trim();
// => ''
// Multiple whitespace types
trim('\t\n hello world \r\n');
// => 'hello world'