🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

pyarray

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pyarray

A node module for manipulating arrays just like how you would in Python!

1.2.1
latest
Source
npm
Version published
Maintainers
1
Created
Source

pyarray logo
pyarray

A node module for manipulating arrays just like how you would in Python!



Build Status

Install

NPM

Features

  • Supports all native javascript array methods, such as push, indexOf etc.
  • Supports native Python list methods too!
  • Not only that, but you can also use index ranges and negative indexes, no more array[array.length-1]

Methods

For detailed information about pyarray's method behaviour visit Python's official docs. Even the errors are the same!

Python methodSupported?Note
list.append(x)YesIdentical to Array.prototype.push
list.extend(L)Yes
list.insert(i, x)Yes
list.remove(x)Yes
list.pop([i])YesRenamed to pypop to avoid conflict with Array.prototype.pop
list.index(x)Yes
list.count(x)Yes
list.reverse()YesIdentical to Array.prototype.reverse
list.sort()No

Examples

import pyarray from 'pyarray'

Creating a pyarray

let fruits = pyarray(['Banana', 'Apple', 'Orange', 'Plum', 'Grape'])

Accessing elements

PythonpyarrayResult
fruitsfruits.get()['Banana', 'Apple', 'Orange', 'Plum', 'Grape']
fruits[0]fruits[0]'Banana'
fruits[-1]fruits[-1]'Grape'
fruits[0:-2]fruits['0:-2']['Banana', 'Apple', 'Orange']
fruits[0:-1:2]fruits['0:-1:2']['Banana', 'Orange']
fruits[::-1]fruits['::-1']['Grape', 'Plum', 'Orange', 'Apple', 'Banana']
You can also use the .get() method as a fallback, the syntax is
obj.get(start, end, step)

Testing

  • Install dependencies $ npm install

  • Run tests $ npm run test

  • View coverage

$ istanbul cover node_modules\mocha\bin\_mocha -- dist/tests
$ open coverage/lcov-report/index.html

Keywords

python

FAQs

Package last updated on 08 Sep 2016

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