CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lodash-trim

The lodash method _.trim exported as a module for removing leading and trailing whitespace or specified characters from strings.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

lodash.trim

lodash.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.

Package Information

  • Package Name: lodash.trim
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install lodash.trim

Core Imports

var trim = require('lodash.trim');

ESM (ES modules):

import trim from 'lodash.trim';

Basic Usage

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']

Capabilities

String Trimming

Removes leading and trailing whitespace or specified characters from strings.

function trim(string, chars, guard);

Parameters:

  • string (string, optional, default: '') - The string to trim
  • chars (string, optional, default: whitespace) - The characters to trim from both ends
  • guard (Object, optional) - Internal parameter that enables use as a callback for functions like _.map

Returns:

  • string - The trimmed string

Usage 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'
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/lodash.trim@3.1.x
Publish Source
CLI
Badge
tessl/npm-lodash-trim badge