string-features

0.11.2 • Public • Published

String features

npm version npm npm GitHub Release Date Maintenance

String-features or simptly str as the name suggests is having all the features that you will normally require while working with strings.
The cleaner and readable the code the better, with this motive i've created this package which is open for changes.
If you want to make any cahnges just make the changes and update README. I'll update everything and add the name to contributers list.

Installation

  1. If you want to use this library, you first need to install the Node.js.

  2. When you install node.js, will also be installed npm.

  3. Please run the following command.

npm install --save string-features

Usage

var str = require('string-features');

Examples

Following are few examples, by all means this is not an exaustive list and you can do much more with many methods available for your use.

str.dashCase("fooBar") // foo-bar

str.underscoreCase("BatteryAAA") // battery_aaa

str.underscoreCase("coldWind") //cold_wind

str.removeHTMLTags("<html> <body> Javascript<body> is not Java") // Javascript is not Java

str.removeSpecialCharacters("coding$%-is%& fun", true) // codingisfun

str.reverse("Hello world") // dlrow olleH

str.isEmpty("   ") //true

str.isUpperCase("Hello") //false

str.isUpperCase("HELLO") //true

str.removeExtraSpaces("     wrong   spacing       here ")) // wrong spacing here

str.count('abcabc', 'abc') // 2 

Methods

  • titleCase

Converts string to title case.
First letter of every word is capital rest all are lower case

str.titleCase("title case") // Title Case
str.titleCase("TItle cAse") // Title Case
  • toCamelCase

Converts string to camel case

str.toCamelCase("coding-is-fun")      // codingIsFun
str.toCamelCase("coding is fun")      // codingIsFun
str.toCamelCase("coding$% is%& fun")  // codingIsFun
  • removeSpecialCharacters

Removes special characters from string.
You can also choose to remove spaces from the string by passsing second param as true default is false.

str.removeSpecialCharacters("coding$%-is%& fun", true)  // codingisfun
str.removeSpecialCharacters("coding$%-is%& fun", false) // codingis fun
  • reverse
    Reverse the input string.
str.reverse("Coding") // gnidoC
  • isEmpty
    Return true if the string is made up of whitespace or is null/undefined.
str.isEmpty("   ") //true
str.isEmpty(null)  //true
  • isUpperCase
    Return true if the string is made up of all capital letters.

  • isLowerCase
    Return true if the string is made up of all lower letters.

  • isNumeric
    Return true if the string is made up of all numbers.

isNaN(123)         // false
isNaN('123')       // false
isNaN('1e10000')   // false (This translates to Infinity, which is a number)
isNaN('foo')       // true
isNaN('10px')      // true
  • removeExtraSpaces Removes extra spaced from string.
str.removeExtraSpaces(" this contains   spaces ")) // this contains spaces
  • contains
    Check if string contains a substring.
str.contains("coding is fun", fun) // true
  • count
    Returns count of sub string in string.
str.count('abcabc', 'abc')      // 2 
str.count("this is ice", "is")  // 2
  • dashCase
    Converts string to dashed string.
str.dashCase("fooBar")  // foo-bar
str.dashCase("FooBar")  // -foo-bar
  • removeHTMLTags
    Removed all HTML tags from a string.
str.removeHTMLTags("<html> <body> Javascript<body> is not Java") // Javascript is not Java 
  • underscoreCase
    Convert the input string to underscore case
 str.underscoreCase(BatteryAAA) // battery_aaa
 str.underscoreCase(coldWind)   // cold_wind
  • endsWith
    Check if input string ends with given substring
 str.endsWith("Hello World", "World") // True
 str.endsWith("Hello#", "#")   // True
 str.endsWith("This is a test", "test") // True
 str.endsWith("This is a test", "st") // True

Package Sidebar

Install

npm i string-features

Weekly Downloads

5

Version

0.11.2

License

MIT

Unpacked Size

11.3 kB

Total Files

4

Last publish

Collaborators

  • riteshchauhan25696