Functions for working with strings and text. These utilities provide comprehensive string manipulation, formatting, and transformation capabilities.
| Function | Description | Parameters | Returns |
|---|---|---|---|
camelCase |
Converts to camelCase | string |
camelCase string |
kebabCase |
Converts to kebab-case | string |
kebab-case string |
snakeCase |
Converts to snake_case | string |
snake_case string |
startCase |
Converts to Start Case | string |
Start Case string |
capitalize |
Capitalizes first letter | string |
Capitalized string |
upperFirst |
Uppercases first letter | string |
Modified string |
lowerFirst |
Lowercases first letter | string |
Modified string |
lowerCase |
Converts to lowercase | string |
Lowercase string |
upperCase |
Converts to UPPERCASE | string |
Uppercase string |
truncate |
Truncates string | string, options? |
Truncated string |
pad |
Pads string | string, length?, chars? |
Padded string |
words |
Splits into words | string, pattern? |
Array of words |
deburr |
Removes diacritical marks | string |
Deburred string |
escape |
Escapes HTML entities | string |
Escaped string |
escapeRegExp |
Escapes RegExp special chars | string |
Escaped string |
unescape |
Unescapes HTML entities | string |
Unescaped string |
template |
Creates template function | string, options? |
Template function |
Converts string to camel case.
import { camelCase } from 'highdash';
console.log(camelCase('--foo-bar--')); // 'fooBar'
console.log(camelCase('fooBar')); // 'fooBar'
console.log(camelCase('__FOO_BAR__')); // 'fooBar'
console.log(camelCase('foo bar')); // 'fooBar'
console.log(camelCase('foo-bar-baz')); // 'fooBarBaz'
// Real-world examples
console.log(camelCase('user-name')); // 'userName'
console.log(camelCase('first-name')); // 'firstName'
console.log(camelCase('last-name')); // 'lastName'Converts string to kebab case.
import { kebabCase } from 'highdash';
console.log(kebabCase('Foo Bar')); // 'foo-bar'
console.log(kebabCase('fooBar')); // 'foo-bar'
console.log(kebabCase('__FOO_BAR__')); // 'foo-bar'
console.log(kebabCase('foo_bar')); // 'foo-bar'
// Real-world examples
console.log(kebabCase('userName')); // 'user-name'
console.log(kebabCase('firstName')); // 'first-name'
console.log(kebabCase('lastName')); // 'last-name'Converts string to snake case.
import { snakeCase } from 'highdash';
console.log(snakeCase('Foo Bar')); // 'foo_bar'
console.log(snakeCase('fooBar')); // 'foo_bar'
console.log(snakeCase('--FOO-BAR--')); // 'foo_bar'
console.log(snakeCase('foo-bar')); // 'foo_bar'
// Real-world examples
console.log(snakeCase('userName')); // 'user_name'
console.log(snakeCase('firstName')); // 'first_name'
console.log(snakeCase('lastName')); // 'last_name'Converts string to start case.
import { startCase } from 'highdash';
console.log(startCase('--foo-bar--')); // 'Foo Bar'
console.log(startCase('fooBar')); // 'Foo Bar'
console.log(startCase('__FOO_BAR__')); // 'Foo Bar'
console.log(startCase('foo_bar')); // 'Foo Bar'
// Real-world examples
console.log(startCase('userName')); // 'User Name'
console.log(startCase('firstName')); // 'First Name'
console.log(startCase('lastName')); // 'Last Name'Converts the first character of string to upper case and the remaining to lower case.
import { capitalize } from 'highdash';
console.log(capitalize('FRED')); // 'Fred'
console.log(capitalize('fred')); // 'Fred'
console.log(capitalize('FRED')); // 'Fred'
console.log(capitalize('')); // ''
// Real-world examples
console.log(capitalize('hello world')); // 'Hello world'
console.log(capitalize('JOHN DOE')); // 'John doe'Converts the first character of string to upper case.
import { upperFirst } from 'highdash';
console.log(upperFirst('fred')); // 'Fred'
console.log(upperFirst('FRED')); // 'FRED'
console.log(upperFirst('')); // ''
// Real-world examples
console.log(upperFirst('hello world')); // 'Hello world'
console.log(upperFirst('john doe')); // 'John doe'Converts the first character of string to lower case.
import { lowerFirst } from 'highdash';
console.log(lowerFirst('Fred')); // 'fred'
console.log(lowerFirst('FRED')); // 'fRED'
console.log(lowerFirst('')); // ''
// Real-world examples
console.log(lowerFirst('Hello World')); // 'hello World'
console.log(lowerFirst('JOHN DOE')); // 'jOHN DOE'Converts string to lower case.
import { lowerCase } from 'highdash';
console.log(lowerCase('--Foo-Bar--')); // 'foo bar'
console.log(lowerCase('fooBar')); // 'foo bar'
console.log(lowerCase('__FOO_BAR__')); // 'foo bar'
// Real-world examples
console.log(lowerCase('Hello World')); // 'hello world'
console.log(lowerCase('JOHN DOE')); // 'john doe'Converts string to upper case.
import { upperCase } from 'highdash';
console.log(upperCase('--foo-bar--')); // 'FOO BAR'
console.log(upperCase('fooBar')); // 'FOO BAR'
console.log(upperCase('__foo_bar__')); // 'FOO BAR'
// Real-world examples
console.log(upperCase('hello world')); // 'HELLO WORLD'
console.log(upperCase('john doe')); // 'JOHN DOE'Truncates string if it's longer than the given maximum string length. The last characters of the truncated string are replaced with the omission string.
import { truncate } from 'highdash';
console.log(truncate('hi-diddly-ho there, neighborino'));
// => 'hi-diddly-ho there, neighbo...'
console.log(truncate('hi-diddly-ho there, neighborino', { length: 24, separator: ' ' }));
// => 'hi-diddly-ho there,...'
console.log(truncate('hi-diddly-ho there, neighborino', {
length: 24,
omission: ' [...]'
}));
// => 'hi-diddly-ho there, ne [...]'
// Real-world examples
const longText = 'This is a very long text that needs to be truncated for display purposes';
console.log(truncate(longText, { length: 50 }));
// => 'This is a very long text that needs to be trun...'
console.log(truncate(longText, { length: 50, separator: ' ' }));
// => 'This is a very long text that needs to be...'Pads string on the left and right sides if it's shorter than length. Padding characters are truncated if they can't be evenly divided by the padding length.
import { pad } from 'highdash';
console.log(pad('abc', 8)); // ' abc '
console.log(pad('abc', 8, '_-')); // '_-abc_-_'
console.log(pad('abc', 3)); // 'abc'
// Real-world examples
console.log(pad('123', 6, '0')); // '000123'
console.log(pad('hello', 10, ' ')); // ' hello 'Splits string into an array of its words.
import { words } from 'highdash';
console.log(words('fred, barney, & pebbles')); // ['fred', 'barney', 'pebbles']
console.log(words('fred, barney, & pebbles', /[^, ]+/g)); // ['fred', 'barney', '&', 'pebbles']
// Real-world examples
console.log(words('hello world')); // ['hello', 'world']
console.log(words('camelCase')); // ['camel', 'Case']
console.log(words('snake_case')); // ['snake', 'case']Deburrs string by converting Latin-1 Supplement and Latin Extended-A letters to basic Latin letters and removing combining diacritical marks.
import { deburr } from 'highdash';
console.log(deburr('déjà vu')); // 'deja vu'
console.log(deburr('café')); // 'cafe'
console.log(deburr('naïve')); // 'naive'
// Real-world examples
console.log(deburr('résumé')); // 'resume'
console.log(deburr('piñata')); // 'pinata'
console.log(deburr('jalapeño')); // 'jalapeno'Converts the characters &, <, >, ", and ' in string to their corresponding HTML entities.
import { escape } from 'highdash';
console.log(escape('fred, barney, & pebbles')); // 'fred, barney, & pebbles'
console.log(escape('<div>Hello & "World"</div>')); // '<div>Hello & "World"</div>'
// Real-world examples
console.log(escape('Tom & Jerry')); // 'Tom & Jerry'
console.log(escape('He said "Hello"')); // 'He said "Hello"'
console.log(escape('<script>alert("xss")</script>')); // '<script>alert("xss")</script>'Escapes the RegExp special characters in string.
import { escapeRegExp } from 'highdash';
console.log(escapeRegExp('[lodash](https://lodash.com/)')); // '\\[lodash\\]\\(https://lodash\\.com/\\)'
// Real-world examples
console.log(escapeRegExp('hello.world')); // 'hello\\.world'
console.log(escapeRegExp('test*string')); // 'test\\*string'
console.log(escapeRegExp('(test)')); // '\\(test\\)'Converts the HTML entities &, <, >, ", and ' in string to their corresponding characters.
import { unescape } from 'highdash';
console.log(unescape('fred, barney, & pebbles')); // 'fred, barney, & pebbles'
console.log(unescape('<div>Hello & "World"</div>')); // '<div>Hello & "World"</div>'
// Real-world examples
console.log(unescape('Tom & Jerry')); // 'Tom & Jerry'
console.log(unescape('He said "Hello"')); // 'He said "Hello"'
console.log(unescape('<script>alert("xss")</script>')); // '<script>alert("xss")</script>'Creates a compiled template function that can interpolate data properties in "interpolate" delimiters, HTML-escape interpolated data properties in "escape" delimiters, and execute JavaScript in "evaluate" delimiters.
import { template } from 'highdash';
// Basic interpolation
const compiled = template('hello <%= user %>!');
console.log(compiled({ 'user': 'fred' })); // 'hello fred!'
// HTML escaping
const compiled2 = template('<%= a %> & <%= b %>');
console.log(compiled2({ 'a': '1', 'b': '2' })); // '1 & 2'
// JavaScript evaluation
const compiled3 = template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
console.log(compiled3({ 'users': ['fred', 'barney'] })); // '<li>fred</li><li>barney</li>'
// Real-world examples
const userTemplate = template(`
<div class="user">
<h2><%= name %></h2>
<p>Email: <%= email %></p>
<p>Age: <%= age %></p>
</div>
`);
const userData = {
name: 'John Doe',
email: 'john@example.com',
age: 30
};
console.log(userTemplate(userData));
// => <div class="user">
// <h2>John Doe</h2>
// <p>Email: john@example.com</p>
// <p>Age: 30</p>
// </div>// Import specific functions
import { camelCase, capitalize, truncate } from 'highdash';
// Import from specific module (better tree-shaking)
import { camelCase } from 'highdash/string/camelCase.js';
import { capitalize } from 'highdash/string/capitalize.js';
import { truncate } from 'highdash/string/truncate.js';
// Import all string functions
import * as string from 'highdash/string';- Case conversion: Optimized regex patterns for efficient conversion
- String manipulation: Uses native string methods where possible
- Memory usage: Minimal memory overhead for string operations
- Type safety: Full TypeScript support with proper type inference
- Case conversion: Use
camelCase,kebabCase,snakeCasefor naming conventions - Text formatting: Use
capitalize,upperFirst,lowerFirstfor text display - Text truncation: Use
truncatefor UI text limits - String processing: Use
deburr,escape,unescapefor text cleaning - Template rendering: Use
templatefor dynamic string generation - Word extraction: Use
wordsfor text analysis - String padding: Use
padfor formatting and alignment