https://github.com/hustcc/slice.js
:milky_way: nano library to enhance String.substring / Array.slice with python slice style by Proxy.
https://github.com/hustcc/slice.js
array python slice string
Last synced: about 1 month ago
JSON representation
:milky_way: nano library to enhance String.substring / Array.slice with python slice style by Proxy.
- Host: GitHub
- URL: https://github.com/hustcc/slice.js
- Owner: hustcc
- License: mit
- Created: 2016-07-27T04:26:52.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-10T13:15:56.000Z (about 7 years ago)
- Last Synced: 2025-03-17T07:51:25.961Z (about 1 month ago)
- Topics: array, python, slice, string
- Language: JavaScript
- Homepage: https://git.hust.cc/slice.js
- Size: 23.4 KB
- Stars: 34
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# slice.js
> Nano version for slice of string and array, just like Python.
[](https://travis-ci.org/hustcc/slice.js) [](https://coveralls.io/github/hustcc/slice.js?branch=master) [](https://www.npmjs.com/package/slice.js) [](https://www.npmjs.com/package/slice.js) [](https://www.npmjs.com/package/slice.js)
# 1. Install
> **npm install slice.js**
```js
var slice = require('slice.js');//or
import slice from 'slice.js';
```# 2. Usage
There is only one API named `slice`.
```js
// 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](https://github.com/hustcc).