Socket
Socket
Sign inDemoInstall

bag

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    bag

Unordered collection


Version published
Weekly downloads
13
increased by550%
Maintainers
1
Install size
6.77 kB
Created
Weekly downloads
 

Readme

Source

bag

An array-backed unordered collection.

API

var Bag = require('bag').Bag;

// Create a new bag
var bag = new Bag;

// Get number of items in bag
console.log(bag.length); // => 0
console.log(bag.isEmpty()); // => true

// Add some items
bag.add(1);
bag.add(2);
bag.add(3);

console.log(bag.length); // => 3
console.log(bag.isEmpty()); // => false

// Membership test
bag.contains(1);  // => true
bag.contains(4);  // => false

// Iterator
bag.forEach(function(value) { /* ... */ });

// Remove the last item
var removed = bag.removeLast();
console.log(removed); // => 3

// Remove a specific object
bag.removeObject(2); // => true

// Add all items from an array or another bag:
bag.addAll([8,9,10]);

// Remove all items from an array or another bag:
bag.removeAll([8,9,10]);

// Remove all items
bag.clear();
console.log(bag.length); // => 0
console.log(bag.isEmpty()); // => true

There are also get(), set() and remove() methods which operate on specific indices but these should be avoided in most circumstances because the order of items within the bag is not constant.

Keywords

FAQs

Last updated on 22 Mar 2016

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc