New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

get-substring-by-range

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-substring-by-range

A simple function to get a (sometimes circular) chunk of a string. Takes in 0-based start and end params.

1.0.0
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

#getSubstringByRange

A simple function to get a (sometimes circular) chunk of a string. Takes in 0-based start and end params.

#Useage:

npm install get-substring-by-range
var getSubstringByRange = require('get-substring-by-range')
getSubstringByRange("0123456789",{start: 4, end: 5}) //grab the 4th and 5th chars of the string
//"45"
getSubstringByRange("0123456789",{start: 7, end: 2}) //grab from the 7th char and wrap around the end to the 2nd char
//"012789"

#How it works:

function getSubstringByRange (string, rangeToCopy) {
	if (rangeToCopy.start > rangeToCopy.end) {
		return string.slice(0, rangeToCopy.end + 1) + string.slice(rangeToCopy.start, string.length)
	} else {
		return string.slice(rangeToCopy.start,rangeToCopy.end+1)
	}
}

Keywords

string

FAQs

Package last updated on 03 Jul 2015

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