The Wayback Machine - https://web.archive.org/web/20200910162636/https://github.com/hustcc/slice.js
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

slice.js

Nano version for slice of string and array, just like Python.

Build Status Coverage Status npm npm npm

1. Install

npm install slice.js

var slice = require('slice.js');

//or

import slice from 'slice.js';

2. Usage

There is only one API named slice.

// for array
const arr = slice([1, '2', 3, '4', 5, '6', 7, '8', 9, '0']);

arr[-2];  		// 9
arr['2:5'];  		// [3, '4', 5]
arr[':-2'];  		// [1, '2', 3, '4', 5, '6', 7, '8']
arr['-2:'];  		// [9, '0']
arr['1:5:2'];  		// ['2', '4']
arr['5:1:-2'];  	// ['6', '4']

// for string
const str = slice('1234567890');

str[-2];  		// '9'
str['2:5'];  		// '345'
str[':-2'];  		// '12345678'
str['-2:'];  		// '90'
str['1:5:2'];  		// '24'
str['5:1:-2'];  	// '64'

3. Test

npm install

npm run test

LICENSE

MIT@hustcc.

About

🌌 nano library to enhance String.substring / Array.slice with python slice style by Proxy.

Topics

Resources

License

Packages

No packages published
You can’t perform that action at this time.