Socket
Socket
Sign inDemoInstall

string-saw

Package Overview
Dependencies
1
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    string-saw

provides an easy way to string together match/replacement operations in an error-free manner


Version published
Weekly downloads
1.2K
increased by6.23%
Maintainers
1
Install size
215 kB
Created
Weekly downloads
 

Readme

Source

string-saw Build Status

provides an easy way to string together match/replacement operations in an error-free manner

String Saw Sandbox

install

npm install string-saw

or

bower install string-saw

or head over to cdnjs

methods

  • match (Array/String/Function/Saw) -> Saw
  • matchAll (RegExp) -> [Array/Object]
  • replace (Array/RegExp/String match, String/Function replacement) -> Saw
  • remove (String/RegExp [match]) -> Saw
  • map (Function func) -> Saw
  • item (Integer index) -> Saw
  • itemFromRight (Integer offset) -> Saw
  • first () -> Saw
  • last () -> Saw
  • trim () -> Saw
  • uniq () -> Saw
  • join (String separator/Function separator) -> Saw
  • each (Function func) -> Saw
  • find(String/RegExp/Function match) -> Saw
  • filter(String/RegExp/Function match) -> Saw
  • filterNot(String/RegExp/Function match) -> Saw
  • reduce (Function func) -> Saw
  • slice (Integer start, Integer end) -> Saw
  • split (String/RegExp match) -> Saw
  • transform (Function context) -> Saw
  • upperCase () -> Saw
  • lowerCase () -> Saw
  • prepend (String) -> Saw
  • append (String) -> Saw
  • capitalize () -> Saw
  • reverse () -> Saw
  • sort (Function func) -> Saw
  • length () -> Integer
  • has (String/RegExp match/Function match) -> Boolean
  • startsWith(String/[String]) -> Boolean
  • endsWith(String/[String]) -> Boolean
  • toString () -> String
  • toArray (returns an array) -> Array
  • toNumber () -> Integer (0 if no match)
  • toInt () -> Integer (can return NaN)
  • toFloat () -> Float
  • toBoolean () -> Boolean
  • toObject () -> Object
  • indexOf (String/RegExp/Function match) -> Integer
  • indexesOf (String/RegExp/Function match) -> [Integer]

examples

var saw = require('string-saw');

saw('one two three four five six hello 323423 hello')
	.remove(/\d+/g, 'hello')
	.split(' ')
	.slice(3,4)
	.toString(); // returns "four"

saw('1 2 3')
	.match(/\d+$/)
	.toNumber(); // returns the number 3

saw('1 2 3')
	.split(' ')
	.last()
	.toNumber(); // returns the number 3

saw('joe:56, bob:57')
	.matchAll(/(?<name>(\S+)):(?<age>(\d+))/g) 
	/* returns 
	[
		{name: 'joe', age: '56'},
		{name: 'bob', age: '57'}
	]
	*/

saw('joe:56, bob:57')
	.matchAll(/(\S+):(\d+)/g) 
	/* returns 
	[
		['joe', '56'],
		['bob', '57']
	]
	*/


saw('1 2 3 4 5')
	.split(' ')
	.itemFromRight(2)
	.toNumber(); // returns the number 3

saw([' one ', ' two ', ' three '])
	.trim()
	.join(',')
	.toString(); // returns "one,two,three"

saw('John. Smith.')
	.match(/\S+/g)
	.remove('.')
	.toObject('first', 'last'); // returns {first: "John", last: "Smith"}

FAQs

Last updated on 25 Jun 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc