Vector-ts, a Python List -like data structure for Typescript / JavaScript.

(C) Serge Hulne.

Goal

The aim of the npm package vector-ts is twofold:

  1. It aims at providing a data structure for Typescript and JavaScript which emulates a Python List, in which one can: add elements, delete them, append, prepend, insert, … them by value as well as by index.
  2. It provide a convenience class (which is a wrapper around the Array class) whose goal is to make operations on Arrays safer and more expressive / readable than with the Array.splice method (which is not very intuitive).

Where can I get It?

How can I use it?

It can be installed from npm with the command:

npm i vector-ts

Examples of use:

import {Vector} from “vector-ts”let v = new Vector<string>()v.append("A");v.append("B");v.append("C");console.log(v.a);

returns:

[ 'A', 'B', 'C' ]

Further:

v.delete("B");console.log(v.a);

returns:

[ ‘A’, ‘C’ ]

Further:

let t = new Vector<string>();
let u = new Vector<string>();
t.append(“A”);t.append(“B”);t.append(“C”);u.append(“X”);u.append(“Y”);u.append(“Z”);let s = t.concat(u);console.log(s);

returns:

[ 'A', 'B', 'C', 'X', 'Y', 'Z' ]

The list of available operations / methods is:

constructorappendclearconcatdeletedeleteAtdeleteAtEnddeleteAtStartforEachfromArraygetValueincludesinsertAtinsertAtEndinsertAtStartlengthprependsetValuesortsubstitutesubstituteAtswapAt

https://serge-hulne.github.io/vector-ts-js/classes/vector.html

A list of examples is available at:

https://github.com/serge-hulne/vector-ts-js/blob/main/vector_test.ts

Bugs (or missing features or feedback) can be reported here:

https://github.com/serge-hulne/vector-ts-js/issues

Happy coding!

--

--

--

Author, scientist (Physics PhD), philosophy, Sci-Fi, thrillers, humor, blues and Irish music, green energy, origins of consciousness.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Internet, Web and terms around them!!

Udemy- Python for Time Series Data Analysis Course Review

#8 Fun Python — File Operation that look like Database

How to deploy Qitmeer Network at Home

I̶n̶s̶t̶a̶l̶l̶i̶n̶g̶ Forcing NVIDIA Drivers to work with Ubuntu (14.04 and up) EFI Boot

Docker under the Hood — User space, Kernel, Syscalls, Permissions, setuid, setgid, and Capabilities

Custom Bezier Curve Tool for HTML Canvas, pt. 2

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Serge Hulne

Serge Hulne

Author, scientist (Physics PhD), philosophy, Sci-Fi, thrillers, humor, blues and Irish music, green energy, origins of consciousness.

More from Medium

Automating Front-End Performance Tests

How to Create a Linked List in JavaScript

Data Structures in JavaScript: Singly Linked Lists

Deep dive into Array.prototype.sort()