string-library
[School Assignment] JS Library for manipulating strings
What it does
This simple package provides a number of functions that can help you to manipulate strings in your projects, all taking a string as a parameter:
- capitalize(str)
- allCaps(str)
- capitalizeWords(str)
- capitalizeHeadline(str) (does not capitalize the following words: the, in, a, an, and, but, for, of, at, by, from
- removeExtraSpaces(str)
- kebobCase(str)
- snakeCase(str)
- camelCase(str)
- shift(str) (accepts a number as a parameter to shift multiple characters to the end of the string)
- makeHashtag(str) (will return the three longest words in the string, capitalized and hashtagged)
- isEmpty(str)
Installation
npm install @euripidean/string-library
Usage
const stringLibrary = require('@euripidean/string-library');
capitalize
const capitalized = stringLibrary.capitalize("hello world");
console.log(capitalized); // Output: "Hello world"
allCaps
const uppercase = stringLibrary.allCaps("hello world");
console.log(uppercase); // Output: "HELLO WORLD"
capitalizeWords
const wordsCapitalized = stringLibrary.capitalizeWords("hello world");
console.log(wordsCapitalized); // Output: "Hello World"
capitalizeHeadline
const headlineCapitalized = stringLibrary.capitalizeHeadline("a tale of two cities");
console.log(headlineCapitalized); // Output: "A Tale of Two Cities"
removeExtraSpaces
const trimmedString = stringLibrary.removeExtraSpaces(" Hello world! ");
console.log(trimmedString); // Output: "Hello world!"
kebobCase
const kebabCased = stringLibrary.kebobCase("Hello World");
console.log(kebabCased); // Output: "hello-world"
snakeCase
const snakeCased = stringLibrary.snakeCase("Hello World");
console.log(snakeCased); // Output: "hello_world"
camelCase
const camelCased = stringLibrary.camelCase("Hello World");
console.log(camelCased); // Output: "helloWorld"
shift
const shiftedString = stringLibrary.shift("Hello", 2);
console.log(shiftedString); // Output: "lloHe"
makeHashtag
const hashtags = stringLibrary.makeHashTag("This is a sample string");
console.log(hashtags); // Output: ["#Sample", "#String", "#This"]
isEmpty
const emptyCheck = stringLibrary.isEmpty(" ");
console.log(emptyCheck); // Output: true
const emptyCheck = stringLibrary.isEmpty("Oh hey");
console.log(emptyCheck); // Output: false