eg-string-modification

1.0.4 • Public • Published

EG-string-modify

npm version

EG-string-modify is a collection of string modification utility functions for Node.js.

Link to npm package

https://www.npmjs.com/package/eg-string-modification

Installation

Install the package using npm:

npm install EG-string-modify

Import the package into your project:

const eg = require('eg-string-modify');

Functions

capitalize(string) Capitalizes the first letter of a given string.

const capitalized = eg.capitalize('hello');
console.log(capitalized); // Output: "Hello"

allCaps(string)

Converts the given string to uppercase.

const uppercase = eg.allCaps('hello');
console.log(uppercase); // Output: "HELLO"

capitalizeWords(string)

Capitalizes the first letter of each word in the given string.

const capitalizedWords = eg.capitalizeWords('hello world');
console.log(capitalizedWords); // Output: "Hello World"

capitalizeHeadline(string)

Capitalizes all words in a headline, except specified exception words, unless one of those words is the first word of the string.

const headline = eg.capitalizeHeadline('the greatest hello in the world');
console.log(headline); // Output: "The Greatest Hello in the World

removeExtraSpaces(string)

Removes extra spaces from the beginning and end of the given string, and replaces consecutive spaces with a single space.

const trimmed = eg.removeExtraSpaces('   hello   world   ');
console.log(trimmed); // Output: "hello world"

kebobCase(string)

Converts the given string to kebab case by removing special characters and replacing spaces with hyphens.

const kebabCased = eg.kebabCase('  I am hungry!');
console.log(kebabCased); // Output: "i-am-hungry"

snakeCase(string)

Converts the given string to snake case by removing special characters and replacing spaces with underscores.

const snakeCased = eg.snakeCase('  SSSS! I am a  snake');
console.log(snakeCased); // Output: "ssss_i_am_a_snake"

camelCase(string)

Converts the given string to camel case by removing special characters, capitalizing the first letter of each word (except the first), and removing spaces.

const camelCased = eg.camelCase('  camel sounds! i am a  camel');
console.log(camelCased); // Output: "camelSoundsIAmACamel"

shift(string)

Shifts the characters of the given string one position to the left, with the first character moving to the end.

const shifted = eg.shift('hello');
console.log(shifted); // Output: "elloh"

makeHashTag(string)

Creates an array of hashtags from the words in the given string.

const hashTags = eg.makeHashTag('Hello world javascript');
console.log(hashTags); // Output: ["#Hello", "#world", "#javascript"]

isEmpty(string)

Returns true if the given string is empty or contains only whitespace.

const emptyCheck1 = eg.isEmpty('Abc def');
console.log(emptyCheck1); // Output: false
const emptyCheck2 = eg.isEmpty(`   
			
			`);
console.log(emptyCheck2); // Output: true

Package Sidebar

Install

npm i eg-string-modification

Weekly Downloads

3

Version

1.0.4

License

ISC

Unpacked Size

74.8 kB

Total Files

22

Last publish

Collaborators

  • eg-school