1.2.0 • Published 6 months ago
@samlevy/string-helpers v1.2.0
String Helpers
Some basic JavaScript string helpers, loosely based on some of Laravel's string helpers.
Installation
Install from NPM:
npm install @samlevy/string-helpersUsage
You can import the entire module to access the helpers:
import Str from "@samlevy/string-helpers";
Str.camel('Foo Bar'); // 'fooBar'
Str.camel('foo/bar.baz'); // 'fooBarBaz'
Str.camel('foo bar'); // 'fooBar'
Str.headline('foo bar'); // 'Foo Bar'
Str.headline('foo/bar.baz'); // 'Foo Bar Baz'
Str.headline('fooBarBaz'); // 'Foo Bar Baz'
Str.snake('Foo Bar'); // 'foo_bar'
Str.snake('fooBarBaz'); // 'foo_bar_baz'
Str.snake('foo/bar.baz'); // 'foo_bar_baz'
Str.studly('Foo Bar'); // 'FooBar'
Str.studly('foo/bar.baz'); // 'FooBarBaz'
Str.studly('foo bar'); // 'FooBar'Or you can import individual helpers:
import { camel, random, squish } from "@samlevy/string-helpers";
camel('Foo Bar'); // 'fooBar'
camel('foo/bar.baz'); // 'fooBarBaz'
camel('foo bar'); // 'fooBar'
random(); // 'a1b2C3D4e5F6g7H8'
random(10); // 'a1b2C3D4e5'
squish('foo bar'); // 'foo bar'
squish(' foo bar '); // 'foo bar'
squish(" \n\n foo\nbar \n\n\n "); // 'foo bar'Testing
You can run the tests and linters through npm run or through npx:
# Tests
npm run test
npx jest
# Biome linting
npm run biome
npx biome check
# ESLint linting
npm run eslint
npx eslint
# OXLint linting
npm run oxlint
npx oxlintContributing
Contributions via PR are welcome, either as complete changes (including tests), or as failing test cases.