npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

underscore-ko

v1.8.31

Published

Dead simple utility that attaches Underscore.js array and collection functions (and mutators) to Knockout.js observable arrays.

Downloads

82

Readme

UnderscoreKO

Underscore.js + Knockout = Array Happy Fun Time!

This tiny library (< 1KB) adds all the collection and array methods you've come to love in Underscore.js to your Knockout observable arrays. It will not override any existing functionality (if any exists).

Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)

Install

Manual

Download .\build\underscore-ko.min.js and put it in your project.

Nuget

Install the UnderscoreKO Nuget package.

PM> Install-Package UnderscoreKO

bower

bower install underscore-ko

npm

npm install underscore-ko

TypeScript Declarations

UnderscoreKO ships with built-in TypeScript declarations, see build\underscore-ko.d.ts.

Usage

Use the Underscore methods just as you normally would, but now you don't need to specify the array to use:

var vm = {
    arr: ko.observableArray([1, 2, 3]);
};

vm.arr.each(function (x) {
    // do something
});

// This returns a raw array, not a ko.observableArray
var newArr = vm.arr.union([0, 1]);

// but this will append 0 and 1 to the underlying array and trigger a change notification
vm.arr.union_([0, 1]);

In addition, there are several functions you can use that will mutate (change) the underlying array, which are provided as convenient shortcuts.

// Re-structure the observable array [1, 2, 3]
vm.arr.without_(2);
// vm.arr() is now equal to [1, 3]

// Without this, you would need to do:
vm.arr(vm.arr.without(2));

Live Demo

View the live jsFiddle demo

Documentation

See the Underscore.js documentation for more information on the API. All array and collection methods are supported with the exception of any I felt didn't provide value (.toArray() for example).

See spec.js for examples of how to use specific functions, but I'm telling you, it's as you'd expect.

Mutator Methods

These methods change the underlying array instead of returning a copy of the array.

  • filter_, select_
  • reject_
  • invoke_
  • sortBy_
  • groupBy_
  • shuffle_
  • rest_, tail_
  • compact_
  • flatten_
  • without_
  • union_
  • intersection_
  • difference_
  • uniq_, unique_
  • zip_
  • unzip_

Contributing

See Contributing