Socket
Book a DemoInstallSign in
Socket

string-features

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-features

Common things you need while working with strings

0.11.2
latest
Source
npmnpm
Version published
Weekly downloads
10
100%
Maintainers
1
Weekly downloads
 
Created
Source

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

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

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

  • 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

Keywords

strings

FAQs

Package last updated on 26 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.