New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

js-string-helper

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-string-helper

Helper module for string to provide support for common functions related to string, except javascript built-in objects.

latest
Source
npmnpm
Version
0.1.3
Version published
Weekly downloads
6
500%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

helper functions

FAQs

Package last updated on 15 Nov 2022

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