Code Monkey home page Code Monkey logo

underscore-mixins's Introduction

underscore-mixins

A Small Collection of Underscore.js Mixins

_.zipObj()

This takes an object whose values are arrays and zips them into an array of objects using the same keys.

var input = {
  key1: [1, 2, 3],
  key2: [4, 5, 6],
  key3: [7, 8, 9]
}

_.zipObj(input);
// Returns:
// [
//   {
//     "key1": 1,
//     "key2": 4,
//     "key3": 7
//   },
//   {
//     "key1": 2,
//     "key2": 5,
//     "key3": 8
//   },
//   {
//     "key1": 3,
//     "key2": 6,
//     "key3": 9
//   }
// ]

filterObj()

This takes an incoming data source and strips out any keys that are not present in the control object.

var data = {
    name : {
        first : 'Al',
        last : 'Engel'
    }
    address : '10 Imaginary St.',
    city : 'Springfield',
    state : 'GA'
    _id : 'Some Protected Field'
};

var control = {
    name : true,
    address : true,
    state : true
};

_.filterObj(data, control);
// Returns:
// {
//     name : {
//         first : 'Al',
//         last : 'Engel'
//     },
//     address : '10 Imaginary St.',
//     state : 'Springfield'
// }
// Omitted 'city', '_id' fields in returned data

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.