Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stringjs

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

stringjs

A library that helps manipulate strings in JavaScript, from uppercase to lowercase, via useful features

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17
decreased by-10.53%
Maintainers
1
Weekly downloads
 
Created
Source

StringJs

StringJs is a library that introduces useful and easy functions to manipulate strings in JavaScript

 

example workflow codecov dependencies devdependencies

 

Features

  • import this package in your project
  • choose a string and the right function in this library
  • now you have your formatted string!

 

Installation

npm install --save stringjs

or

yarn add stringjs

 

How To Import and Use

const stringjs = require('stringjs')

or

import stringjs from 'stringjs'

 

After this import you can use any function provided in the section below with this call structure

stringjs.capitalizeFirst()

 

Functions and Methods

MethodInputOutput
capitalizeFirsta stringThe string with the first letter capitalized
capitalizeLasta stringThe string with the last letter capitalized
capitalizeByIndexa string and a parameter of type number, array or functionThe string with the letter in the index provided (zero-based) capitalized.
  • In case the provided second parameter is an array of integers, the string is capitalized in all the index positions
  • In case the provided second parameter is a function, the function is used to test if the index matches the boolean condition of the function and then makes that character in uppercase
If the index is greater then the string's length, returns the string as provided
capitalizeByLettera string and a parameter of type number, array or functionConverts in uppercase all the occurencies of the letter provided
  • In case the provided second parameter is an array of characters, all the letters included in the array are converted in uppercase
  • In case the provided second parameter is a function, the function is used to test if the letter matches the boolean condition of the function and then makes that characters in uppercase
deCapitalizeFirsta stringThe string with the first letter decapitalized
deCapitalizeLasta stringThe string with the last letter decapitalized
deCapitalizeByIndexa string and a parameter of type number, array or functionThe string with the letter in the index provided (zero-based) capitalized.
  • In case the provided second parameter is an array of integers, the string is decapitalized in all the index positions
  • In case the provided second parameter is a function, the function is used to test if the index matches the boolean condition of the function and then makes that character in lowercase
If the index is greater then the string's length, returns the string as provided
deCapitalizeByLettera string and a parameter of type number, array or functionConverts in lowercase all the occurencies of the letter provided
  • In case the provided second parameter is an array of characters, all the letters included in the array are converted in lowercase
  • In case the provided second parameter is a function, the function is used to test if the letter matches the boolean condition of the function and then makes that characters in lowercase

 

Working Examples

capitalizeFirst

stringjs.capitalizeFirst('my cool string')

// OUTPUT: My cool string

capitalizeLast

stringjs.capitalizeLast('my cool string')

// OUTPUT: my cool strinG

capitalizeByIndex

stringjs.capitalizeByIndex('my cool string', 3)

// OUTPUT: my Cool string



stringjs.capitalizeByIndex('my cool string', 50)

// OUTPUT: my cool string



stringjs.capitalizeByIndex('my cool string', [0, 1, 5, 20, 6, 13])

// OUTPUT: MY coOL strinG



stringjs.capitalizeByIndex('my cool string', (i) => { return i === 3 || i === 5 })

// OUTPUT: my CoOl string

capitalizeByLetter

stringjs.capitalizeByLetter('test', 't')

// OUTPUT: TesT



stringjs.capitalizeByLetter('test', ['t', 'e'])

// OUTPUT: TEsT



stringjs.capitalizeByLetter('test', (l) => { return l === 'e' || l === 's' })

// OUTPUT: tESt

deCapitalizeFirst

stringjs.deCapitalizeFirst('TEST')

// OUTPUT: tEST

deCapitalizeLast

stringjs.deCapitalizeLast('TEST')

// OUTPUT: TESt

deCapitalizeByIndex

stringjs.deCapitalizeByIndex('MY COOL STRING', 3)

// OUTPUT: MY cOOL STRING



stringjs.deCapitalizeByIndex('MY COOL STRING', 50)

// OUTPUT: MY COOL STRING



stringjs.deCapitalizeByIndex('MY COOL STRING', [0, 1, 5, 20, 6, 13])

// OUTPUT: my COol STRINg



stringjs.deCapitalizeByIndex('MY COOL STRING', (i) => { return i === 3 || i === 5 })

// OUTPUT: MY cOoL STRING

deCapitalizeByLetter

stringjs.deCapitalizeByLetter('TEST', 'T')

// OUTPUT: tESt



stringjs.deCapitalizeByLetter('TEST', ['T', 'E'])

// OUTPUT: teSt



stringjs.deCapitalizeByLetter('TEST', (l) => { return l === 'E' || l === 'S' })

// OUTPUT: TesT

 

License

MIT

Keywords

FAQs

Package last updated on 16 Mar 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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc