0.1.3 • Published 1 year ago

js-string-helper v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

js-string-helper

Helper module for string to provide support for common functions related to string, except javascript built-in objects. It's open source and any one is welcome to contribute.

Installation

npm install --save js-string-helper

Usage

import {trim, isEmail, getLinksFromText} from 'js-string-helper'

Method

URL Validation

MethodoutputExplanation
isUrlbooleancheck whether a string is an URL
isImageUrlbooleancheck whether an URL is link of an image
getDomainstringget domain name of the url
hasValidUrlProtocolbooleancheck whether a url has valid url protocol
removeQueryStringbooleanreturn url without query string
getQueryStringobjectreturn object with all the parameter name and parameter value
getLastPathnamebooleanreturn the last pathname of the url

  \ Example:

const exampleUrl = 'https://example.com/img.jpg?param1=1234&param2=5678'

isUrl(exampleUrl)  // true

getDomain(exampleUrl)  // example.com

hasValidUrlProtocol(exampleUrl)  // true

removeQueryString(exampleUrl)  // https://example.com/img.jpg

getQueryString(exampleUrl)  // { 'param1': "1234", 'param2': '5678' }

getLastPathname(exampleUrl)  // img.jpg

isImageUrl(exampleUrl)  // true

 

String Validation

MethodoutputExplanation
isEmailbooleancheck whether a string is email
isPhoneNumberbooleancheck whether a string is phone number of length 10
getLinksFromTextstringextract url from a text
removeSpecialCharacterstringreturn text without any special character
cleanstringsame as removeSpecialCharacter

  \ Example:

isEmail("hello@gmail.com")  // true

isPhoneNumber("01095273239")  // true 

getLinksFromText("dummy text of https://www.lipsum.com/ in the printing")  // https://www.lipsum.com/ 

removeSpecialCharacter("Campum efficitur, , pulcherrimum; #sequimur teneam ullo! ")  // Campum efficitur  pulcherrimum sequimur teneam ullo  asp

Case Styles

MethodoutputExplanation
toTitleCasestringcapitalize first character of each word in a string
toCamelCasestringcapitalize first character of each word (except first word)
toPascalCasestringcapitalize first character of each word
toKebabCasestringreplace space between words with hyphen ( - )
toSnakeCasestringreplace space between words with underscore ( _ )

  Example:

toTitleCase("hello world")  // Hello World

toCamelCase("hello world")  // helloWorld

toPascalCase("hello world")  // HelloWorld

toKebabCase("hello world")  // hello-world

toSnakeCase("hello world")  // hello_world
0.1.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.3

1 year ago

0.0.39

2 years ago

0.0.38

2 years ago

0.0.37

2 years ago

0.0.36

2 years ago

0.0.35

2 years ago

0.0.34

2 years ago

0.0.33

2 years ago

0.0.31

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago