New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

valentine

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

valentine

JavaScripts Functional Sister. Utilitiy, Iterators, type checking

  • 1.5.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
63
decreased by-33.68%
Maintainers
1
Weekly downloads
 
Created
Source
\  / _. |  _  ._ _|_ o ._   _
 \/ (_| | (/_ | | |_ | | | (/_

Build Status JavaScript's Sister, and protector — inspired by Underscore; Valentine provides you with type checking, functional iterators, and common utility helpers such as waterfalls, queues, and parallels; all utilizing native JavaScript methods (when available) for optimal speed.

Browser usage:

<script src="valentine.js"></script>
<script>
  v.forEach(['a', 'b', 'c'], function (letter) {

  })
</script>

Node users, install it:

$ npm install valentine

Use it:

var v = require('valentine')

// showcase object style
v(['a', 'b', 'c']).map(function (letter) {
  return letter.toUpperCase()
}).join(' '); // => 'A B C'

API

iterators

  • v.each(ar || obj, callback[, scope])
  • v.map(ar || obj, callback[, scope])
  • v.every(ar, callback[, scope])
  • v.some(ar, callback[, scope])
  • v.filter(ar, callback[, scope])
  • v.reject(ar, callback[, scope])
  • v.indexOf(ar, item[, start])
  • v.lastIndexOf(ar, item[, start])
  • v.reduce(ar, callback, memo[, scope])
  • v.reduceRight(ar, callback, memo[, scope])

utility

  • v.extend(obj[, obj2[, obj3[...]]])
  • v.merge(ar1, ar2)
  • v.pluck(ar, key)
  • v.toArray(sparse)
  • v.size(ar)
  • v.find(ar, key)
  • v.compact(ar)
  • v.flatten(ar)
  • v.uniq(ar)
  • v.first(ar)
  • v.last(ar)
  • v.keys(obj)
  • v.values(obj)
  • v.trim(str)
  • v.bind(scope, fn, [curried args])
  • v.curry(fn, [curried args])
  • v.inArray(ar, needle)
  • v.parallel([fn args])
v.parallel(
  function (fn) {
    getTimeline(function (e, timeline) {
      fn(e, timeline)
    })
  }
, function (fn) {
    getUser(function (e, user) {
      fn(e, user)
    })
  }
, function (e, timeline, user) {
    if (e) return console.log(e)
    ok(timeline == 'one', 'first result is "one"')
    ok(user == 'two', 'second result is "two"')
  }
)
  • v.waterfall([fn args])
v.waterfall(
  function (callback) {
    callback(null, 'one', 'two')
  }
, function (a, b, callback) {
    console.log(a == 'one')
    console.log(b == 'two')
    callback(null, 'three')
  }
, function (c, callback) {
    console.log(c == 'three')
    callback(null, 'final result')
  }
, function (err, result) {
    console.log(!!err == false)
    console.log(result == 'final result')
  }
)
  • v.waterfall([fn1, fn2<, fn3>], callback)
  • v.queue([fn args])
var it = v.queue(
  function () {
    console.log('one')
    it.next()
  }
, function () {
    console.log('two')
    it.next()
  }
, function () {
    console.log('three')
  }
)
it.next()

type checking

  • v.is.fun(o)
  • v.is.str(o)
  • v.is.ele(o)
  • v.is.arr(o)
  • v.is.arrLike(o)
  • v.is.num(o)
  • v.is.bool(o)
  • v.is.args(o)
  • v.is.emp(o)
  • v.is.dat(o)
  • v.is.nan(o)
  • v.is.nil(o)
  • v.is.und(o)
  • v.is.obj(o)

Object Style

v(['a', 'b', 'c']).map(function (letter) {
  return letter.toUpperCase()
}); // => ['A', 'B', 'C']

Chains

v(['a', 'b', [['c']], 0, false,,,null,['a', 'b', 'c']])
  .chain().flatten().compact().uniq().map(function (letter) {
    return letter.toUpperCase()
  }).value(); // => ['A', 'B', 'C']

Ender Support

Don't have Ender? Install it, and don't ever look back.

$ [sudo] npm install ender -g

Then build valentine into your package

$ ender build valentine

Have an existing Ender package? Include it:

$ ender add valentine

Write code like a boss


// as a top level method
$.v(['a', ['virus'], 'b', 'c']).reject(function (el, i) {
  return $.is.arr(el[i])
})

// top level methods in bridge
$.each
  map
  merge
  extend
  toArray
  keys
  values
  trim
  bind
  curry
  parallel
  waterfall
  inArray
  queue

Or just require the valentine module

!function (v) {
  v(['a', ['virus'], 'b', 'c']).reject(function (el, i) {
    return v.is.arr(el[i])
  })
}(require('valentine'))

Developers

Care to contribute? Make your edits to src/valentine.js and get your environment up and running

$ npm install -d
$ make
$ make test
$ open tests/index.html

Happy iterating!

Keywords

FAQs

Package last updated on 21 Jun 2012

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc