1.0.5 • Published 8 years ago

phosphor-queue v1.0.5

Weekly downloads
22
License
BSD-3-Clause
Repository
github
Last release
8 years ago

phosphor-queue

Build Status Coverage Status

A generic FIFO queue data structure.

API Docs

Package Install

Prerequisites

npm install --save phosphor-queue

Source Build

Prerequisites

git clone https://github.com/phosphorjs/phosphor-queue.git
cd phosphor-queue
npm install

Rebuild

npm run clean
npm run build

Run Tests

Follow the source build instructions first.

npm test

Build Docs

Follow the source build instructions first.

npm run docs

Navigate to docs/index.html.

Supported Runtimes

The runtime versions which are currently known to work are listed below. Earlier versions may also work, but come with no guarantees.

  • Node 0.12.7+
  • IE 11+
  • Firefox 32+
  • Chrome 38+

Bundle for the Browser

Follow the package install instructions first.

npm install --save-dev browserify
browserify myapp.js -o mybundle.js

Usage Examples

Note: This module is fully compatible with Node/Babel/ES6/ES5. Simply omit the type declarations when using a language other than TypeScript.

import { Queue } from 'phosphor-queue';


let q = new Queue<number>([0, 1, 2, 3]);

q.front;  // 0
q.back;   // 3
q.size;   // 4
q.empty;  // false

q.pop();  // 0
q.pop();  // 1
q.pop();  // 2
q.pop();  // 3
q.pop();  // undefined
q.front;  // undefined
q.back;   // undefined
q.size;   // 0
q.empty;  // true

q.push(42);
q.push(43);
q.push(44);
q.push(44);
q.push(45);

q.toArray();  // [42, 43, 44, 44, 45]

q.remove(42);     // true
q.remove(19);     // false
q.removeAll(44);  // 2
q.removeAll(19);  // 0
q.toArray();      // [43, 45]

q.clear();
q.size;     // 0
q.empty;    // true

q.push(42);
q.push(43);
q.push(44);
q.push(45);

q.some(v => v < 40);  // false
q.some(v => v > 44);  // true

q.every(v => v > 40);  // true
q.every(v => v > 44);  // false

q.filter(v => v < 40);  // []
q.filter(v => v > 44);  // [45]

q.map(v => v * 2);  // [84, 86, 88, 90]

q.forEach((v, i) => {
  console.log(v, i);
});

let index = q.forEach((v, i) => {
  if (v === 43) return i;
});

index;  // 1
1.0.5

8 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.9.6

9 years ago

0.9.5

9 years ago

0.9.4

9 years ago

0.9.3

9 years ago

0.9.2

9 years ago

0.9.1

9 years ago

0.9.0

9 years ago