# python-style-slicing

> Python style list slicing for JavaScript arrays.

Latest version **1.0.4** (published 2015-08-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install python-style-slicing
pnpm add python-style-slicing
yarn add python-style-slicing
bun add python-style-slicing
```

Provides the command `pss`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2015-08-26 |
| First published | 2015-08-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Author | Shahmeer Navid |
| Maintainers | shahmeernavid |

## Links

- npm: https://www.npmjs.com/package/python-style-slicing
- npm.io page: https://npm.io/package/python-style-slicing

## Dependencies (6)

- [gulp](https://npm.io/package/gulp.md) ^3.9.0
- [shelljs](https://npm.io/package/shelljs.md) ^0.5.3
- [gulp-util](https://npm.io/package/gulp-util.md) ^3.0.6
- [gulp-babel](https://npm.io/package/gulp-babel.md) ^5.2.1
- [gulp-sourcemaps](https://npm.io/package/gulp-sourcemaps.md) ^1.5.2
- [source-map-support](https://npm.io/package/source-map-support.md) ^0.3.2

## Recent versions

- 1.0.4 (latest) — 2015-08-26
- 1.0.3 — 2015-08-25
- 1.0.2 — 2015-08-25
- 1.0.1 — 2015-08-25
- 1.0.0 — 2015-08-25

## README

# PythonStyleListSlice
Python like list slicing in javascript. Transpiles JavaScript to allow for `arr[1:2]`, `arr[::2]`, `arr[-1]`, `arr[-1] = 5`, etc...

# Installation
`npm -g install python-style-slicing`

# Node API

#### PSS::transpile(code, filename='dummy.js', sourceMap=false)
- `code`: the code to transpile
- `filename`: original file code came from. Used in creation of sourcemaps. Defaults to `'dummy.js'`
- `sourceMap`: boolean indicating whether or not to generate source maps. Defaults to `false`


##### Example usage

```
import PSS from 'python-style-slicing';

const code = ['var x = [1, 2, 3, 4, 5];', 'console.log(x[::2]);'].join('\n');

const output = PSS.transpile(code, 'test.js', true);
```

# CLI
`pss [file] [--s] [-o output_location]`

If no file given, `pss` will read from `stdin`. If no output location given, `pss` will output to `stdout`. The `--s` flag option indicates whether or not to generate source maps along with output.

# How It Works
Uses a modified version of the [acorn](https://github.com/marijnh/acorn) parser to generate an AST with the following new nodes:
```
ComputedMemberRangeExpression: {
    startExpression: Expression,
    endExpression: Expression,
    skipExpression: Expression
},
ComputedMemberAssignmentExpression: <The same as an AssignmentExpression>
```

A modified version of the [escodegen](https://github.com/estools/escodegen) code generator then generates code.
```
ComputedMemberRangeExpression ->
    __$$__computedMemberRangeGet__$$__(array, startExpression, endExpression, skipExpression)
ComputedMemberAssignmentExpression ->
    __$$__computedMemberSet__$$__(array, property, value, operator)
ComputedMember ->
    __$$__ComputedMemberGet__$$__(array, property)
```
# License

MIT

---
_Source: https://npm.io/package/python-style-slicing · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
