code stringlengths 2 1.05M |
|---|
import React from 'react';
import withRoot from 'docs/src/modules/components/withRoot';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import markdown from './card-content.md';
function Page() {
return <MarkdownDocs markdown={markdown} />;
}
export default withRoot(Page);
|
var webpack = require('webpack');
var path = require('path');
module.exports = {
entry: [
'webpack-dev-server/client?http://localhost:5000',
'webpack/hot/dev-server',
'./index'
],
output: {
path: path.join(__dirname, '/'),
filename: 'bundle.js',
publicPath: '/'
},
resolve: {
extensions: ['', '.js', '.jsx']
},
devtool: 'eval-source-map',
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
module: {
loaders: [
{
test: /\.jsx?$/,
loaders: ['react-hot', 'babel'],
exclude: /node_modules/
}
]
}
};
|
app.directive('fileModel', ['$parse', function ($parse) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var model = $parse(attrs.fileModel);
var modelSetter = model.assign;
element.bind('change', function(){
scope.$apply(function(){
modelSetter(scope, element[0].files[0]);
});
});
}
};
}]); |
(function($)
{
var defauts=
{
"noms" : {},
"separateur": "rect-",
"margeRect" : 15,
"largeurRect" : 80,
"hauteurRect" : 60,
"paddingProfondeur" : 60,
"orientation" : "paysage",
"onAdd" : function(id,e) { return formUserInstrumentConcert(1,id,e); },
"onEdit" : function(id,e) { return formUserInstrumentConcert(2,id,e); },
"onDel" : function(id,e) { return supprimerItemConcert(id); }
};
var methods =
{
ajouterNoeud : function(idNoeud,idNoeudFils,nomNoeud)
{
var noeud = $(this).find("#"+idNoeud);
if(noeud)
{
params.noms[idNoeudFils] = nomNoeud;
var fils = noeud.children();
if(fils.length == 0)
noeud.replaceWith("<ul id=\""+idNoeud+"\"><li id=\""+idNoeudFils+"\"></li></ul>");
else
noeud.append("<li id=\""+idNoeudFils+"\"></li>");
}
return methods.init.apply(this);
},
modifierNoeud : function(idNoeud,nomNoeud)
{
var noeud = $(this).find("#"+idNoeud);
if(noeud)
{
params.noms[idNoeud] = nomNoeud;
}
return methods.init.apply(this);
},
supprimerNoeud : function(idNoeud)
{
var noeud = $(this).find("#"+idNoeud);
if(noeud)
{
noeud.remove();
}
return methods.init.apply(this);
},
dessinerTextes: function(noeud)
{
var rect = $("#"+params.separateur+noeud.attr("id"),svg.root());
if(rect)
{
var x = parseInt(rect.attr("x"),10)+ 5;
var y = parseInt(rect.attr("y"),10)+ 20;
var largeur = parseInt(rect.attr("width"),10);
var hauteur = parseInt(rect.attr("height"),10);
if(!isNaN(x) && !isNaN(y) && !isNaN(largeur) && !isNaN(hauteur) && params.noms[noeud.attr("id")])
{
var g = svg.group({fontWeight: 'bold', fontSize: '15', fill: 'black'});
svg.text(g,x, parseInt(y-3,10), params.noms[noeud.attr("id")]);
}
}
var fils = $(noeud.children());
for(var i =0; i < fils.length; i++)
methods.dessinerTextes($(fils[i]));
},
orientation : function(mode)
{
params.orientation = mode;
return methods.init.apply(this);
},
dessinerTraits: function (noeud, isRoot)
{
var rect = $("#"+params.separateur+noeud.attr("id"),svg.root());
var x = parseInt(rect.attr("x"),10);
var y = parseInt(rect.attr("y"),10);
var largeur = parseInt(rect.attr("width"),10);
var hauteur = parseInt(rect.attr("height"),10);
if(!isNaN(x) && !isNaN(y) && !isNaN(largeur) && !isNaN(hauteur))
{
var fils = $(noeud.children());
for(var i =0; i < fils.length; i++)
{
var rectFils = $("#"+params.separateur+$(fils[i]).attr("id"),svg.root());
var xFils = parseInt(rectFils.attr("x"),10);
var yFils = parseInt(rectFils.attr("y"),10);
var largeurFils = parseInt(rectFils.attr("width"),10);
var hauteurFils = parseInt(rectFils.attr("height"),10);
if(!isNaN(x) && !isNaN(y) && !isNaN(largeur) && !isNaN(hauteur))
{
if(params.orientation == "paysage")
svg.line(x + parseInt(largeur/2,10), y+hauteur, xFils + parseInt(largeurFils/2,10), yFils,{stroke: "black"});
else
svg.line(x + largeur, y+ parseInt(hauteur/2) , xFils , yFils + parseInt(hauteurFils/2,10),{stroke: "black"});
}
methods.dessinerTraits($(fils[i]));
}
}
},
dessinerRectangles: function (posX,posY,longueurTotale, noeud)
{
if(params.orientation == "paysage")
{
svg.rect( posX + parseInt((longueurTotale - params.margeRect - params.largeurRect)/2,10) , posY, params.largeurRect,params.hauteurRect,
{id:params.separateur+ noeud.attr("id"), fill: "lightgrey", stroke: "black",
});
}else
{
svg.rect( posX, posY + parseInt((longueurTotale - params.margeRect - params.hauteurRect)/2,10) , params.largeurRect,params.hauteurRect,
{id:params.separateur+ noeud.attr("id"), fill: "lightgrey", stroke: "black",
});
}
var fils = $(noeud.children());
if(fils.length > 0)
{
var lg = parseInt(longueurTotale / fils.length,10);
for(var i = 0; i < fils.length ; i++)
{
if(params.orientation == "paysage")
methods.dessinerRectangles(posX + (i*lg), posY + params.hauteurRect + params.paddingProfondeur, lg, $(fils[i]));
else
methods.dessinerRectangles(posX + params.hauteurRect + params.paddingProfondeur, posY + (i*lg), lg, $(fils[i]));
}
}
},
init: function(options)
{
return this.each(function()
{
if($(this).html().length > 0)
{
if(! $(this).find(".datas").length)
$(this).html($("<div class=\"arbre\"></div><br /><div class=\"datas\">"+$(this).html()+"</div>"));
var html = $(this).find(".datas").hide().html();
$(this).find(".arbre").svg().svg('destroy').svg();
svg = $(this).find(".arbre").svg('get');
if(params.orientation == "paysage")
var width = parseInt($(svg.root()).attr("width"),10) -50;
else
var width = parseInt($(svg.root()).attr("height"),10);
methods.dessinerRectangles(20,20,width,$(html));
methods.dessinerTraits($(html),true);
methods.dessinerTextes($(html));
$("#menuConcert").remove();
$("rect").each(function(i)
{
$(this).hover(function()
{
$("#menuConcert").remove();
var id = $(this).attr("id").split(params.separateur);
var x = $(this).offset().left -10;
var y = $(this).offset().top - 33 ;
var lg = parseInt($(this).attr("width"),10)+20;
var menu = $("<div id=\"menuConcert\" class=\"menuConcert\" >"+
"<a href=\"#addNoeud\" class=\"fleft addNoeud\" title=\"Ajouter une entité\" ></a>"+
"<a href=\"#editNoeud\" class=\"fleft editNoeud\" title=\"Modifier une entité\" ></a>"+
(i != 0 ? "<a href=\"#delNoeud\" class=\"fleft delNoeud\" title=\"Supprimer une entité\" ></a>" : "")+
"</div>").appendTo("body");
menu.css({ width: lg+"px", top: y+"px", left: x+"px" });
menu.find(".addNoeud").click(function(e){return params.onAdd(id[1], menu);});
menu.find(".editNoeud").click(function(e){return params.onEdit(id[1], menu);});
menu.find(".delNoeud").click(function(e){return params.onDel(id[1], menu);});
});
});
}
});
}
};
var params= null;
var svg = null;
$.fn.arbre = function( method )
{
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
params = $.extend(defauts,arguments[0]);
return methods.init.apply( this, arguments );
}
};
})(jQuery);
|
$(function () {
<<<<<<< HEAD
module('tooltip')
test('should provide no conflict', function () {
var tooltip = $.fn.tooltip.noConflict()
ok(!$.fn.tooltip, 'tooltip was set back to undefined (org value)')
$.fn.tooltip = tooltip
})
test('should be defined on jquery object', function () {
var div = $('<div></div>')
ok(div.tooltip, 'popover method is defined')
})
test('should return element', function () {
var div = $('<div></div>')
ok(div.tooltip() == div, 'document.body returned')
})
test('should expose default settings', function () {
ok(!!$.fn.tooltip.Constructor.DEFAULTS, 'defaults is defined')
})
test('should empty title attribute', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>').tooltip()
ok(tooltip.attr('title') === '', 'title attribute was emptied')
})
test('should add data attribute for referencing original title', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>').tooltip()
equal(tooltip.attr('data-original-title'), 'Another tooltip', 'original title preserved in data attribute')
})
test('should place tooltips relative to placement option', function () {
$.support.transition = false
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.tooltip({placement: 'bottom'})
.tooltip('show')
ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied')
tooltip.tooltip('hide')
})
test('should allow html entities', function () {
$.support.transition = false
var tooltip = $('<a href="#" rel="tooltip" title="<b>@fat</b>"></a>')
.appendTo('#qunit-fixture')
.tooltip({html: true})
.tooltip('show')
ok($('.tooltip b').length, 'b tag was inserted')
tooltip.tooltip('hide')
ok(!$('.tooltip').length, 'tooltip removed')
})
test('should respect custom classes', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.tooltip({ template: '<div class="tooltip some-class"><div class="tooltip-arrow"/><div class="tooltip-inner"/></div>'})
.tooltip('show')
ok($('.tooltip').hasClass('some-class'), 'custom class is present')
tooltip.tooltip('hide')
ok(!$('.tooltip').length, 'tooltip removed')
})
test('should fire show event', function () {
stop()
var tooltip = $('<div title="tooltip title"></div>')
.on('show.bs.tooltip', function () {
ok(true, 'show was called')
start()
})
.tooltip('show')
})
test('should fire shown event', function () {
stop()
var tooltip = $('<div title="tooltip title"></div>')
.on('shown.bs.tooltip', function () {
ok(true, 'shown was called')
start()
})
.tooltip('show')
})
test('should not fire shown event when default prevented', function () {
stop()
var tooltip = $('<div title="tooltip title"></div>')
.on('show.bs.tooltip', function (e) {
e.preventDefault()
ok(true, 'show was called')
start()
})
.on('shown.bs.tooltip', function () {
ok(false, 'shown was called')
})
.tooltip('show')
})
test('should fire hide event', function () {
stop()
var tooltip = $('<div title="tooltip title"></div>')
.on('shown.bs.tooltip', function () {
$(this).tooltip('hide')
})
.on('hide.bs.tooltip', function () {
ok(true, 'hide was called')
start()
})
.tooltip('show')
})
test('should fire hidden event', function () {
stop()
var tooltip = $('<div title="tooltip title"></div>')
.on('shown.bs.tooltip', function () {
$(this).tooltip('hide')
})
.on('hidden.bs.tooltip', function () {
ok(true, 'hidden was called')
start()
})
.tooltip('show')
})
test('should not fire hidden event when default prevented', function () {
stop()
var tooltip = $('<div title="tooltip title"></div>')
.on('shown.bs.tooltip', function () {
$(this).tooltip('hide')
})
.on('hide.bs.tooltip', function (e) {
e.preventDefault()
ok(true, 'hide was called')
start()
})
.on('hidden.bs.tooltip', function () {
ok(false, 'hidden was called')
})
.tooltip('show')
})
test('should not show tooltip if leave event occurs before delay expires', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.tooltip({ delay: 200 })
stop()
tooltip.trigger('mouseenter')
setTimeout(function () {
ok(!$('.tooltip').is('.fade.in'), 'tooltip is not faded in')
tooltip.trigger('mouseout')
setTimeout(function () {
ok(!$('.tooltip').is('.fade.in'), 'tooltip is not faded in')
start()
}, 200)
}, 100)
})
test('should not show tooltip if leave event occurs before delay expires, even if hide delay is 0', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.tooltip({ delay: { show: 200, hide: 0} })
stop()
tooltip.trigger('mouseenter')
setTimeout(function () {
ok(!$('.tooltip').is('.fade.in'), 'tooltip is not faded in')
tooltip.trigger('mouseout')
setTimeout(function () {
ok(!$('.tooltip').is('.fade.in'), 'tooltip is not faded in')
start()
}, 200)
}, 100)
})
test('should wait 200 ms before hiding the tooltip', 3, function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.tooltip({ delay: { show: 0, hide: 200} })
stop()
tooltip.trigger('mouseenter')
setTimeout(function () {
ok($('.tooltip').is('.fade.in'), 'tooltip is faded in')
tooltip.trigger('mouseout')
setTimeout(function () {
ok($('.tooltip').is('.fade.in'), '100ms:tooltip is still faded in')
setTimeout(function () {
ok(!$('.tooltip').is('.in'), 'tooltip removed')
start()
}, 150)
}, 100)
}, 1)
})
test('should not hide tooltip if leave event occurs, then tooltip is show immediately again', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.tooltip({ delay: { show: 0, hide: 200} })
stop()
tooltip.trigger('mouseenter')
setTimeout(function () {
ok($('.tooltip').is('.fade.in'), 'tooltip is faded in')
tooltip.trigger('mouseout')
setTimeout(function () {
ok($('.tooltip').is('.fade.in'), '100ms:tooltip is still faded in')
tooltip.trigger('mouseenter')
setTimeout(function () {
ok($('.tooltip').is('.in'), 'tooltip removed')
start()
}, 150)
}, 100)
}, 1)
})
test('should not show tooltip if leave event occurs before delay expires', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.tooltip({ delay: 100 })
stop()
tooltip.trigger('mouseenter')
setTimeout(function () {
ok(!$('.tooltip').is('.fade.in'), 'tooltip is not faded in')
tooltip.trigger('mouseout')
setTimeout(function () {
ok(!$('.tooltip').is('.fade.in'), 'tooltip is not faded in')
start()
}, 100)
}, 50)
})
test('should show tooltip if leave event hasn\'t occured before delay expires', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.tooltip({ delay: 150 })
stop()
tooltip.trigger('mouseenter')
setTimeout(function () {
ok(!$('.tooltip').is('.fade.in'), 'tooltip is not faded in')
}, 100)
setTimeout(function () {
ok($('.tooltip').is('.fade.in'), 'tooltip has faded in')
start()
}, 200)
})
test('should destroy tooltip', function () {
var tooltip = $('<div/>').tooltip().on('click.foo', function () {})
ok(tooltip.data('bs.tooltip'), 'tooltip has data')
ok($._data(tooltip[0], 'events').mouseover && $._data(tooltip[0], 'events').mouseout, 'tooltip has hover event')
ok($._data(tooltip[0], 'events').click[0].namespace == 'foo', 'tooltip has extra click.foo event')
tooltip.tooltip('show')
tooltip.tooltip('destroy')
ok(!tooltip.hasClass('in'), 'tooltip is hidden')
ok(!$._data(tooltip[0], 'bs.tooltip'), 'tooltip does not have data')
ok($._data(tooltip[0], 'events').click[0].namespace == 'foo', 'tooltip still has click.foo')
ok(!$._data(tooltip[0], 'events').mouseover && !$._data(tooltip[0], 'events').mouseout, 'tooltip does not have any events')
})
test('should show tooltip with delegate selector on click', function () {
var div = $('<div><a href="#" rel="tooltip" title="Another tooltip"></a></div>')
var tooltip = div.appendTo('#qunit-fixture')
.tooltip({ selector: 'a[rel=tooltip]',
trigger: 'click' })
div.find('a').trigger('click')
ok($('.tooltip').is('.fade.in'), 'tooltip is faded in')
})
test('should show tooltip when toggle is called', function () {
var tooltip = $('<a href="#" rel="tooltip" title="tooltip on toggle"></a>')
.appendTo('#qunit-fixture')
.tooltip({trigger: 'manual'})
.tooltip('toggle')
ok($('.tooltip').is('.fade.in'), 'tooltip should be toggled in')
})
test('should place tooltips inside the body', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.tooltip({container: 'body'})
.tooltip('show')
ok($('body > .tooltip').length, 'inside the body')
ok(!$('#qunit-fixture > .tooltip').length, 'not found in parent')
tooltip.tooltip('hide')
})
test('should place tooltip inside window', function () {
var container = $('<div />').appendTo('body')
.css({position: 'absolute', width: 200, height: 200, bottom: 0, left: 0}),
tooltip = $('<a href="#" title="Very very very very very very very very long tooltip">Hover me</a>')
.css({position: 'absolute', top: 0, left: 0})
.appendTo(container)
.tooltip({placement: 'top', animate: false})
.tooltip('show')
stop()
setTimeout(function () {
ok($('.tooltip').offset().left >= 0)
start()
container.remove()
}, 100)
})
test('should place tooltip on top of element', function () {
var container = $('<div />').appendTo('body')
.css({position: 'absolute', bottom: 0, left: 0, textAlign: 'right', width: 300, height: 300}),
p = $('<p style="margin-top:200px" />').appendTo(container),
tooltiped = $('<a href="#" title="very very very very very very very long tooltip">Hover me</a>')
.css({marginTop: 200})
.appendTo(p)
.tooltip({placement: 'top', animate: false})
.tooltip('show')
stop()
setTimeout(function () {
var tooltip = container.find('.tooltip')
start()
ok(Math.round(tooltip.offset().top + tooltip.outerHeight()) <= Math.round(tooltiped.offset().top))
container.remove()
}, 100)
})
test('should add position class before positioning so that position-specific styles are taken into account', function () {
$('head').append('<style> .tooltip.right { white-space: nowrap; } .tooltip.right .tooltip-inner { max-width: none; } </style>')
var container = $('<div />').appendTo('body'),
target = $('<a href="#" rel="tooltip" title="very very very very very very very very long tooltip in one line"></a>')
.appendTo(container)
.tooltip({placement: 'right'})
.tooltip('show'),
tooltip = container.find('.tooltip')
// this is some dumb hack shit because sub pixels in firefox
var top = Math.round(target.offset().top + (target[0].offsetHeight / 2) - (tooltip[0].offsetHeight / 2))
var top2 = Math.round(tooltip.offset().top)
var topDiff = top - top2
ok(topDiff <= 1 && topDiff >= -1)
target.tooltip('hide')
})
test('tooltip title test #1', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Simple tooltip" style="display: inline-block; position: absolute; top: 0; left: 0;"></a>')
.appendTo('#qunit-fixture')
.tooltip({
})
.tooltip('show')
equal($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title from title attribute is set')
tooltip.tooltip('hide')
ok(!$('.tooltip').length, 'tooltip removed')
})
test('tooltip title test #2', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Simple tooltip" style="display: inline-block; position: absolute; top: 0; left: 0;"></a>')
.appendTo('#qunit-fixture')
.tooltip({
title: 'This is a tooltip with some content'
})
.tooltip('show')
equal($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title is set from title attribute while prefered over title option')
tooltip.tooltip('hide')
ok(!$('.tooltip').length, 'tooltip removed')
})
test('tooltip title test #3', function () {
var tooltip = $('<a href="#" rel="tooltip" style="display: inline-block; position: absolute; top: 0; left: 0;"></a>')
.appendTo('#qunit-fixture')
.tooltip({
title: 'This is a tooltip with some content'
})
.tooltip('show')
equal($('.tooltip').children('.tooltip-inner').text(), 'This is a tooltip with some content', 'title from title option is set')
tooltip.tooltip('hide')
ok(!$('.tooltip').length, 'tooltip removed')
})
test('tooltips should be placed dynamically, with the dynamic placement option', function () {
$.support.transition = false
var ttContainer = $('<div id="dynamic-tt-test"/>').css({
'height' : 400,
'overflow' : 'hidden',
'position' : 'absolute',
'top' : 0,
'left' : 0,
'width' : 600})
.appendTo('body')
var topTooltip = $('<div style="display: inline-block; position: absolute; left: 0; top: 0;" rel="tooltip" title="Top tooltip">Top Dynamic Tooltip</div>')
.appendTo('#dynamic-tt-test')
.tooltip({placement: 'auto'})
.tooltip('show')
ok($('.tooltip').is('.bottom'), 'top positioned tooltip is dynamically positioned bottom')
topTooltip.tooltip('hide')
var rightTooltip = $('<div style="display: inline-block; position: absolute; right: 0;" rel="tooltip" title="Right tooltip">Right Dynamic Tooltip</div>')
.appendTo('#dynamic-tt-test')
.tooltip({placement: 'right auto'})
.tooltip('show')
ok($('.tooltip').is('.left'), 'right positioned tooltip is dynamically positioned left')
rightTooltip.tooltip('hide')
var leftTooltip = $('<div style="display: inline-block; position: absolute; left: 0;" rel="tooltip" title="Left tooltip">Left Dynamic Tooltip</div>')
.appendTo('#dynamic-tt-test')
.tooltip({placement: 'auto left'})
.tooltip('show')
ok($('.tooltip').is('.right'), 'left positioned tooltip is dynamically positioned right')
leftTooltip.tooltip('hide')
ttContainer.remove()
})
=======
'use strict';
module('tooltip plugin')
test('should be defined on jquery object', function () {
var div = $('<div></div>')
ok(div.tooltip, 'popover method is defined')
})
module('tooltip', {
setup: function () {
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
$.fn.bootstrapTooltip = $.fn.tooltip.noConflict()
},
teardown: function () {
$.fn.tooltip = $.fn.bootstrapTooltip
delete $.fn.bootstrapTooltip
}
})
test('should provide no conflict', function () {
ok(!$.fn.tooltip, 'tooltip was set back to undefined (org value)')
})
test('should return element', function () {
var div = $('<div></div>')
ok(div.bootstrapTooltip() == div, 'document.body returned')
})
test('should expose default settings', function () {
ok(!!$.fn.bootstrapTooltip.Constructor.DEFAULTS, 'defaults is defined')
})
test('should empty title attribute', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>').bootstrapTooltip()
ok(tooltip.attr('title') === '', 'title attribute was emptied')
})
test('should add data attribute for referencing original title', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>').bootstrapTooltip()
equal(tooltip.attr('data-original-title'), 'Another tooltip', 'original title preserved in data attribute')
})
test('should add set set aria describedby to the element called on show', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>').bootstrapTooltip()
.appendTo('#qunit-fixture')
.bootstrapTooltip('show')
ok(tooltip.attr('aria-describedby'), 'has the right attributes')
var id = $('.tooltip').attr('id')
ok($('#' + id).length == 1, 'has a unique id')
ok($('.tooltip').attr('aria-describedby') === tooltip.attr('id'), 'they match!')
ok(tooltip.attr('aria-describedby') !== undefined, 'has the right attributes')
})
test('should remove the aria-describedby attributes on hide', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>').bootstrapTooltip()
.appendTo('#qunit-fixture')
.bootstrapTooltip('show')
ok(tooltip.attr('aria-describedby'), 'has the right attributes')
tooltip.bootstrapTooltip('hide')
ok(!tooltip.attr('aria-describedby'), 'removed the attributes on hide')
})
test('should assign a unique id tooltip element', function () {
$('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.bootstrapTooltip('show')
var id = $('.tooltip').attr('id')
ok($('#' + id).length == 1 && id.indexOf('tooltip') === 0, 'generated prefixed and unique tooltip id')
})
test('should place tooltips relative to placement option', function () {
$.support.transition = false
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ placement: 'bottom' })
.bootstrapTooltip('show')
ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied')
tooltip.bootstrapTooltip('hide')
})
test('should allow html entities', function () {
$.support.transition = false
var tooltip = $('<a href="#" rel="tooltip" title="<b>@fat</b>"></a>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ html: true })
.bootstrapTooltip('show')
ok($('.tooltip b').length, 'b tag was inserted')
tooltip.bootstrapTooltip('hide')
ok(!$('.tooltip').length, 'tooltip removed')
})
test('should respect custom classes', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ template: '<div class="tooltip some-class"><div class="tooltip-arrow"/><div class="tooltip-inner"/></div>' })
.bootstrapTooltip('show')
ok($('.tooltip').hasClass('some-class'), 'custom class is present')
tooltip.bootstrapTooltip('hide')
ok(!$('.tooltip').length, 'tooltip removed')
})
test('should fire show event', function () {
stop()
$('<div title="tooltip title"></div>')
.on('show.bs.tooltip', function () {
ok(true, 'show was called')
start()
})
.bootstrapTooltip('show')
})
test('should fire shown event', function () {
stop()
var tooltip = $('<div title="tooltip title"></div>').appendTo('#qunit-fixture')
tooltip
.on('shown.bs.tooltip', function () {
ok(true, 'shown was called')
tooltip.remove()
start()
})
.bootstrapTooltip('show')
})
test('should not fire shown event when default prevented', function () {
stop()
$('<div title="tooltip title"></div>')
.on('show.bs.tooltip', function (e) {
e.preventDefault()
ok(true, 'show was called')
start()
})
.on('shown.bs.tooltip', function () {
ok(false, 'shown was called')
})
.bootstrapTooltip('show')
})
test('should fire hide event', function () {
stop()
var tooltip = $('<div title="tooltip title"></div>').appendTo('#qunit-fixture')
tooltip
.on('shown.bs.tooltip', function () {
$(this).bootstrapTooltip('hide')
})
.on('hide.bs.tooltip', function () {
ok(true, 'hide was called')
tooltip.remove()
start()
})
.bootstrapTooltip('show')
})
test('should fire hidden event', function () {
stop()
var tooltip = $('<div title="tooltip title"></div>').appendTo('#qunit-fixture')
tooltip
.on('shown.bs.tooltip', function () {
$(this).bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
ok(true, 'hidden was called')
tooltip.remove()
start()
})
.bootstrapTooltip('show')
})
test('should not fire hidden event when default prevented', function () {
stop()
var tooltip = $('<div title="tooltip title"></div>').appendTo('#qunit-fixture')
tooltip
.on('shown.bs.tooltip', function () {
$(this).bootstrapTooltip('hide')
})
.on('hide.bs.tooltip', function (e) {
e.preventDefault()
ok(true, 'hide was called')
tooltip.remove()
start()
})
.on('hidden.bs.tooltip', function () {
ok(false, 'hidden was called')
})
.bootstrapTooltip('show')
})
test('should not show tooltip if leave event occurs before delay expires', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ delay: 200 })
stop()
tooltip.trigger('mouseenter')
setTimeout(function () {
ok(!$('.tooltip').is('.fade.in'), 'tooltip is not faded in')
tooltip.trigger('mouseout')
setTimeout(function () {
ok(!$('.tooltip').is('.fade.in'), 'tooltip is not faded in')
start()
}, 200)
}, 100)
})
test('should not show tooltip if leave event occurs before delay expires, even if hide delay is 0', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ delay: { show: 200, hide: 0 }})
stop()
tooltip.trigger('mouseenter')
setTimeout(function () {
ok(!$('.tooltip').is('.fade.in'), 'tooltip is not faded in')
tooltip.trigger('mouseout')
setTimeout(function () {
ok(!$('.tooltip').is('.fade.in'), 'tooltip is not faded in')
start()
}, 200)
}, 100)
})
test('should wait 200 ms before hiding the tooltip', 3, function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ delay: { show: 0, hide: 200 }})
stop()
tooltip.trigger('mouseenter')
setTimeout(function () {
ok($('.tooltip').is('.fade.in'), 'tooltip is faded in')
tooltip.trigger('mouseout')
setTimeout(function () {
ok($('.tooltip').is('.fade.in'), '100ms:tooltip is still faded in')
setTimeout(function () {
ok(!$('.tooltip').is('.in'), 'tooltip removed')
start()
}, 150)
}, 100)
}, 1)
})
test('should not hide tooltip if leave event occurs, then tooltip is show immediately again', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ delay: { show: 0, hide: 200 }})
stop()
tooltip.trigger('mouseenter')
setTimeout(function () {
ok($('.tooltip').is('.fade.in'), 'tooltip is faded in')
tooltip.trigger('mouseout')
setTimeout(function () {
ok($('.tooltip').is('.fade.in'), '100ms:tooltip is still faded in')
tooltip.trigger('mouseenter')
setTimeout(function () {
ok($('.tooltip').is('.in'), 'tooltip removed')
start()
}, 150)
}, 100)
}, 1)
})
test('should not show tooltip if leave event occurs before delay expires', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ delay: 100 })
stop()
tooltip.trigger('mouseenter')
setTimeout(function () {
ok(!$('.tooltip').is('.fade.in'), 'tooltip is not faded in')
tooltip.trigger('mouseout')
setTimeout(function () {
ok(!$('.tooltip').is('.fade.in'), 'tooltip is not faded in')
start()
}, 100)
}, 50)
})
test('should show tooltip if leave event hasn\'t occured before delay expires', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ delay: 150 })
stop()
tooltip.trigger('mouseenter')
setTimeout(function () {
ok(!$('.tooltip').is('.fade.in'), 'tooltip is not faded in')
}, 100)
setTimeout(function () {
ok($('.tooltip').is('.fade.in'), 'tooltip has faded in')
start()
}, 200)
})
test('should destroy tooltip', function () {
var tooltip = $('<div/>').bootstrapTooltip().on('click.foo', function () {})
ok(tooltip.data('bs.tooltip'), 'tooltip has data')
ok($._data(tooltip[0], 'events').mouseover && $._data(tooltip[0], 'events').mouseout, 'tooltip has hover event')
ok($._data(tooltip[0], 'events').click[0].namespace == 'foo', 'tooltip has extra click.foo event')
tooltip.bootstrapTooltip('show')
tooltip.bootstrapTooltip('destroy')
ok(!tooltip.hasClass('in'), 'tooltip is hidden')
ok(!$._data(tooltip[0], 'bs.tooltip'), 'tooltip does not have data')
ok($._data(tooltip[0], 'events').click[0].namespace == 'foo', 'tooltip still has click.foo')
ok(!$._data(tooltip[0], 'events').mouseover && !$._data(tooltip[0], 'events').mouseout, 'tooltip does not have any events')
})
test('should show tooltip with delegate selector on click', function () {
var div = $('<div><a href="#" rel="tooltip" title="Another tooltip"></a></div>')
div.appendTo('#qunit-fixture').bootstrapTooltip({
selector: 'a[rel="tooltip"]', trigger: 'click'
})
div.find('a').trigger('click')
ok($('.tooltip').is('.fade.in'), 'tooltip is faded in')
})
test('should show tooltip when toggle is called', function () {
$('<a href="#" rel="tooltip" title="tooltip on toggle"></a>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ trigger: 'manual' })
.bootstrapTooltip('toggle')
ok($('.tooltip').is('.fade.in'), 'tooltip should be toggled in')
})
test('should hide shown tooltip when toggle is called on tooltip', function () {
var tooltip = $('<a href="#" rel="tooltip" title="tooltip on toggle">@ResentedHook</a>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ trigger: 'manual' })
.bootstrapTooltip('toggle')
$('.tooltip', '#qunit-fixture').bootstrapTooltip('toggle')
ok($('.tooltip').not('.fade.in'), 'tooltip should be toggled out')
tooltip.bootstrapTooltip('hide')
$('#qunit-fixture').empty()
})
test('should place tooltips inside the body', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ container: 'body' })
.bootstrapTooltip('show')
ok($('body > .tooltip').length, 'inside the body')
ok(!$('#qunit-fixture > .tooltip').length, 'not found in parent')
tooltip.bootstrapTooltip('hide')
})
test('should place tooltip inside window', function () {
var container = $('<div />').appendTo('body')
.css({ position: 'absolute', width: 200, height: 200, bottom: 0, left: 0 })
$('<a href="#" title="Very very very very very very very very long tooltip">Hover me</a>')
.css({ position: 'absolute', top: 0, left: 0 })
.appendTo(container)
.bootstrapTooltip({ placement: 'top', animate: false })
.bootstrapTooltip('show')
stop()
setTimeout(function () {
ok($('.tooltip').offset().left >= 0)
start()
container.remove()
}, 100)
})
test('should place tooltip on top of element', function () {
var container = $('<div />').appendTo('body')
.css({ position: 'absolute', bottom: 0, left: 0, textAlign: 'right', width: 300, height: 300 })
var p = $('<p style="margin-top:200px" />').appendTo(container)
var tooltiped = $('<a href="#" title="very very very very very very very long tooltip">Hover me</a>')
.css({ marginTop: 200 })
.appendTo(p)
.bootstrapTooltip({ placement: 'top', animate: false })
.bootstrapTooltip('show')
stop()
setTimeout(function () {
var tooltip = container.find('.tooltip')
start()
ok(Math.round(tooltip.offset().top + tooltip.outerHeight()) <= Math.round(tooltiped.offset().top))
container.remove()
}, 100)
})
test('should add position class before positioning so that position-specific styles are taken into account', function () {
$('head').append('<style id="test"> .tooltip.right { white-space: nowrap; } .tooltip.right .tooltip-inner { max-width: none; } </style>')
var container = $('<div />').appendTo('body')
var target = $('<a href="#" rel="tooltip" title="very very very very very very very very long tooltip in one line"></a>')
.appendTo(container)
.bootstrapTooltip({ placement: 'right', viewport: null })
.bootstrapTooltip('show')
var tooltip = container.find('.tooltip')
// this is some dumb hack shit because sub pixels in firefox
var top = Math.round(target.offset().top + (target[0].offsetHeight / 2) - (tooltip[0].offsetHeight / 2))
var top2 = Math.round(tooltip.offset().top)
var topDiff = top - top2
ok(topDiff <= 1 && topDiff >= -1)
target.bootstrapTooltip('hide')
$('head #test').remove()
})
test('tooltip title test #1', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Simple tooltip" style="display: inline-block; position: absolute; top: 0; left: 0;"></a>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({})
.bootstrapTooltip('show')
equal($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title from title attribute is set')
tooltip.bootstrapTooltip('hide')
ok(!$('.tooltip').length, 'tooltip removed')
})
test('tooltip title test #2', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Simple tooltip" style="display: inline-block; position: absolute; top: 0; left: 0;"></a>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
title: 'This is a tooltip with some content'
})
.bootstrapTooltip('show')
equal($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title is set from title attribute while prefered over title option')
tooltip.bootstrapTooltip('hide')
ok(!$('.tooltip').length, 'tooltip removed')
})
test('tooltip title test #3', function () {
var tooltip = $('<a href="#" rel="tooltip" style="display: inline-block; position: absolute; top: 0; left: 0;"></a>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
title: 'This is a tooltip with some content'
})
.bootstrapTooltip('show')
equal($('.tooltip').children('.tooltip-inner').text(), 'This is a tooltip with some content', 'title from title option is set')
tooltip.bootstrapTooltip('hide')
ok(!$('.tooltip').length, 'tooltip removed')
})
test('tooltips should be placed dynamically, with the dynamic placement option', function () {
$.support.transition = false
var ttContainer = $('<div id="dynamic-tt-test"/>').css({
height: 400,
overflow: 'hidden',
position: 'absolute',
top: 0,
left: 0,
width: 600
})
.appendTo('body')
var topTooltip = $('<div style="display: inline-block; position: absolute; left: 0; top: 0;" rel="tooltip" title="Top tooltip">Top Dynamic Tooltip</div>')
.appendTo('#dynamic-tt-test')
.bootstrapTooltip({ placement: 'auto' })
.bootstrapTooltip('show')
ok($('.tooltip').is('.bottom'), 'top positioned tooltip is dynamically positioned bottom')
topTooltip.bootstrapTooltip('hide')
var rightTooltip = $('<div style="display: inline-block; position: absolute; right: 0;" rel="tooltip" title="Right tooltip">Right Dynamic Tooltip</div>')
.appendTo('#dynamic-tt-test')
.bootstrapTooltip({ placement: 'right auto' })
.bootstrapTooltip('show')
ok($('.tooltip').is('.left'), 'right positioned tooltip is dynamically positioned left')
rightTooltip.bootstrapTooltip('hide')
var leftTooltip = $('<div style="display: inline-block; position: absolute; left: 0;" rel="tooltip" title="Left tooltip">Left Dynamic Tooltip</div>')
.appendTo('#dynamic-tt-test')
.bootstrapTooltip({ placement: 'auto left' })
.bootstrapTooltip('show')
ok($('.tooltip').is('.right'), 'left positioned tooltip is dynamically positioned right')
leftTooltip.bootstrapTooltip('hide')
ttContainer.remove()
})
test('should adjust the tip\'s top when up against the top of the viewport', function () {
$('head').append('<style id="test"> .tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; } </style>')
var container = $('<div />').appendTo('body')
var target = $('<a href="#" rel="tooltip" title="tip" style="position: fixed; top: 0px; left: 0px;"></a>')
.appendTo(container)
.bootstrapTooltip({ placement: 'right', viewport: { selector: 'body', padding: 12 }})
.bootstrapTooltip('show')
var tooltip = container.find('.tooltip')
ok(Math.round(tooltip.offset().top) === 12)
target.bootstrapTooltip('hide')
$('head #test').remove()
})
test('should adjust the tip\'s top when up against the bottom of the viewport', function () {
$('head').append('<style id="test"> .tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; } </style>')
var container = $('<div />').appendTo('body')
var target = $('<a href="#" rel="tooltip" title="tip" style="position: fixed; bottom: 0px; left: 0px;"></a>')
.appendTo(container)
.bootstrapTooltip({ placement: 'right', viewport: { selector: 'body', padding: 12 }})
.bootstrapTooltip('show')
var tooltip = container.find('.tooltip')
ok(Math.round(tooltip.offset().top) === Math.round($(window).height() - 12 - tooltip[0].offsetHeight))
target.bootstrapTooltip('hide')
$('head #test').remove()
})
test('should adjust the tip\'s left when up against the left of the viewport', function () {
$('head').append('<style id="test"> .tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; } </style>')
var container = $('<div />').appendTo('body')
var target = $('<a href="#" rel="tooltip" title="tip" style="position: fixed; top: 0px; left: 0px;"></a>')
.appendTo(container)
.bootstrapTooltip({ placement: 'bottom', viewport: { selector: 'body', padding: 12 }})
.bootstrapTooltip('show')
var tooltip = container.find('.tooltip')
ok(Math.round(tooltip.offset().left) === 12)
target.bootstrapTooltip('hide')
$('head #test').remove()
})
test('should adjust the tip\'s left when up against the right of the viewport', function () {
$('head').append('<style id="test"> .tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; } </style>')
var container = $('<div />').appendTo('body')
var target = $('<a href="#" rel="tooltip" title="tip" style="position: fixed; top: 0px; right: 0px;"></a>')
.appendTo(container)
.bootstrapTooltip({ placement: 'bottom', viewport: { selector: 'body', padding: 12 }})
.bootstrapTooltip('show')
var tooltip = container.find('.tooltip')
ok(Math.round(tooltip.offset().left) === Math.round($(window).width() - 12 - tooltip[0].offsetWidth))
target.bootstrapTooltip('hide')
$('head #test').remove()
})
test('should adjust the tip when up against the right of an arbitrary viewport', function () {
$('head').append('<style id="test"> .tooltip, .tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; } </style>')
$('head').append('<style id="viewport-style"> .container-viewport { position: absolute; top: 50px; left: 60px; width: 300px; height: 300px; } </style>')
var container = $('<div />', { 'class': 'container-viewport' }).appendTo('body')
var target = $('<a href="#" rel="tooltip" title="tip" style="position: fixed; top: 50px; left: 350px;"></a>')
.appendTo(container)
.bootstrapTooltip({ placement: 'bottom', viewport: '.container-viewport' })
.bootstrapTooltip('show')
var tooltip = container.find('.tooltip')
ok(Math.round(tooltip.offset().left) === Math.round(60 + container.width() - tooltip[0].offsetWidth))
target.bootstrapTooltip('hide')
$('head #test').remove()
$('head #viewport-style').remove()
})
test('should not error when trying to show an auto-placed tooltip that has been removed from the dom', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>').appendTo('#qunit-fixture')
tooltip
.one('show.bs.tooltip', function () {
tooltip.remove()
})
.bootstrapTooltip({ placement: 'auto' })
var passed = true
try {
tooltip.bootstrapTooltip('show')
}
catch (err) {
passed = false
console.log(err)
}
ok(passed, '.tooltip(\'show\') should not throw an error in this case')
try {
tooltip.remove()
}
catch (err) {
// tooltip may have already been removed
}
})
>>>>>>> 1aaad6481cb064f31f85d519cd56e3c1799585cf
})
|
var https = require('https');
module.exports = {
shorten: function(url, cb) {
https.get('https://is.gd/create.php?format=simple&url=' + encodeURIComponent(url), function (res) {
var body = '';
res.on('data', function(chunk) { body += chunk; });
res.on('end', function() { cb(body); });
});
},
custom: function(url, text, cb) {
https.get('https://is.gd/create.php?format=simple&url=' + encodeURIComponent(url) + '&shorturl=' + encodeURIComponent(text), function (res) {
var body = '';
res.on('data', function(chunk) { body += chunk; });
res.on('end', function() { cb(body); });
});
},
lookup: function(url, cb) {
https.get('https://is.gd/forward.php?format=simple&shorturl=' + encodeURIComponent(url), function (res) {
var body = '';
res.on('data', function(chunk) { body += chunk; });
res.on('end', function() { cb(body); });
});
}
};
|
$(function() {
$('.tabbed').tabs();
$('.help-inner').hide();
$('.help .secondary').on('click', function(e) {
e.preventDefault();
$('.help-inner').toggle();
});
$('#resultsGoMapView').on('click', function(e) {
e.preventDefault();
$('a[href="#tabs-2"]').click();
});
/*var map = L.map('map').setView([51.505, -0.09], 1);
L.tileLayer('http://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>'
}).addTo(map);*/
}); |
var blessed = require('blessed');
var copyPaste = require('copy-paste');
var screen;
var terminal;
function build(channelName) {
var channelUrl = 'http://termcast.xyz/' + channelName;
this.screen = blessed.screen({
smartCSR: true
});
copyPaste.copy(channelUrl);
this.terminal = blessed.terminal({
parent: this.screen,
cursorBlink: true,
screenKeys: false,
label: ' broadcasting @ ' + channelUrl + ' ',
left: 0,
top: 0,
width: this.screen.width,
height: this.screen.height,
border: 'line'
});
this.screen.key('C-q', function() {
this.screen.destroy();
process.kill(0);
return;
});
}
function screenshot(callback) {
var frame = this.terminal.screenshot();
callback(frame);
}
module.exports = {
build: build,
screenshot: screenshot
}
|
import {ChangeAction} from "../../../../history/action/ChangeAction.js";
import {Editor} from "../../../../Editor.js";
import {Slider} from "../../../../components/input/Slider.js";
import {PassNode} from "./PassNode.js";
function HueSaturationPassNode(parent)
{
PassNode.call(this, parent, "HueSaturation");
var self = this;
this.addText("Hue");
this.hue = new Slider(this);
this.hue.size.set(80, 18);
this.hue.setStep(0.05);
this.hue.setRange(-1, 1);
this.hue.setOnChange(function()
{
Editor.addAction(new ChangeAction(self.pass, "hue", self.hue.getValue()));
});
this.add(this.hue);
this.nextRow();
this.addText("Saturation");
this.saturation = new Slider(this);
this.saturation.size.set(80, 18);
this.saturation.setStep(0.05);
this.saturation.setRange(-1, 1);
this.saturation.setOnChange(function()
{
Editor.addAction(new ChangeAction(self.pass, "saturation", self.saturation.getValue()));
});
this.add(this.saturation);
this.nextRow();
}
HueSaturationPassNode.prototype = Object.create(PassNode.prototype);
PassNode.registerPass("HueSaturation", HueSaturationPassNode);
HueSaturationPassNode.prototype.setPass = function(pass)
{
PassNode.prototype.setPass.call(this, pass);
this.hue.setValue(this.pass.hue);
this.saturation.setValue(this.pass.saturation);
};
export {HueSaturationPassNode};
|
/**
* This file is part of the RedKite CMS Application and it is distributed
* under the GPL LICENSE Version 2.0. To use this application you must leave
* intact this copyright notice.
*
* Copyright (c) RedKite Labs <info@redkite-labs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* For extra documentation and help please visit http://www.redkite-labs.com
*
* @license GPL LICENSE Version 2.0
*
*/
function SlotEditorModel()
{
var self = this;
BaseEditorModel.call(self);
self.transactionIcon = ko.observable(false);
}
SlotEditorModel.prototype = Object.create(BaseEditorModel.prototype);
SlotEditorModel.prototype.constructor = SlotEditorModel;
SlotEditorModel.prototype.openEditor = function()
{
blockEditorModel.closeEditor();
BaseEditorModel.prototype.openEditor.call(this);
this.availableBlocksPanel(true);
this.dock();
$('.rkcms-available-blocks').fullHeight();
};
SlotEditorModel.prototype.addBlock = function ()
{
var self = this;
var blocks = self.activeModel.blocks;
var type = $('.rkcms-available-blocks .rkcms-selected-block').attr('data-type');
if (null == type) {
type = "Text";
}
var position = 1;
var slotName = self.activeModel.slotName;
var next = parseInt(self.activeModel.next()) + 1;
self.activeModel.next(next);
var objBlock = JSON.parse($('.rkcms-available-blocks .rkcms-selected-block').attr('data-block'));
objBlock.name = 'block' + next;
objBlock.slot_name = slotName;
queue['rkcms-block-add-' + slotName + '-' + objBlock.name] = {
'entity' : 'block',
'action' : 'add',
'data' : {
'type': type,
'slot': slotName,
'name': objBlock.name,
'position': position,
'page': page,
'language': language,
'country': country,
'direction': "top"
}
};
blocks.splice(position, 0, objBlock);
}; |
/**
* Module dependencies.
*/
var util = require('util')
, OAuthStrategy = require('passport-oauth').OAuthStrategy
, InternalOAuthError = require('passport-oauth').InternalOAuthError;
/**
* `Strategy` constructor.
*
* The Xing authentication strategy authenticates requests by delegating to
* Xing using the OAuth protocol.
*
* Applications must supply a `verify` callback which accepts a `token`,
* `tokenSecret` and service-specific `profile`, and then calls the `done`
* callback supplying a `user`, which should be set to `false` if the
* credentials are not valid. If an exception occured, `err` should be set.
*
* Options:
* - `consumerKey` identifies client to Xing
* - `consumerSecret` secret used to establish ownership of the consumer key
* - `callbackURL` URL to which Xing will redirect the user after obtaining authorization
*
* Examples:
*
* passport.use(new XingStrategy({
* consumerKey: '123-456-789',
* consumerSecret: 'shhh-its-a-secret'
* callbackURL: 'https://www.example.net/auth/xing/callback'
* },
* function(token, tokenSecret, profile, done) {
* User.findOrCreate(..., function (err, user) {
* done(err, user);
* });
* }
* ));
*
* @param {Object} options
* @param {Function} verify
* @api public
*/
function Strategy(options, verify) {
options = options || {};
options.requestTokenURL = options.requestTokenURL || 'https://api.xing.com/v1/request_token';
options.accessTokenURL = options.accessTokenURL || 'https://api.xing.com/v1/access_token';
options.userAuthorizationURL = options.userAuthorizationURL || 'https://api.xing.com/v1/authorize';
options.sessionKey = options.sessionKey || 'oauth:xing';
OAuthStrategy.call(this, options, verify);
this.name = 'xing';
this._profileFields = options.profileFields || null;
}
/**
* Inherit from `OAuthStrategy`.
*/
util.inherits(Strategy, OAuthStrategy);
/**
* Authenticate request by delegating to Xing using OAuth.
*
* @param {Object} req
* @api protected
*/
Strategy.prototype.authenticate = function(req) {
// When a user denies authorization on Xing, they are presented with a
// link to return to the application in the following format:
//
// http://www.example.com/auth/xing/callback?oauth_problem=user_refused
//
// Following the link back to the application is interpreted as an
// authentication failure.
if (req.query && req.query.oauth_problem) {
return this.fail();
}
// Call the base class for standard OAuth authentication.
OAuthStrategy.prototype.authenticate.call(this, req);
}
/**
* Retrieve user profile from Xing.
*
* This function constructs a normalized profile, with the following properties:
*
* - `id`
* - `displayName`
* - `name.familyName`
* - `name.givenName`
*
* @param {String} token
* @param {String} tokenSecret
* @param {Object} params
* @param {Function} done
* @api protected
*/
Strategy.prototype.userProfile = function(token, tokenSecret, params, done) {
var url = 'https://api.xing.com/v1/users/me.json?fields=id,first_name,last_name,display_name,active_email,page_name,permalink,gender,photo_urls,birth_date';
if (this._profileFields) {
var fields = this._convertProfileFields(this._profileFields);
url = 'https://api.xing.com/v1/users/me.json?fields=' + fields;
}
this._oauth.get(url, token, tokenSecret, function (err, body, res) {
if (err) { return done(new InternalOAuthError('failed to fetch user profile', err)); }
try {
var json = JSON.parse(body);
var profile = { provider: 'xing' };
// Xing returns an array of user, currently only the first is used
var user = json.users[0];
profile.id = user.id;
profile.displayName = user.display_name;
profile.name = { familyName: user.last_name,
givenName: user.first_name };
// The following fields are optional and only populated if they are provided by Xing
if (user.page_name) { profile.username = user.page_name };
if (user.permalink) { profile.profileUrl = user.permalink };
if (user.gender) { profile.gender = user.gender }
if (user.birth_date && user.birth_date.year && user.birth_date.month && user.birth_date.day) {
profile.birthday = new Date(user.birth_date.year,
user.birth_date.month,
user.birth_date.day);
}
profile.emails = [];
if (user.active_email) { profile.emails.push({type: "home", value: user.active_email, primary: true}); };
if (user.private_address) { profile.emails.push({type: "home", value: user.private_address.email}); };
if (user.business_address) { profile.emails.push({type: "work", value: user.business_address.email}); };
if (profile.emails.length === 0) { delete profile.emails };
if (user.photo_urls) {
profile.photos = [];
Object.keys(user.photo_urls).forEach(function(key) {
profile.photos.push({value: user.photo_urls[key],
type: key});
});
}
profile._raw = body;
profile._json = user;
done(null, profile);
} catch(e) {
done(e);
}
});
}
Strategy.prototype._convertProfileFields = function(profileFields) {
var map = {
'id': 'id',
'displayName': 'display_name',
'name': ['first_name', 'last_name'],
'emails': 'active_email',
'photos': 'photo_urls',
'profileUrl': 'permalink',
'gender': 'gender',
'username': 'page_name',
'birthday': 'birth_date'
};
var fields = ['id', 'first_name', 'last_name', 'display_name'];
profileFields.forEach(function(f) {
// return raw Xing profile field to support the many fields that don't
// map cleanly to Portable Contacts
if (typeof map[f] === 'undefined') { return fields.push(f); };
if (Array.isArray(map[f])) {
Array.prototype.push.apply(fields, map[f]);
} else {
fields.push(map[f]);
}
});
// Make sure the fields are unique
var unique = [];
for (var i = 0; i < fields.length; i++) {
if (unique.indexOf(fields[i]) == -1) {
unique.push(fields[i]);
}
}
return unique.join(',');
}
/**
* Expose `Strategy`.
*/
module.exports = Strategy;
|
importScripts('../command-block-utils.js', '../main.js')
const log = console.log
onmessage = function(e) {
if (e.data === 'ENABLE_DEBUG') {
console.log = log
console.log('Enabled console logging!')
return
} else if (e.data === 'DISABLE_DEBUG') {
console.log = () => {}
log('Disabled console logging!')
return
}
const code = e.data
const p = new Program()
let stack
stack = p.compile(code)
stack = p.handleLabels(stack)
const command = CBU.summonStack(stack)
postMessage(command)
}
|
'use strict';
module.exports = function (t, a) {
var anchor;
a.throws(function () {
t({});
}, "Other");
if (typeof document !== 'undefined') {
anchor = document.createElement('a');
a(t(anchor), anchor, "Anchor");
}
};
|
import Ember from 'ember';
export default Ember.Route.extend({
model: function () {
return Ember.RSVP.hash({
posts: this.store.findAll('post'),
pages: this.store.findAll('page'),
events: this.store.findAll('event'),
todos: this.store.findAll('todo'),
opportunities: this.store.findAll('opportunity'),
emails: this.store.findAll('email'),
settings: this.store.findAll('setting'),
// s: this.store.findAll(''),
// s: this.store.findAll('')
})
},
});
|
exports.Router = require('./router');
exports.Client = require('./client');
exports.Server = require('./server');
exports.Proxy = require('./proxy');
exports.Publisher = require('./publisher');
exports.Subscriber = require('./subscriber');
|
var searchData=
[
['memorylocation',['MemoryLocation',['../struct_memory_location.html',1,'']]]
];
|
var gamma = require('gamma')
function factorialln(n) {
if (n < 0) {
return -1.0
} else if (n === 0 || n === 1) {
// prevents rounding errors due to gamma approximation
return 0.0
} else {
return gamma.log(n + 1.0)
}
}
module.exports = factorialln
|
import React, { Component, PropTypes } from 'react';
import THREE from 'three';
import { browserHistory } from 'react-router';
import { connect } from 'react-redux';
import {
commonResources, gameResources, PausedScreenResources,
StaticEntitiesResources, TitleScreenResources,
} from '../../resources';
@connect(
state => {
const { letters, shaders } = state;
const lettersArray = Object.values( letters[ 'Sniglet Regular' ] );
const shadersArray = Object.values( shaders ).map( shader => shader.resource );
return { lettersArray, shadersArray };
}
)
export default class GameResources extends Component {
render() {
const {
lettersArray, shadersArray,
} = this.props;
return <resources>
{ lettersArray }
{ shadersArray }
{ commonResources }
{ gameResources }
{ PausedScreenResources }
{ StaticEntitiesResources }
{ TitleScreenResources }
</resources>;
}
}
|
/*
* jquery.localLanding
* https://github.com/matt/jquery.localLanding
*
* Copyright (c) 2012 Matt McManus
* Licensed under the MIT, GPL licenses.
*/
/*
options = {
css : '',
languages: {
es: {
url: '',
text: '',
src: ''
},
ar: {
url: '',
text: '',
src: ''
},
zh: {
url: '',
text: '',
src: ''
}
}
}
Process:
1. Detect proper language
2. Load CSS
3. Drop element in
*/
(function($) {
// Mozilla uses .language, IE uses .userLanguage. Strip out specific localities,
// high level language is fine
$.lang = navigator.language.substr(0,2) || navigator.userLanguage.substr(0,2);
$.localLanding = function(options) {
if (options.languages[$.lang]) {
var lang = options.languages[$.lang], a = [];
// Load the CSS file if one is specified
if (options.css) { $('head').append('<link rel="stylesheet" href="http://cms-staging.arcadia.edu/css/activeDataX.css" type="text/css" />'); }
a.push('<a id="localLanding" href="'+lang.url+'" ');
if (lang.src) {
a.push('class="ir" style="background-image:url('+lang.src+')"');
}
a.push('>'+lang.text+'</a>');
$(a.join('')).appendTo('body');
}
};
}(jQuery));
|
arr = [
"thumb",
"index",
"middle",
"ring",
"pinky",
"ring",
"middle",
"index"
];
list = [];
for (var i = 1, j=0; i < 100; ++i) {
list[i] = arr[j];
if (j === 7)
j = 0;
else
++j;
}
function count(n) {
// 1: thumb
// 2: index
// 3: middle
// 4: ring
// 5: pinky
// 6: ring
// 7: middle
// 8: index
// 9: thumb
// 10: index
// ...
// 1 == 9
// 2 == 10
// ...
n = n % 8;
switch(n){
case 1:
return "thumb";
case 2:
case 8:
return "index";
case 3:
case 7:
return "middle";
case 4:
case 6:
return "ring";
case 5:
return "pinky";
}
}
console.log(
count(12),
list[12]
);
|
module.exports = {
'...': {
unary: {
name: 'spread',
direction: 'right',
precedence: 19
}
},
'..': {
binary: {
name: 'range',
precedence: 3
}
},
'+': {
binary: {
name: 'add',
fn: function(a, b) {
return a + b;
},
precedence: 13
},
unary:{
name: 'positive',
direction: 'right',
fn: function(a) {
return +a;
},
precedence: 15
}
},
'-': {
binary: {
name: 'subtract',
fn: function(a, b) {
return a - b;
},
precedence: 13
},
unary:{
name: 'negative',
direction: 'right',
fn: function(a) {
return -a;
},
precedence: 15
}
},
'*': {
binary: {
name: 'multiply',
fn: function(a, b) {
return a * b;
},
precedence: 14
}
},
'/': {
binary: {
name: 'divide',
fn: function(a, b) {
return a / b;
},
precedence: 14
}
},
'%': {
binary: {
name: 'remainder',
fn: function(a, b) {
return a % b;
},
precedence: 14
}
},
'in': {
binary: {
name: 'in',
fn: function(a, b) {
return a in b;
},
precedence: 11
}
},
'===': {
binary: {
name: 'exactlyEqual',
fn: function(a, b) {
return a === b;
},
precedence: 10
}
},
'!==': {
binary: {
name: 'netExactlyEqual',
fn: function(a, b) {
return a !== b;
},
precedence: 10
}
},
'==': {
binary: {
name: 'equal',
fn: function(a, b) {
return a == b;
},
precedence: 10
}
},
'!=': {
binary: {
name: 'notEqual',
fn: function(a, b) {
return a != b;
},
precedence: 10
}
},
'>=': {
binary: {
name: 'greaterThanOrEqual',
fn: function(a, b) {
return a >= b;
},
precedence: 11
}
},
'<=': {
binary: {
name: 'lessThanOrEqual',
fn: function(a, b) {
return a <= b;
},
precedence: 11
}
},
'>': {
binary: {
name: 'greaterThan',
fn: function(a, b) {
return a > b;
},
precedence: 11
}
},
'<': {
binary: {
name: 'lessThan',
fn: function(a, b) {
return a < b;
},
precedence: 11
}
},
'&&': {
binary: {
name: 'and',
fn: function(a, b) {
return a && b;
},
precedence: 6
}
},
'||': {
binary: {
name: 'or',
fn: function(a, b) {
return a || b;
},
precedence: 5
}
},
'!': {
unary: {
name: 'not',
direction: 'right',
fn: function(a) {
return !a;
},
precedence: 15
}
},
'&': {
binary: {
name: 'bitwiseAnd',
fn: function(a, b) {
return a & b;
},
precedence: 9
}
},
'^': {
binary: {
name: 'bitwiseXOr',
fn: function(a, b) {
return a ^ b;
},
precedence: 8
}
},
'|': {
binary: {
name: 'bitwiseOr',
fn: function(a, b) {
return a | b;
},
precedence: 7
}
},
'~': {
unary: {
name: 'bitwiseNot',
direction: 'right',
fn: function(a) {
return ~a;
},
precedence: 15
}
},
'typeof': {
unary: {
name: 'typeof',
direction: 'right',
fn: function(a) {
return typeof a;
},
precedence: 15
}
},
'<<': {
binary: {
name: 'bitwiseLeftShift',
fn: function(a, b) {
return a << b;
},
precedence: 12
}
},
'>>': {
binary: {
name: 'bitwiseRightShift',
fn: function(a, b) {
return a >> b;
},
precedence: 12
}
},
'>>>': {
binary: {
name: 'bitwiseUnsignedRightShift',
fn: function(a, b) {
return a >>> b;
},
precedence: 12
}
},
'?': {
trinary: {
name: 'ternary',
trinary: 'tuple',
associativity: 'right',
precedence: 4
}
},
':': {
binary: {
name: 'tuple',
precedence: 3
}
}
}; |
var ada__pmmh_8h =
[
[ "AdaPmmh", "classAdaPmmh.html", "classAdaPmmh" ],
[ "Mat", "ada__pmmh_8h.html#ae601f56a556993079f730483c574356f", null ],
[ "Vec", "ada__pmmh_8h.html#a4c7df05c6f5e8a0d15ae14bcdbc07152", null ]
]; |
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"/KoreBot.js":[function(require,module,exports){
var clients = require('./index.js');
var EventEmitter = require('events');
var inherits = require('inherits');
var bind = require('lodash').bind;
var isFunction = require('lodash').isFunction;
var RTM_CLIENT_EVENTS = clients.CLIENT_EVENTS.RTM;
var RTM_EVENTS = clients.RTM_EVENTS;
function KoreBot() {
EventEmitter.call(this);
this.WebClient = null;
this.RtmClient = null;
this.options = {};
this.accessToken = null;
this.initialized = false;
}
inherits(KoreBot, EventEmitter);
KoreBot.prototype.emit = function emit() {
KoreBot.super_.prototype.emit.apply(this, arguments);
};
KoreBot.prototype.sendMessage = function(message,optCb) {
if(this.initialized){
message["resourceid"] = '/bot.message';
message["botInfo"] = this.options.botInfo || {};
this.RtmClient.sendMessage(message,optCb);
}else{
if(optCb){
optCb(true,"Bot is Initializing...Please try again");
}
}
};
KoreBot.prototype.onMessage = function(msg) {
this.emit(RTM_EVENTS.MESSAGE, msg);
};
KoreBot.prototype.close = function() {
if (this.RtmClient) {
this.RtmClient._close();
}
};
KoreBot.prototype.onHistory = function(err, data) {
};
KoreBot.prototype.getHistory = function(options) {
//@@TODO --??
this.WebClient.history.history({}, bind(this.onHistory, this));
};
KoreBot.prototype.sync = function(options) {
//@@TODO --??
};
KoreBot.prototype.onOpenWSConnection = function(msg) {
this.initialized = true;
this.emit(RTM_CLIENT_EVENTS.RTM_CONNECTION_OPENED, {});
};
KoreBot.prototype.onLogIn = function(err, data) {
this.accessToken = data.authorization.accessToken;
this.options.accessToken = this.accessToken;
this.WebClient.user.accessToken = this.accessToken;
this.RtmClient = new clients.KoreRtmClient({}, this.options);
this.RtmClient.start({"botInfo":this.options.botInfo});
this.RtmClient.on(RTM_EVENTS.MESSAGE,bind(this.onMessage, this));
this.RtmClient.on(RTM_CLIENT_EVENTS.RTM_CONNECTION_OPENED,bind(this.onOpenWSConnection, this));
};
KoreBot.prototype.logIn = function(err, data) {
if (err) {
//TODO::??
} else {
this.options = data;
this.claims = data.assertion;
this.WebClient = new clients.KoreWebClient({}, this.options);
this.WebClient.claims = this.claims;
this.WebClient.login.login({"assertion":data.assertion,"botInfo":this.options.botInfo}, bind(this.onLogIn, this));
}
};
KoreBot.prototype.generateUUID = function() {
var d = new Date().getTime();
if(window.performance && typeof window.performance.now === "function"){
d += performance.now(); //use high-precision timer if available
}
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (d + Math.random()*16)%16 | 0;
d = Math.floor(d/16);
return (c=='x' ? r : (r&0x3|0x8)).toString(16);
});
return uuid;
};
KoreBot.prototype.anonymous = function(options){
var korecookie = localStorage.getItem("korecom");
// if(korecookie)
// korecookie = JSON.parse(korecookie);
var uuid = (korecookie) || this.generateUUID();
localStorage.setItem("korecom", uuid);
if(!options.clientId){
console.log("clientId should be there for anonymous user");
return;
}
var assertion = {};
assertion.issuer = options.clientId;
assertion.subject = uuid;
options.assertion = assertion;
this.options = options;
this.claims = options.assertion;
this.WebClient = new clients.KoreWebClient({}, this.options);
this.WebClient.claims = this.claims;
this.WebClient.anonymouslogin.login({
"assertion": options.assertion,
"botInfo":this.options.botInfo
}, bind(this.onLogIn, this));
};
/*
Example of options ::
{
assertion : function(options,callBack){
},
isLoggedIn : true/false,
clientId : "sadhash123",
orgId : "1125rtrrt"
}
*/
KoreBot.prototype.init = function(options) {
options = options || {};
this.options = options;
if(options.isLoggedIn){
if(isFunction(options.assertionFn)){
options.assertionFn(options,bind(this.logIn, this));
}else{
//TODO::??
}
}else{
this.anonymous(options);
//TODO::??
}
};
module.exports.instance = function(){
return new KoreBot();
};
},{"./index.js":1,"events":25,"inherits":19,"lodash":20}],1:[function(require,module,exports){
var events = require('./lib/clients/events');
module.exports= {
KoreWebClient: require('./lib/clients/web/client'),
KoreRtmClient: require('./lib/clients/rtm/client'),
CLIENT_EVENTS: {
WEB: events.CLIENT_EVENTS.WEB,
RTM: events.CLIENT_EVENTS.RTM,
},
RTM_EVENTS: events.RTM_EVENTS,
RTM_MESSAGE_SUBTYPES: events.RTM_MESSAGE_SUBTYPES,
};
},{"./lib/clients/events":4,"./lib/clients/rtm/client":8,"./lib/clients/web/client":16}],2:[function(require,module,exports){
var EventEmitter = require('events');
var async = require('async');
var bind = require('lodash').bind;
var inherits = require('inherits');
var retry = require('retry');
var urlJoin = require('url-join');
var WEB_CLIENT_EVENTS = require('./events/client').WEB;
var helpers = require('./helpers');
var requestsTransport = require('./transports/request').requestTransport;
function BaseAPIClient(token, opts) {
EventEmitter.call(this);
this._token = token;
this.koreAPIUrl = opts.koreAPIUrl || 'https://app.kore.com/api/';
this.transport = opts.transport || requestsTransport;
this.userAgent ;
this._requestQueue = async.priorityQueue(
bind(this._callTransport, this),
opts.maxRequestConcurrency
);
this._createFacets();
}
inherits(BaseAPIClient, EventEmitter);
BaseAPIClient.prototype.emit = function emit() {
BaseAPIClient.super_.prototype.emit.apply(this, arguments);
};
BaseAPIClient.prototype._createFacets = function _createFacets() {
};
BaseAPIClient.prototype._callTransport = function _callTransport(task, queueCb) {
var args = task.args;
var cb = task.cb;
var _this = this;
var retryOp = retry.operation(this.retryConfig);
var handleTransportResponse = function handleTransportResponse(err, headers, statusCode, body) {
var headerSecs;
var headerMs;
var httpErr;
var jsonResponse;
var jsonParseErr;
if (err) {
if (!retryOp.retry(err)) {
cb(retryOp.mainError(), null);
} else {
return;
}
}
if (statusCode !== 200) {
if (statusCode === 429) {
_this._requestQueue.pause();
headerSecs = parseInt(headers['Retry-After'], 10);
headerMs = headerSecs * 1000;
setTimeout(function retryRateLimitedRequest() {
_this.transport(args, handleTransportResponse);
_this._requestQueue.resume();
}, headerMs);
_this.emit(WEB_CLIENT_EVENTS.RATE_LIMITED, headerSecs);
} else {
httpErr = new Error('Unable to process request, received bad ' + statusCode + ' error');
if (!retryOp.retry(httpErr)) {
cb(httpErr, null);
} else {
return;
}
}
} else {
cb(null, body);
}
queueCb();
};
retryOp.attempt(function attemptTransportCall() {
_this.transport(args, handleTransportResponse);
});
};
BaseAPIClient.prototype.makeAPICall = function makeAPICall(endpoint, optData, optCb) {
var apiCallArgs = helpers.getAPICallArgs(this._token, optData, optCb);
var args = {
url: urlJoin(this.koreAPIUrl, endpoint),
data: apiCallArgs.data,
headers: {
'User-Agent': this.userAgent,
"content-type":'application/json'
},
};
if(optData && optData.opts && optData.opts.authorization)
args.headers.Authorization = optData.opts.authorization;
this._requestQueue.push({
args: args,
cb: apiCallArgs.cb,
});
};
module.exports = BaseAPIClient;
},{"./events/client":3,"./helpers":7,"./transports/request":9,"async":17,"events":25,"inherits":19,"lodash":20,"retry":21,"url-join":24}],3:[function(require,module,exports){
/**
* API client events.
*/
module.exports.WEB = {
RATE_LIMITED: 'rate_limited',
};
module.exports.RTM = {
CONNECTING: 'connecting', // the rtm.start API call has been made, but the
// response has not come back
AUTHENTICATED: 'authenticated', // rtm.start returned successfully with a websocket
// URL to connect to
WS_OPENING: 'ws_opening', // the underlying websocket connection is being
// opened
WS_OPENED: 'ws_opened', // the underlying websocket connection has opened
// and messages can be received from the remote
RTM_CONNECTION_OPENED: 'open', // the remote server has acked the socket and sent a
// `hello` message, the connection is now live and
// can be used to send messages
DISCONNECT: 'disconnect', // the RTM client has disconnected and will not try
// to reconnect again automatically
UNABLE_TO_RTM_START: 'unable_to_rtm_start', // the rtm.start API call failed in some way, this
// may be recoverable
WS_CLOSE: 'ws_close', // the underlying websocket connection was closed. A
// reconnect may be attempted after this
WS_ERROR: 'ws_error', // the underlying websocket connection threw an
// an error
ATTEMPTING_RECONNECT: 'attempting_reconnect', // the client is attempting to initiate a reconnect
RAW_MESSAGE: 'raw_message', // a message was received from the RTM API. This
// will also contain the raw message payload that
// was sent from kore
};
},{}],4:[function(require,module,exports){
module.exports = {
CLIENT_EVENTS: {
WEB: require('./client').WEB,
RTM: require('./client').RTM,
},
RTM_EVENTS: require('./rtm').EVENTS,
RTM_MESSAGE_SUBTYPES: require('./rtm').MESSAGE_SUBTYPES,
};
},{"./client":3,"./rtm":5}],5:[function(require,module,exports){
/**
* Events sent by the kore RTM API.
*/
module.exports.EVENTS = {
HELLO: 'hello',
MESSAGE: 'message',
};
module.exports.MESSAGE_SUBTYPES = {
BOT_MESSAGE: 'bot_message',
ME_MESSAGE: 'me_message',
};
},{}],6:[function(require,module,exports){
/**
*
*/
var RTM_EVENTS = require('./rtm').EVENTS;
/**
* @param {string} subtype
* @param {string=} delim
*/
var makeMessageEventWithSubtype = function makeMessageEventWithSubtype(subtype, delim) {
return [RTM_EVENTS.MESSAGE, subtype].join(delim || '::');
};
module.exports.makeMessageEventWithSubtype = makeMessageEventWithSubtype;
},{"./rtm":5}],7:[function(require,module,exports){
/**
* Helpers for working with kore API clients.
*/
var assign = require('lodash').assign;
var isFunction = require('lodash').isFunction;
var isUndefined = require('lodash').isUndefined;
var isString = require('lodash').isString;
var forEach = require('lodash').forEach;
var noop = require('lodash').noop;
var getData = function getData(data, token) {
var newData = assign({}, data ? data.opts || {} : {});
forEach(data || {}, function getValidData(val, key) {
if (!isUndefined(val) && val !== null && key !== 'opts') {
if (key === 'attachments') {
if (isString(val)) {
newData[key] = val;
} else {
newData[key] = JSON.stringify(val);
}
} else {
newData[key] = val;
}
}
});
if (token) {
newData.token = token;
}
return newData;
};
var getAPICallArgs = function getAPICallArgs(token, optData, optCb) {
var data;
var cb;
if (arguments.length === 1) {
// Pass in a no-op function here to avoid adding more conditionals in the _callTransport fn
cb = noop;
data = getData({}, token);
} else if (arguments.length === 2) {
if (isFunction(arguments[1])) {
cb = arguments[1];
data = getData({}, token);
} else {
cb = noop;
data = getData(optData, token);
}
} else if (arguments.length === 3) {
cb = optCb || noop;
data = getData(optData, token);
}
return {
cb: cb,
data: data,
};
};
module.exports.getData = getData;
module.exports.getAPICallArgs = getAPICallArgs;
},{"lodash":20}],8:[function(require,module,exports){
var bind = require('lodash').bind;
var cloneDeep = require('lodash').cloneDeep;
var contains = require('lodash').contains;
var inherits = require('inherits');
var isUndefined = require('lodash').isUndefined;
var RTM_API_EVENTS = require('../events/rtm').EVENTS;
var RTM_CLIENT_INTERNAL_EVENT_TYPES = [
'pong',
RTM_API_EVENTS.HELLO,
];
var UNRECOVERABLE_RTM_START_ERRS = [
'not_authed',
'invalid_auth',
'account_inactive',
];
var CLIENT_EVENTS = require('../events/client').RTM;
var BaseAPIClient = require('../client');
var RtmApi = require('../web/apis').RtmApi;
var makeMessageEventWithSubtype = require('../events/utils').makeMessageEventWithSubtype;
var wsSocketFn = require('../transports/ws');
function KoreRTMClient(token, opts) {
var clientOpts = opts || {};
clientOpts.maxRequestConcurrency = 1;
BaseAPIClient.call(this, token, clientOpts);
this._socketFn = clientOpts.socketFn || wsSocketFn;
this.ws = undefined;
this.MAX_RECONNECTION_ATTEMPTS = clientOpts.maxReconnectionAttempts || 10;
this.RECONNECTION_BACKOFF = clientOpts.reconnectionBackoff || 3000;
this.MAX_PONG_INTERVAL = clientOpts.maxPongInterval || 10000;
this.WS_PING_INTERVAL = clientOpts.wsPingInterval || 5000;
this.autoReconnect = clientOpts.autoReconnect !== false;
this.connected = false;
this.authenticated = false;
this.activeUserId = undefined;
this._pendingMessages = {};
this._connAttempts = 0;
this._connecting = false;
this._reconnecting = false;
this.user = {};
this.user.accessToken = clientOpts.accessToken;
this.botInfo = clientOpts.botInfo || {};
}
inherits(KoreRTMClient, BaseAPIClient);
/** @inheritDoc */
KoreRTMClient.prototype._createFacets = function _createFacets() {
KoreRTMClient.super_.prototype._createFacets.call(this);
this._rtm = new RtmApi(this);
};
KoreRTMClient.prototype.start = function start(opts) {
// Check whether the client is currently attempting to connect to the RTM API.
if (!this._connecting) {
this.emit(CLIENT_EVENTS.CONNECTING);
this._connecting = true;
opts = opts || {"botInfo":this.botInfo};
opts.authorization = "bearer "+ this.user.accessToken;
this._rtm.start(opts, bind(this._onStart, this));
}
};
KoreRTMClient.prototype.nextMessageId = function nextMessageId() {
this._messageId = this._messageId || 1;
return this._messageId++;
};
KoreRTMClient.prototype._onStart = function _onStart(err, data) {
var errMsg;
var __reconnect__ = this._reconnecting?true:false;
this._connecting = false;
this._reconnecting = false;
try{
data = data;
}
catch(e){
console.log(e && e.stack);
}
if (err || !data.url) {
this.emit(CLIENT_EVENTS.UNABLE_TO_RTM_START, err || data.error);
// Any of these mean this client is unusable, so don't attempt to auto-reconnect
if (data && contains(UNRECOVERABLE_RTM_START_ERRS, data.error)) {
errMsg = 'unrecoverable failure connecting to the RTM API';
this.disconnect(errMsg, data.error);
} else {
this.authenticated = false;
if (this.autoReconnect) {
this.reconnect();
}
}
} else {
if(__reconnect__){
data.url = data.url + "&isReconnect=true"
}
this.authenticated = true;
//this.activeUserId = data.self.id;
this.emit(CLIENT_EVENTS.AUTHENTICATED, data);
this.connect(data.url);
}
};
//To close the ws on refresh,close, and on logout.
KoreRTMClient.prototype._close = function _close() {
this.autoReconnect = false;
this._safeDisconnect();
};
KoreRTMClient.prototype._safeDisconnect = function _safeDisconnect() {
if (this.ws) {
// Stop listening to the websocket's close event, so that the auto-reconnect logic doesn't fire
// twice.
//this.ws.removeAllListeners('close');
this.ws.close();
}
this.authenticated = false;
this.connected = false;
};
KoreRTMClient.prototype.connect = function connect(socketUrl) {
this.emit(CLIENT_EVENTS.WS_OPENING,{});
this.ws = this._socketFn(socketUrl);
this.ws.onopen = bind(this.handleWsOpen, this);
this.ws.onmessage = bind(this.handleWsMessage, this);
this.ws.onerror = bind(this.handleWsError, this);
this.ws.onclose = bind(this.handleWsClose, this);
this.ws.onping = bind(this.handleWsPing, this);
};
KoreRTMClient.prototype.disconnect = function disconnect(optErr, optCode) {
this.emit(CLIENT_EVENTS.DISCONNECT, optErr, optCode);
this.autoReconnect = false;
this._safeDisconnect();
};
KoreRTMClient.prototype.reconnect = function reconnect() {
console.log("in reconnect");
if (!this._reconnecting) {
this.emit(CLIENT_EVENTS.ATTEMPTING_RECONNECT);
this._reconnecting = true;
this._safeDisconnect();
this._connAttempts++;
if (this._connAttempts > this.MAX_RECONNECTION_ATTEMPTS) {
throw new Error('unable to connect to kore RTM API, failed after max reconnection attempts');
}
setTimeout(bind(this.start, this), this._connAttempts * this.RECONNECTION_BACKOFF);
}
};
KoreRTMClient.prototype.handleWsOpen = function handleWsOpen() {
this.connected = true;
this.emit('open',{data:{}});
this._connAttempts = 0;
};
KoreRTMClient.prototype.handleWsMessage = function handleWsMessage(wsMsg) {
var message;
this.emit("message", wsMsg);
try {
message = JSON.parse(wsMsg);
} catch (err) {
return;
}
if (contains(RTM_CLIENT_INTERNAL_EVENT_TYPES, message.type)) {
this._handleWsMessageInternal(message.type, message);
} else {
this._handleWsMessageViaEventHandler(message.type, message);
}
};
KoreRTMClient.prototype._handleWsMessageInternal = function _handleWsMessageInternal(
messageType, message) {
if (messageType === RTM_API_EVENTS.HELLO) {
this._handleHello();
}
};
KoreRTMClient.prototype._handleWsMessageViaEventHandler = function _handleWsMessageViaEventHandler(
messageType, message) {
var replyTo;
if (messageType === RTM_API_EVENTS.MESSAGE) {
replyTo = message.reply_to;
if (replyTo) {
if (this._pendingMessages[replyTo]) {
delete this._pendingMessages[replyTo];
} else {
return;
}
}
}
this.emit(messageType, message);
if (messageType === RTM_API_EVENTS.MESSAGE && !isUndefined(message.subtype)) {
this.emit(makeMessageEventWithSubtype(message.subtype), message);
}
};
KoreRTMClient.prototype.handleWsError = function handleWsError(err) {
this.emit(CLIENT_EVENTS.WS_ERROR, err);
};
KoreRTMClient.prototype.handleWsClose = function handleWsClose(code, reason) {
this.connected = false;
this.emit(CLIENT_EVENTS.WS_CLOSE, code, reason);
if (this.autoReconnect) {
if (!this._connecting) {
this.reconnect();
}
} else {
this.disconnect('websocket closed with auto-reconnect false on the RTM client');
}
};
KoreRTMClient.prototype.handleWsPing = function handleWsPing() {
if (this.ws.pong) {
this.ws.pong();
}
};
KoreRTMClient.prototype._handleHello = function _handleHello() {
this.connected = true;
this.emit(CLIENT_EVENTS.RTM_CONNECTION_OPENED);
};
KoreRTMClient.prototype.sendMessage = function sendMessage(message, optCb) {
this.send(message, optCb);
};
KoreRTMClient.prototype.send = function send(message, optCb) {
var wsMsg = cloneDeep(message);
var jsonMessage;
var err;
var _this = this;
if (this.connected) {
wsMsg.id = wsMsg.clientMessageId || this.nextMessageId();
jsonMessage = JSON.stringify(wsMsg);
this._pendingMessages[wsMsg.id] = wsMsg;
this.ws.send(jsonMessage, undefined, function handleWsMsgResponse(wsRespErr) {
if (!isUndefined(wsRespErr)) {
}
if (!isUndefined(optCb)) {
optCb(wsRespErr);
}
});
} else {
err = 'ws not connected, unable to send message';
if (!isUndefined(optCb)) {
optCb(new Error(err));
}
}
};
module.exports = KoreRTMClient;
},{"../client":2,"../events/client":3,"../events/rtm":5,"../events/utils":6,"../transports/ws":10,"../web/apis":13,"inherits":19,"lodash":20}],9:[function(require,module,exports){
/**
* Simple transport using the node request library.
*/
var has = require('lodash').has;
var partial = require('lodash').partial;
var request = require('browser-request');
var handleRequestTranportRes = function handleRequestTranportRes(cb, err, response, body) {
var headers;
var statusCode;
if (err) {
headers = response ? response.headers || {} : {};
statusCode = response ? response.statusCode || null : null;
cb(err, headers, statusCode, body);
} else {
cb(err, response.headers, response.statusCode, body);
}
};
var getRequestTransportArgs = function getReqestTransportArgs(args) {
var transportArgs = {
url: args.url,
headers: args.headers,
};
if (has(args.data, 'file')) {
transportArgs.formData = args.data;
} else {
transportArgs.json = args.data;
}
return transportArgs;
};
var requestTransport = function requestTransport(args, cb) {
var requestArgs = getRequestTransportArgs(args);
request.post(requestArgs, partial(handleRequestTranportRes, cb));
};
module.exports.requestTransport = requestTransport;
},{"browser-request":18,"lodash":20}],10:[function(require,module,exports){
var wsTransport = function wsTransport(socketUrl, opts) {
var wsTransportOpts = opts || {};
var wsOpts = {};
return new WebSocket(socketUrl);
};
module.exports = wsTransport;
},{}],11:[function(require,module,exports){
function BaseApi () {
// body...
}
module.exports = BaseApi;
},{}],12:[function(require,module,exports){
var BaseApi = require('./BaseApi');
var inherits = require('inherits');
function AnonymousLogin(client) {
this.name = 'anonymouslogin';
this.client = client;
}
inherits(AnonymousLogin, BaseApi);
AnonymousLogin.prototype.login = function login(opts, optCb) {
opts = opts || {};
var args = {
opts: opts,
};
return this.client.makeAPICall('/oAuth/token/jwtgrant/anonymous', args, optCb);
};
module.exports = AnonymousLogin;
},{"./BaseApi":11,"inherits":19}],13:[function(require,module,exports){
module.exports = {
RtmApi: require('./rtm.js'),
LogInApi: require('./login.js'),
AnonymousLogin : require('./anonymouslogin.js'),
};
},{"./anonymouslogin.js":12,"./login.js":14,"./rtm.js":15}],14:[function(require,module,exports){
var BaseApi = require('./BaseApi');
var inherits = require('inherits');
function LogInApi(client) {
this.name = 'login';
this.client = client;
}
inherits(LogInApi, BaseApi);
LogInApi.prototype.login = function login(opts, optCb) {
opts = opts || {};
var args = {
opts: opts,
};
return this.client.makeAPICall('/oAuth/token/jwtgrant', args, optCb);
};
module.exports = LogInApi;
},{"./BaseApi":11,"inherits":19}],15:[function(require,module,exports){
var BaseApi = require('./BaseApi');
var inherits = require('inherits');
function RtmApi(client) {
this.name = 'rtm';
this.client = client;
}
inherits(RtmApi, BaseApi);
RtmApi.prototype.start = function start(opts, optCb) {
var args = {
opts: opts,
};
return this.client.makeAPICall('/rtm/start', args, optCb);
};
module.exports = RtmApi;
},{"./BaseApi":11,"inherits":19}],16:[function(require,module,exports){
var bind = require('lodash').bind;
var forEach = require('lodash').forEach;
var inherits = require('inherits');
var BaseAPIClient = require('../client');
var apis = require('./apis/index');
function WebAPIClient(token, opts) {
var clientOpts = opts || {};
BaseAPIClient.call(this, token, clientOpts);
this.claims = opts.claims;
this.retryConfig = clientOpts.retryConfig || {
retries: 5,
factor: 3.9,
};
this.user = {};
}
inherits(WebAPIClient, BaseAPIClient);
WebAPIClient.prototype._createFacets = function _createFacets() {
var newFacet;
var makeAPICall;
WebAPIClient.super_.prototype._createFacets.call(this);
makeAPICall = bind(this.makeAPICall, this);
forEach(apis, function registerWebClientFacet(Facet) {
newFacet = new Facet(this);
this[newFacet.name] = newFacet;
}, this);
};
module.exports = WebAPIClient;
},{"../client":2,"./apis/index":13,"inherits":19,"lodash":20}],17:[function(require,module,exports){
(function (process,global){
/*!
* async
* https://github.com/caolan/async
*
* Copyright 2010-2014 Caolan McMahon
* Released under the MIT license
*/
(function () {
var async = {};
function noop() {}
function identity(v) {
return v;
}
function toBool(v) {
return !!v;
}
function notId(v) {
return !v;
}
// global on the server, window in the browser
var previous_async;
// Establish the root object, `window` (`self`) in the browser, `global`
// on the server, or `this` in some virtual machines. We use `self`
// instead of `window` for `WebWorker` support.
var root = typeof self === 'object' && self.self === self && self ||
typeof global === 'object' && global.global === global && global ||
this;
if (root != null) {
previous_async = root.async;
}
async.noConflict = function () {
root.async = previous_async;
return async;
};
function only_once(fn) {
return function() {
if (fn === null) throw new Error("Callback was already called.");
fn.apply(this, arguments);
fn = null;
};
}
function _once(fn) {
return function() {
if (fn === null) return;
fn.apply(this, arguments);
fn = null;
};
}
//// cross-browser compatiblity functions ////
var _toString = Object.prototype.toString;
var _isArray = Array.isArray || function (obj) {
return _toString.call(obj) === '[object Array]';
};
// Ported from underscore.js isObject
var _isObject = function(obj) {
var type = typeof obj;
return type === 'function' || type === 'object' && !!obj;
};
function _isArrayLike(arr) {
return _isArray(arr) || (
// has a positive integer length property
typeof arr.length === "number" &&
arr.length >= 0 &&
arr.length % 1 === 0
);
}
function _arrayEach(arr, iterator) {
var index = -1,
length = arr.length;
while (++index < length) {
iterator(arr[index], index, arr);
}
}
function _map(arr, iterator) {
var index = -1,
length = arr.length,
result = Array(length);
while (++index < length) {
result[index] = iterator(arr[index], index, arr);
}
return result;
}
function _range(count) {
return _map(Array(count), function (v, i) { return i; });
}
function _reduce(arr, iterator, memo) {
_arrayEach(arr, function (x, i, a) {
memo = iterator(memo, x, i, a);
});
return memo;
}
function _forEachOf(object, iterator) {
_arrayEach(_keys(object), function (key) {
iterator(object[key], key);
});
}
function _indexOf(arr, item) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] === item) return i;
}
return -1;
}
var _keys = Object.keys || function (obj) {
var keys = [];
for (var k in obj) {
if (obj.hasOwnProperty(k)) {
keys.push(k);
}
}
return keys;
};
function _keyIterator(coll) {
var i = -1;
var len;
var keys;
if (_isArrayLike(coll)) {
len = coll.length;
return function next() {
i++;
return i < len ? i : null;
};
} else {
keys = _keys(coll);
len = keys.length;
return function next() {
i++;
return i < len ? keys[i] : null;
};
}
}
// Similar to ES6's rest param (http://ariya.ofilabs.com/2013/03/es6-and-rest-parameter.html)
// This accumulates the arguments passed into an array, after a given index.
// From underscore.js (https://github.com/jashkenas/underscore/pull/2140).
function _restParam(func, startIndex) {
startIndex = startIndex == null ? func.length - 1 : +startIndex;
return function() {
var length = Math.max(arguments.length - startIndex, 0);
var rest = Array(length);
for (var index = 0; index < length; index++) {
rest[index] = arguments[index + startIndex];
}
switch (startIndex) {
case 0: return func.call(this, rest);
case 1: return func.call(this, arguments[0], rest);
}
// Currently unused but handle cases outside of the switch statement:
// var args = Array(startIndex + 1);
// for (index = 0; index < startIndex; index++) {
// args[index] = arguments[index];
// }
// args[startIndex] = rest;
// return func.apply(this, args);
};
}
function _withoutIndex(iterator) {
return function (value, index, callback) {
return iterator(value, callback);
};
}
//// exported async module functions ////
//// nextTick implementation with browser-compatible fallback ////
// capture the global reference to guard against fakeTimer mocks
var _setImmediate = typeof setImmediate === 'function' && setImmediate;
var _delay = _setImmediate ? function(fn) {
// not a direct alias for IE10 compatibility
_setImmediate(fn);
} : function(fn) {
setTimeout(fn, 0);
};
if (typeof process === 'object' && typeof process.nextTick === 'function') {
async.nextTick = process.nextTick;
} else {
async.nextTick = _delay;
}
async.setImmediate = _setImmediate ? _delay : async.nextTick;
async.forEach =
async.each = function (arr, iterator, callback) {
return async.eachOf(arr, _withoutIndex(iterator), callback);
};
async.forEachSeries =
async.eachSeries = function (arr, iterator, callback) {
return async.eachOfSeries(arr, _withoutIndex(iterator), callback);
};
async.forEachLimit =
async.eachLimit = function (arr, limit, iterator, callback) {
return _eachOfLimit(limit)(arr, _withoutIndex(iterator), callback);
};
async.forEachOf =
async.eachOf = function (object, iterator, callback) {
callback = _once(callback || noop);
object = object || [];
var iter = _keyIterator(object);
var key, completed = 0;
while ((key = iter()) != null) {
completed += 1;
iterator(object[key], key, only_once(done));
}
if (completed === 0) callback(null);
function done(err) {
completed--;
if (err) {
callback(err);
}
// Check key is null in case iterator isn't exhausted
// and done resolved synchronously.
else if (key === null && completed <= 0) {
callback(null);
}
}
};
async.forEachOfSeries =
async.eachOfSeries = function (obj, iterator, callback) {
callback = _once(callback || noop);
obj = obj || [];
var nextKey = _keyIterator(obj);
var key = nextKey();
function iterate() {
var sync = true;
if (key === null) {
return callback(null);
}
iterator(obj[key], key, only_once(function (err) {
if (err) {
callback(err);
}
else {
key = nextKey();
if (key === null) {
return callback(null);
} else {
if (sync) {
async.setImmediate(iterate);
} else {
iterate();
}
}
}
}));
sync = false;
}
iterate();
};
async.forEachOfLimit =
async.eachOfLimit = function (obj, limit, iterator, callback) {
_eachOfLimit(limit)(obj, iterator, callback);
};
function _eachOfLimit(limit) {
return function (obj, iterator, callback) {
callback = _once(callback || noop);
obj = obj || [];
var nextKey = _keyIterator(obj);
if (limit <= 0) {
return callback(null);
}
var done = false;
var running = 0;
var errored = false;
(function replenish () {
if (done && running <= 0) {
return callback(null);
}
while (running < limit && !errored) {
var key = nextKey();
if (key === null) {
done = true;
if (running <= 0) {
callback(null);
}
return;
}
running += 1;
iterator(obj[key], key, only_once(function (err) {
running -= 1;
if (err) {
callback(err);
errored = true;
}
else {
replenish();
}
}));
}
})();
};
}
function doParallel(fn) {
return function (obj, iterator, callback) {
return fn(async.eachOf, obj, iterator, callback);
};
}
function doParallelLimit(fn) {
return function (obj, limit, iterator, callback) {
return fn(_eachOfLimit(limit), obj, iterator, callback);
};
}
function doSeries(fn) {
return function (obj, iterator, callback) {
return fn(async.eachOfSeries, obj, iterator, callback);
};
}
function _asyncMap(eachfn, arr, iterator, callback) {
callback = _once(callback || noop);
arr = arr || [];
var results = _isArrayLike(arr) ? [] : {};
eachfn(arr, function (value, index, callback) {
iterator(value, function (err, v) {
results[index] = v;
callback(err);
});
}, function (err) {
callback(err, results);
});
}
async.map = doParallel(_asyncMap);
async.mapSeries = doSeries(_asyncMap);
async.mapLimit = doParallelLimit(_asyncMap);
// reduce only has a series version, as doing reduce in parallel won't
// work in many situations.
async.inject =
async.foldl =
async.reduce = function (arr, memo, iterator, callback) {
async.eachOfSeries(arr, function (x, i, callback) {
iterator(memo, x, function (err, v) {
memo = v;
callback(err);
});
}, function (err) {
callback(err, memo);
});
};
async.foldr =
async.reduceRight = function (arr, memo, iterator, callback) {
var reversed = _map(arr, identity).reverse();
async.reduce(reversed, memo, iterator, callback);
};
async.transform = function (arr, memo, iterator, callback) {
if (arguments.length === 3) {
callback = iterator;
iterator = memo;
memo = _isArray(arr) ? [] : {};
}
async.eachOf(arr, function(v, k, cb) {
iterator(memo, v, k, cb);
}, function(err) {
callback(err, memo);
});
};
function _filter(eachfn, arr, iterator, callback) {
var results = [];
eachfn(arr, function (x, index, callback) {
iterator(x, function (v) {
if (v) {
results.push({index: index, value: x});
}
callback();
});
}, function () {
callback(_map(results.sort(function (a, b) {
return a.index - b.index;
}), function (x) {
return x.value;
}));
});
}
async.select =
async.filter = doParallel(_filter);
async.selectLimit =
async.filterLimit = doParallelLimit(_filter);
async.selectSeries =
async.filterSeries = doSeries(_filter);
function _reject(eachfn, arr, iterator, callback) {
_filter(eachfn, arr, function(value, cb) {
iterator(value, function(v) {
cb(!v);
});
}, callback);
}
async.reject = doParallel(_reject);
async.rejectLimit = doParallelLimit(_reject);
async.rejectSeries = doSeries(_reject);
function _createTester(eachfn, check, getResult) {
return function(arr, limit, iterator, cb) {
function done() {
if (cb) cb(getResult(false, void 0));
}
function iteratee(x, _, callback) {
if (!cb) return callback();
iterator(x, function (v) {
if (cb && check(v)) {
cb(getResult(true, x));
cb = iterator = false;
}
callback();
});
}
if (arguments.length > 3) {
eachfn(arr, limit, iteratee, done);
} else {
cb = iterator;
iterator = limit;
eachfn(arr, iteratee, done);
}
};
}
async.any =
async.some = _createTester(async.eachOf, toBool, identity);
async.someLimit = _createTester(async.eachOfLimit, toBool, identity);
async.all =
async.every = _createTester(async.eachOf, notId, notId);
async.everyLimit = _createTester(async.eachOfLimit, notId, notId);
function _findGetResult(v, x) {
return x;
}
async.detect = _createTester(async.eachOf, identity, _findGetResult);
async.detectSeries = _createTester(async.eachOfSeries, identity, _findGetResult);
async.detectLimit = _createTester(async.eachOfLimit, identity, _findGetResult);
async.sortBy = function (arr, iterator, callback) {
async.map(arr, function (x, callback) {
iterator(x, function (err, criteria) {
if (err) {
callback(err);
}
else {
callback(null, {value: x, criteria: criteria});
}
});
}, function (err, results) {
if (err) {
return callback(err);
}
else {
callback(null, _map(results.sort(comparator), function (x) {
return x.value;
}));
}
});
function comparator(left, right) {
var a = left.criteria, b = right.criteria;
return a < b ? -1 : a > b ? 1 : 0;
}
};
async.auto = function (tasks, concurrency, callback) {
if (typeof arguments[1] === 'function') {
// concurrency is optional, shift the args.
callback = concurrency;
concurrency = null;
}
callback = _once(callback || noop);
var keys = _keys(tasks);
var remainingTasks = keys.length;
if (!remainingTasks) {
return callback(null);
}
if (!concurrency) {
concurrency = remainingTasks;
}
var results = {};
var runningTasks = 0;
var hasError = false;
var listeners = [];
function addListener(fn) {
listeners.unshift(fn);
}
function removeListener(fn) {
var idx = _indexOf(listeners, fn);
if (idx >= 0) listeners.splice(idx, 1);
}
function taskComplete() {
remainingTasks--;
_arrayEach(listeners.slice(0), function (fn) {
fn();
});
}
addListener(function () {
if (!remainingTasks) {
callback(null, results);
}
});
_arrayEach(keys, function (k) {
if (hasError) return;
var task = _isArray(tasks[k]) ? tasks[k]: [tasks[k]];
var taskCallback = _restParam(function(err, args) {
runningTasks--;
if (args.length <= 1) {
args = args[0];
}
if (err) {
var safeResults = {};
_forEachOf(results, function(val, rkey) {
safeResults[rkey] = val;
});
safeResults[k] = args;
hasError = true;
callback(err, safeResults);
}
else {
results[k] = args;
async.setImmediate(taskComplete);
}
});
var requires = task.slice(0, task.length - 1);
// prevent dead-locks
var len = requires.length;
var dep;
while (len--) {
if (!(dep = tasks[requires[len]])) {
throw new Error('Has nonexistent dependency in ' + requires.join(', '));
}
if (_isArray(dep) && _indexOf(dep, k) >= 0) {
throw new Error('Has cyclic dependencies');
}
}
function ready() {
return runningTasks < concurrency && _reduce(requires, function (a, x) {
return (a && results.hasOwnProperty(x));
}, true) && !results.hasOwnProperty(k);
}
if (ready()) {
runningTasks++;
task[task.length - 1](taskCallback, results);
}
else {
addListener(listener);
}
function listener() {
if (ready()) {
runningTasks++;
removeListener(listener);
task[task.length - 1](taskCallback, results);
}
}
});
};
async.retry = function(times, task, callback) {
var DEFAULT_TIMES = 5;
var DEFAULT_INTERVAL = 0;
var attempts = [];
var opts = {
times: DEFAULT_TIMES,
interval: DEFAULT_INTERVAL
};
function parseTimes(acc, t){
if(typeof t === 'number'){
acc.times = parseInt(t, 10) || DEFAULT_TIMES;
} else if(typeof t === 'object'){
acc.times = parseInt(t.times, 10) || DEFAULT_TIMES;
acc.interval = parseInt(t.interval, 10) || DEFAULT_INTERVAL;
} else {
throw new Error('Unsupported argument type for \'times\': ' + typeof t);
}
}
var length = arguments.length;
if (length < 1 || length > 3) {
throw new Error('Invalid arguments - must be either (task), (task, callback), (times, task) or (times, task, callback)');
} else if (length <= 2 && typeof times === 'function') {
callback = task;
task = times;
}
if (typeof times !== 'function') {
parseTimes(opts, times);
}
opts.callback = callback;
opts.task = task;
function wrappedTask(wrappedCallback, wrappedResults) {
function retryAttempt(task, finalAttempt) {
return function(seriesCallback) {
task(function(err, result){
seriesCallback(!err || finalAttempt, {err: err, result: result});
}, wrappedResults);
};
}
function retryInterval(interval){
return function(seriesCallback){
setTimeout(function(){
seriesCallback(null);
}, interval);
};
}
while (opts.times) {
var finalAttempt = !(opts.times-=1);
attempts.push(retryAttempt(opts.task, finalAttempt));
if(!finalAttempt && opts.interval > 0){
attempts.push(retryInterval(opts.interval));
}
}
async.series(attempts, function(done, data){
data = data[data.length - 1];
(wrappedCallback || opts.callback)(data.err, data.result);
});
}
// If a callback is passed, run this as a controll flow
return opts.callback ? wrappedTask() : wrappedTask;
};
async.waterfall = function (tasks, callback) {
callback = _once(callback || noop);
if (!_isArray(tasks)) {
var err = new Error('First argument to waterfall must be an array of functions');
return callback(err);
}
if (!tasks.length) {
return callback();
}
function wrapIterator(iterator) {
return _restParam(function (err, args) {
if (err) {
callback.apply(null, [err].concat(args));
}
else {
var next = iterator.next();
if (next) {
args.push(wrapIterator(next));
}
else {
args.push(callback);
}
ensureAsync(iterator).apply(null, args);
}
});
}
wrapIterator(async.iterator(tasks))();
};
function _parallel(eachfn, tasks, callback) {
callback = callback || noop;
var results = _isArrayLike(tasks) ? [] : {};
eachfn(tasks, function (task, key, callback) {
task(_restParam(function (err, args) {
if (args.length <= 1) {
args = args[0];
}
results[key] = args;
callback(err);
}));
}, function (err) {
callback(err, results);
});
}
async.parallel = function (tasks, callback) {
_parallel(async.eachOf, tasks, callback);
};
async.parallelLimit = function(tasks, limit, callback) {
_parallel(_eachOfLimit(limit), tasks, callback);
};
async.series = function(tasks, callback) {
_parallel(async.eachOfSeries, tasks, callback);
};
async.iterator = function (tasks) {
function makeCallback(index) {
function fn() {
if (tasks.length) {
tasks[index].apply(null, arguments);
}
return fn.next();
}
fn.next = function () {
return (index < tasks.length - 1) ? makeCallback(index + 1): null;
};
return fn;
}
return makeCallback(0);
};
async.apply = _restParam(function (fn, args) {
return _restParam(function (callArgs) {
return fn.apply(
null, args.concat(callArgs)
);
});
});
function _concat(eachfn, arr, fn, callback) {
var result = [];
eachfn(arr, function (x, index, cb) {
fn(x, function (err, y) {
result = result.concat(y || []);
cb(err);
});
}, function (err) {
callback(err, result);
});
}
async.concat = doParallel(_concat);
async.concatSeries = doSeries(_concat);
async.whilst = function (test, iterator, callback) {
callback = callback || noop;
if (test()) {
var next = _restParam(function(err, args) {
if (err) {
callback(err);
} else if (test.apply(this, args)) {
iterator(next);
} else {
callback.apply(null, [null].concat(args));
}
});
iterator(next);
} else {
callback(null);
}
};
async.doWhilst = function (iterator, test, callback) {
var calls = 0;
return async.whilst(function() {
return ++calls <= 1 || test.apply(this, arguments);
}, iterator, callback);
};
async.until = function (test, iterator, callback) {
return async.whilst(function() {
return !test.apply(this, arguments);
}, iterator, callback);
};
async.doUntil = function (iterator, test, callback) {
return async.doWhilst(iterator, function() {
return !test.apply(this, arguments);
}, callback);
};
async.during = function (test, iterator, callback) {
callback = callback || noop;
var next = _restParam(function(err, args) {
if (err) {
callback(err);
} else {
args.push(check);
test.apply(this, args);
}
});
var check = function(err, truth) {
if (err) {
callback(err);
} else if (truth) {
iterator(next);
} else {
callback(null);
}
};
test(check);
};
async.doDuring = function (iterator, test, callback) {
var calls = 0;
async.during(function(next) {
if (calls++ < 1) {
next(null, true);
} else {
test.apply(this, arguments);
}
}, iterator, callback);
};
function _queue(worker, concurrency, payload) {
if (concurrency == null) {
concurrency = 1;
}
else if(concurrency === 0) {
throw new Error('Concurrency must not be zero');
}
function _insert(q, data, pos, callback) {
if (callback != null && typeof callback !== "function") {
throw new Error("task callback must be a function");
}
q.started = true;
if (!_isArray(data)) {
data = [data];
}
if(data.length === 0 && q.idle()) {
// call drain immediately if there are no tasks
return async.setImmediate(function() {
q.drain();
});
}
_arrayEach(data, function(task) {
var item = {
data: task,
callback: callback || noop
};
if (pos) {
q.tasks.unshift(item);
} else {
q.tasks.push(item);
}
if (q.tasks.length === q.concurrency) {
q.saturated();
}
});
async.setImmediate(q.process);
}
function _next(q, tasks) {
return function(){
workers -= 1;
var removed = false;
var args = arguments;
_arrayEach(tasks, function (task) {
_arrayEach(workersList, function (worker, index) {
if (worker === task && !removed) {
workersList.splice(index, 1);
removed = true;
}
});
task.callback.apply(task, args);
});
if (q.tasks.length + workers === 0) {
q.drain();
}
q.process();
};
}
var workers = 0;
var workersList = [];
var q = {
tasks: [],
concurrency: concurrency,
payload: payload,
saturated: noop,
empty: noop,
drain: noop,
started: false,
paused: false,
push: function (data, callback) {
_insert(q, data, false, callback);
},
kill: function () {
q.drain = noop;
q.tasks = [];
},
unshift: function (data, callback) {
_insert(q, data, true, callback);
},
process: function () {
while(!q.paused && workers < q.concurrency && q.tasks.length){
var tasks = q.payload ?
q.tasks.splice(0, q.payload) :
q.tasks.splice(0, q.tasks.length);
var data = _map(tasks, function (task) {
return task.data;
});
if (q.tasks.length === 0) {
q.empty();
}
workers += 1;
workersList.push(tasks[0]);
var cb = only_once(_next(q, tasks));
worker(data, cb);
}
},
length: function () {
return q.tasks.length;
},
running: function () {
return workers;
},
workersList: function () {
return workersList;
},
idle: function() {
return q.tasks.length + workers === 0;
},
pause: function () {
q.paused = true;
},
resume: function () {
if (q.paused === false) { return; }
q.paused = false;
var resumeCount = Math.min(q.concurrency, q.tasks.length);
// Need to call q.process once per concurrent
// worker to preserve full concurrency after pause
for (var w = 1; w <= resumeCount; w++) {
async.setImmediate(q.process);
}
}
};
return q;
}
async.queue = function (worker, concurrency) {
var q = _queue(function (items, cb) {
worker(items[0], cb);
}, concurrency, 1);
return q;
};
async.priorityQueue = function (worker, concurrency) {
function _compareTasks(a, b){
return a.priority - b.priority;
}
function _binarySearch(sequence, item, compare) {
var beg = -1,
end = sequence.length - 1;
while (beg < end) {
var mid = beg + ((end - beg + 1) >>> 1);
if (compare(item, sequence[mid]) >= 0) {
beg = mid;
} else {
end = mid - 1;
}
}
return beg;
}
function _insert(q, data, priority, callback) {
if (callback != null && typeof callback !== "function") {
throw new Error("task callback must be a function");
}
q.started = true;
if (!_isArray(data)) {
data = [data];
}
if(data.length === 0) {
// call drain immediately if there are no tasks
return async.setImmediate(function() {
q.drain();
});
}
_arrayEach(data, function(task) {
var item = {
data: task,
priority: priority,
callback: typeof callback === 'function' ? callback : noop
};
q.tasks.splice(_binarySearch(q.tasks, item, _compareTasks) + 1, 0, item);
if (q.tasks.length === q.concurrency) {
q.saturated();
}
async.setImmediate(q.process);
});
}
// Start with a normal queue
var q = async.queue(worker, concurrency);
// Override push to accept second parameter representing priority
q.push = function (data, priority, callback) {
_insert(q, data, priority, callback);
};
// Remove unshift function
delete q.unshift;
return q;
};
async.cargo = function (worker, payload) {
return _queue(worker, 1, payload);
};
function _console_fn(name) {
return _restParam(function (fn, args) {
fn.apply(null, args.concat([_restParam(function (err, args) {
if (typeof console === 'object') {
if (err) {
if (console.error) {
console.error(err);
}
}
else if (console[name]) {
_arrayEach(args, function (x) {
console[name](x);
});
}
}
})]));
});
}
async.log = _console_fn('log');
async.dir = _console_fn('dir');
/*async.info = _console_fn('info');
async.warn = _console_fn('warn');
async.error = _console_fn('error');*/
async.memoize = function (fn, hasher) {
var memo = {};
var queues = {};
var has = Object.prototype.hasOwnProperty;
hasher = hasher || identity;
var memoized = _restParam(function memoized(args) {
var callback = args.pop();
var key = hasher.apply(null, args);
if (has.call(memo, key)) {
async.setImmediate(function () {
callback.apply(null, memo[key]);
});
}
else if (has.call(queues, key)) {
queues[key].push(callback);
}
else {
queues[key] = [callback];
fn.apply(null, args.concat([_restParam(function (args) {
memo[key] = args;
var q = queues[key];
delete queues[key];
for (var i = 0, l = q.length; i < l; i++) {
q[i].apply(null, args);
}
})]));
}
});
memoized.memo = memo;
memoized.unmemoized = fn;
return memoized;
};
async.unmemoize = function (fn) {
return function () {
return (fn.unmemoized || fn).apply(null, arguments);
};
};
function _times(mapper) {
return function (count, iterator, callback) {
mapper(_range(count), iterator, callback);
};
}
async.times = _times(async.map);
async.timesSeries = _times(async.mapSeries);
async.timesLimit = function (count, limit, iterator, callback) {
return async.mapLimit(_range(count), limit, iterator, callback);
};
async.seq = function (/* functions... */) {
var fns = arguments;
return _restParam(function (args) {
var that = this;
var callback = args[args.length - 1];
if (typeof callback == 'function') {
args.pop();
} else {
callback = noop;
}
async.reduce(fns, args, function (newargs, fn, cb) {
fn.apply(that, newargs.concat([_restParam(function (err, nextargs) {
cb(err, nextargs);
})]));
},
function (err, results) {
callback.apply(that, [err].concat(results));
});
});
};
async.compose = function (/* functions... */) {
return async.seq.apply(null, Array.prototype.reverse.call(arguments));
};
function _applyEach(eachfn) {
return _restParam(function(fns, args) {
var go = _restParam(function(args) {
var that = this;
var callback = args.pop();
return eachfn(fns, function (fn, _, cb) {
fn.apply(that, args.concat([cb]));
},
callback);
});
if (args.length) {
return go.apply(this, args);
}
else {
return go;
}
});
}
async.applyEach = _applyEach(async.eachOf);
async.applyEachSeries = _applyEach(async.eachOfSeries);
async.forever = function (fn, callback) {
var done = only_once(callback || noop);
var task = ensureAsync(fn);
function next(err) {
if (err) {
return done(err);
}
task(next);
}
next();
};
function ensureAsync(fn) {
return _restParam(function (args) {
var callback = args.pop();
args.push(function () {
var innerArgs = arguments;
if (sync) {
async.setImmediate(function () {
callback.apply(null, innerArgs);
});
} else {
callback.apply(null, innerArgs);
}
});
var sync = true;
fn.apply(this, args);
sync = false;
});
}
async.ensureAsync = ensureAsync;
async.constant = _restParam(function(values) {
var args = [null].concat(values);
return function (callback) {
return callback.apply(this, args);
};
});
async.wrapSync =
async.asyncify = function asyncify(func) {
return _restParam(function (args) {
var callback = args.pop();
var result;
try {
result = func.apply(this, args);
} catch (e) {
return callback(e);
}
// if result is Promise object
if (_isObject(result) && typeof result.then === "function") {
result.then(function(value) {
callback(null, value);
})["catch"](function(err) {
callback(err.message ? err : new Error(err));
});
} else {
callback(null, result);
}
});
};
// Node.js
if (typeof module === 'object' && module.exports) {
module.exports = async;
}
// AMD / RequireJS
else if (typeof define === 'function' && define.amd) {
define([], function () {
return async;
});
}
// included directly via <script> tag
else {
root.async = async;
}
}());
}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"_process":26}],18:[function(require,module,exports){
// Browser Request
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// UMD HEADER START
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], factory);
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals (root is window)
root.returnExports = factory();
}
}(this, function () {
// UMD HEADER END
var XHR = XMLHttpRequest
if (!XHR) throw new Error('missing XMLHttpRequest')
request.log = {
'trace': noop, 'debug': noop, 'info': noop, 'warn': noop, 'error': noop
}
var DEFAULT_TIMEOUT = 3 * 60 * 1000 // 3 minutes
//
// request
//
function request(options, callback) {
// The entry-point to the API: prep the options object and pass the real work to run_xhr.
if(typeof callback !== 'function')
throw new Error('Bad callback given: ' + callback)
if(!options)
throw new Error('No options given')
var options_onResponse = options.onResponse; // Save this for later.
if(typeof options === 'string')
options = {'uri':options};
else
options = JSON.parse(JSON.stringify(options)); // Use a duplicate for mutating.
options.onResponse = options_onResponse // And put it back.
if (options.verbose) request.log = getLogger();
if(options.url) {
options.uri = options.url;
delete options.url;
}
if(!options.uri && options.uri !== "")
throw new Error("options.uri is a required argument");
if(typeof options.uri != "string")
throw new Error("options.uri must be a string");
var unsupported_options = ['proxy', '_redirectsFollowed', 'maxRedirects', 'followRedirect']
for (var i = 0; i < unsupported_options.length; i++)
if(options[ unsupported_options[i] ])
throw new Error("options." + unsupported_options[i] + " is not supported")
options.callback = callback
options.method = options.method || 'GET';
options.headers = options.headers || {};
options.body = options.body || null
options.timeout = options.timeout || request.DEFAULT_TIMEOUT
if(options.headers.host)
throw new Error("Options.headers.host is not supported");
if(options.json) {
options.headers.accept = options.headers.accept || 'application/json'
if(options.method !== 'GET')
options.headers['content-type'] = 'application/json'
if(typeof options.json !== 'boolean')
options.body = JSON.stringify(options.json)
else if(typeof options.body !== 'string')
options.body = JSON.stringify(options.body)
}
//BEGIN QS Hack
var serialize = function(obj) {
var str = [];
for(var p in obj)
if (obj.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
}
return str.join("&");
}
if(options.qs){
var qs = (typeof options.qs == 'string')? options.qs : serialize(options.qs);
if(options.uri.indexOf('?') !== -1){ //no get params
options.uri = options.uri+'&'+qs;
}else{ //existing get params
options.uri = options.uri+'?'+qs;
}
}
//END QS Hack
//BEGIN FORM Hack
var multipart = function(obj) {
//todo: support file type (useful?)
var result = {};
result.boundry = '-------------------------------'+Math.floor(Math.random()*1000000000);
var lines = [];
for(var p in obj){
if (obj.hasOwnProperty(p)) {
lines.push(
'--'+result.boundry+"\n"+
'Content-Disposition: form-data; name="'+p+'"'+"\n"+
"\n"+
obj[p]+"\n"
);
}
}
lines.push( '--'+result.boundry+'--' );
result.body = lines.join('');
result.length = result.body.length;
result.type = 'multipart/form-data; boundary='+result.boundry;
return result;
}
if(options.form){
if(typeof options.form == 'string') throw('form name unsupported');
if(options.method === 'POST'){
var encoding = (options.encoding || 'application/x-www-form-urlencoded').toLowerCase();
options.headers['content-type'] = encoding;
switch(encoding){
case 'application/x-www-form-urlencoded':
options.body = serialize(options.form).replace(/%20/g, "+");
break;
case 'multipart/form-data':
var multi = multipart(options.form);
//options.headers['content-length'] = multi.length;
options.body = multi.body;
options.headers['content-type'] = multi.type;
break;
default : throw new Error('unsupported encoding:'+encoding);
}
}
}
//END FORM Hack
// If onResponse is boolean true, call back immediately when the response is known,
// not when the full request is complete.
options.onResponse = options.onResponse || noop
if(options.onResponse === true) {
options.onResponse = callback
options.callback = noop
}
// XXX Browsers do not like this.
//if(options.body)
// options.headers['content-length'] = options.body.length;
// HTTP basic authentication
if(!options.headers.authorization && options.auth)
options.headers.authorization = 'Basic ' + b64_enc(options.auth.username + ':' + options.auth.password);
return run_xhr(options)
}
var req_seq = 0
function run_xhr(options) {
var xhr = new XHR
, timed_out = false
, is_cors = is_crossDomain(options.uri)
, supports_cors = ('withCredentials' in xhr)
req_seq += 1
xhr.seq_id = req_seq
xhr.id = req_seq + ': ' + options.method + ' ' + options.uri
xhr._id = xhr.id // I know I will type "_id" from habit all the time.
if(is_cors && !supports_cors) {
var cors_err = new Error('Browser does not support cross-origin request: ' + options.uri)
cors_err.cors = 'unsupported'
return options.callback(cors_err, xhr)
}
xhr.timeoutTimer = setTimeout(too_late, options.timeout)
function too_late() {
timed_out = true
var er = new Error('ETIMEDOUT')
er.code = 'ETIMEDOUT'
er.duration = options.timeout
request.log.error('Timeout', { 'id':xhr._id, 'milliseconds':options.timeout })
return options.callback(er, xhr)
}
// Some states can be skipped over, so remember what is still incomplete.
var did = {'response':false, 'loading':false, 'end':false}
xhr.onreadystatechange = on_state_change
xhr.open(options.method, options.uri, true) // asynchronous
if(is_cors)
xhr.withCredentials = !! options.withCredentials
xhr.send(options.body)
return xhr
function on_state_change(event) {
if(timed_out)
return request.log.debug('Ignoring timed out state change', {'state':xhr.readyState, 'id':xhr.id})
request.log.debug('State change', {'state':xhr.readyState, 'id':xhr.id, 'timed_out':timed_out})
if(xhr.readyState === XHR.OPENED) {
request.log.debug('Request started', {'id':xhr.id})
for (var key in options.headers)
xhr.setRequestHeader(key, options.headers[key])
}
else if(xhr.readyState === XHR.HEADERS_RECEIVED)
on_response()
else if(xhr.readyState === XHR.LOADING) {
on_response()
on_loading()
}
else if(xhr.readyState === XHR.DONE) {
on_response()
on_loading()
on_end()
}
}
function on_response() {
if(did.response)
return
did.response = true
request.log.debug('Got response', {'id':xhr.id, 'status':xhr.status})
clearTimeout(xhr.timeoutTimer)
xhr.statusCode = xhr.status // Node request compatibility
// Detect failed CORS requests.
if(is_cors && xhr.statusCode == 0) {
var cors_err = new Error('CORS request rejected: ' + options.uri)
cors_err.cors = 'rejected'
// Do not process this request further.
did.loading = true
did.end = true
return options.callback(cors_err, xhr)
}
options.onResponse(null, xhr)
}
function on_loading() {
if(did.loading)
return
did.loading = true
request.log.debug('Response body loading', {'id':xhr.id})
// TODO: Maybe simulate "data" events by watching xhr.responseText
}
function on_end() {
if(did.end)
return
did.end = true
request.log.debug('Request done', {'id':xhr.id})
xhr.body = xhr.responseText
if(options.json) {
try { xhr.body = JSON.parse(xhr.responseText) }
catch (er) { return options.callback(er, xhr) }
}
options.callback(null, xhr, xhr.body)
}
} // request
request.withCredentials = false;
request.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
//
// defaults
//
request.defaults = function(options, requester) {
var def = function (method) {
var d = function (params, callback) {
if(typeof params === 'string')
params = {'uri': params};
else {
params = JSON.parse(JSON.stringify(params));
}
for (var i in options) {
if (params[i] === undefined) params[i] = options[i]
}
return method(params, callback)
}
return d
}
var de = def(request)
de.get = def(request.get)
de.post = def(request.post)
de.put = def(request.put)
de.head = def(request.head)
return de
}
//
// HTTP method shortcuts
//
var shortcuts = [ 'get', 'put', 'post', 'head' ];
shortcuts.forEach(function(shortcut) {
var method = shortcut.toUpperCase();
var func = shortcut.toLowerCase();
request[func] = function(opts) {
if(typeof opts === 'string')
opts = {'method':method, 'uri':opts};
else {
opts = JSON.parse(JSON.stringify(opts));
opts.method = method;
}
var args = [opts].concat(Array.prototype.slice.apply(arguments, [1]));
return request.apply(this, args);
}
})
//
// CouchDB shortcut
//
request.couch = function(options, callback) {
if(typeof options === 'string')
options = {'uri':options}
// Just use the request API to do JSON.
options.json = true
if(options.body)
options.json = options.body
delete options.body
callback = callback || noop
var xhr = request(options, couch_handler)
return xhr
function couch_handler(er, resp, body) {
if(er)
return callback(er, resp, body)
if((resp.statusCode < 200 || resp.statusCode > 299) && body.error) {
// The body is a Couch JSON object indicating the error.
er = new Error('CouchDB error: ' + (body.error.reason || body.error.error))
for (var key in body)
er[key] = body[key]
return callback(er, resp, body);
}
return callback(er, resp, body);
}
}
//
// Utility
//
function noop() {}
function getLogger() {
var logger = {}
, levels = ['trace', 'debug', 'info', 'warn', 'error']
, level, i
for(i = 0; i < levels.length; i++) {
level = levels[i]
logger[level] = noop
if(typeof console !== 'undefined' && console && console[level])
logger[level] = formatted(console, level)
}
return logger
}
function formatted(obj, method) {
return formatted_logger
function formatted_logger(str, context) {
if(typeof context === 'object')
str += ' ' + JSON.stringify(context)
return obj[method].call(obj, str)
}
}
// Return whether a URL is a cross-domain request.
function is_crossDomain(url) {
var rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/
// jQuery #8138, IE may throw an exception when accessing
// a field from window.location if document.domain has been set
var ajaxLocation
try { ajaxLocation = location.href }
catch (e) {
// Use the href attribute of an A element since IE will modify it given document.location
ajaxLocation = document.createElement( "a" );
ajaxLocation.href = "";
ajaxLocation = ajaxLocation.href;
}
var ajaxLocParts = rurl.exec(ajaxLocation.toLowerCase()) || []
, parts = rurl.exec(url.toLowerCase() )
var result = !!(
parts &&
( parts[1] != ajaxLocParts[1]
|| parts[2] != ajaxLocParts[2]
|| (parts[3] || (parts[1] === "http:" ? 80 : 443)) != (ajaxLocParts[3] || (ajaxLocParts[1] === "http:" ? 80 : 443))
)
)
//console.debug('is_crossDomain('+url+') -> ' + result)
return result
}
// MIT License from http://phpjs.org/functions/base64_encode:358
function b64_enc (data) {
// Encodes string using MIME base64 algorithm
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, enc="", tmp_arr = [];
if (!data) {
return data;
}
// assume utf8 data
// data = this.utf8_encode(data+'');
do { // pack three octets into four hexets
o1 = data.charCodeAt(i++);
o2 = data.charCodeAt(i++);
o3 = data.charCodeAt(i++);
bits = o1<<16 | o2<<8 | o3;
h1 = bits>>18 & 0x3f;
h2 = bits>>12 & 0x3f;
h3 = bits>>6 & 0x3f;
h4 = bits & 0x3f;
// use hexets to index into b64, and append result to encoded string
tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
} while (i < data.length);
enc = tmp_arr.join('');
switch (data.length % 3) {
case 1:
enc = enc.slice(0, -2) + '==';
break;
case 2:
enc = enc.slice(0, -1) + '=';
break;
}
return enc;
}
return request;
//UMD FOOTER START
}));
//UMD FOOTER END
},{}],19:[function(require,module,exports){
if (typeof Object.create === 'function') {
// implementation from standard node.js 'util' module
module.exports = function inherits(ctor, superCtor) {
ctor.super_ = superCtor
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
});
};
} else {
// old school shim for old browsers
module.exports = function inherits(ctor, superCtor) {
ctor.super_ = superCtor
var TempCtor = function () {}
TempCtor.prototype = superCtor.prototype
ctor.prototype = new TempCtor()
ctor.prototype.constructor = ctor
}
}
},{}],20:[function(require,module,exports){
(function (global){
/**
* @license
* lodash 3.10.1 (Custom Build) <https://lodash.com/>
* Build: `lodash modern -d -o ./index.js`
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Available under MIT license <https://lodash.com/license>
*/
;(function() {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** Used as the semantic version number. */
var VERSION = '3.10.1';
/** Used to compose bitmasks for wrapper metadata. */
var BIND_FLAG = 1,
BIND_KEY_FLAG = 2,
CURRY_BOUND_FLAG = 4,
CURRY_FLAG = 8,
CURRY_RIGHT_FLAG = 16,
PARTIAL_FLAG = 32,
PARTIAL_RIGHT_FLAG = 64,
ARY_FLAG = 128,
REARG_FLAG = 256;
/** Used as default options for `_.trunc`. */
var DEFAULT_TRUNC_LENGTH = 30,
DEFAULT_TRUNC_OMISSION = '...';
/** Used to detect when a function becomes hot. */
var HOT_COUNT = 150,
HOT_SPAN = 16;
/** Used as the size to enable large array optimizations. */
var LARGE_ARRAY_SIZE = 200;
/** Used to indicate the type of lazy iteratees. */
var LAZY_FILTER_FLAG = 1,
LAZY_MAP_FLAG = 2;
/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function';
/** Used as the internal argument placeholder. */
var PLACEHOLDER = '__lodash_placeholder__';
/** `Object#toString` result references. */
var argsTag = '[object Arguments]',
arrayTag = '[object Array]',
boolTag = '[object Boolean]',
dateTag = '[object Date]',
errorTag = '[object Error]',
funcTag = '[object Function]',
mapTag = '[object Map]',
numberTag = '[object Number]',
objectTag = '[object Object]',
regexpTag = '[object RegExp]',
setTag = '[object Set]',
stringTag = '[object String]',
weakMapTag = '[object WeakMap]';
var arrayBufferTag = '[object ArrayBuffer]',
float32Tag = '[object Float32Array]',
float64Tag = '[object Float64Array]',
int8Tag = '[object Int8Array]',
int16Tag = '[object Int16Array]',
int32Tag = '[object Int32Array]',
uint8Tag = '[object Uint8Array]',
uint8ClampedTag = '[object Uint8ClampedArray]',
uint16Tag = '[object Uint16Array]',
uint32Tag = '[object Uint32Array]';
/** Used to match empty string literals in compiled template source. */
var reEmptyStringLeading = /\b__p \+= '';/g,
reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
/** Used to match HTML entities and HTML characters. */
var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
reUnescapedHtml = /[&<>"'`]/g,
reHasEscapedHtml = RegExp(reEscapedHtml.source),
reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
/** Used to match template delimiters. */
var reEscape = /<%-([\s\S]+?)%>/g,
reEvaluate = /<%([\s\S]+?)%>/g,
reInterpolate = /<%=([\s\S]+?)%>/g;
/** Used to match property names within property paths. */
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/,
reIsPlainProp = /^\w*$/,
rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
/**
* Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns)
* and those outlined by [`EscapeRegExpPattern`](http://ecma-international.org/ecma-262/6.0/#sec-escaperegexppattern).
*/
var reRegExpChars = /^[:!,]|[\\^$.*+?()[\]{}|\/]|(^[0-9a-fA-Fnrtuvx])|([\n\r\u2028\u2029])/g,
reHasRegExpChars = RegExp(reRegExpChars.source);
/** Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). */
var reComboMark = /[\u0300-\u036f\ufe20-\ufe23]/g;
/** Used to match backslashes in property paths. */
var reEscapeChar = /\\(\\)?/g;
/** Used to match [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components). */
var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
/** Used to match `RegExp` flags from their coerced string values. */
var reFlags = /\w*$/;
/** Used to detect hexadecimal string values. */
var reHasHexPrefix = /^0[xX]/;
/** Used to detect host constructors (Safari > 5). */
var reIsHostCtor = /^\[object .+?Constructor\]$/;
/** Used to detect unsigned integer values. */
var reIsUint = /^\d+$/;
/** Used to match latin-1 supplementary letters (excluding mathematical operators). */
var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
/** Used to ensure capturing order of template delimiters. */
var reNoMatch = /($^)/;
/** Used to match unescaped characters in compiled string literals. */
var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
/** Used to match words to create compound words. */
var reWords = (function() {
var upper = '[A-Z\\xc0-\\xd6\\xd8-\\xde]',
lower = '[a-z\\xdf-\\xf6\\xf8-\\xff]+';
return RegExp(upper + '+(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
}());
/** Used to assign default `context` object properties. */
var contextProps = [
'Array', 'ArrayBuffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Math', 'Number',
'Object', 'RegExp', 'Set', 'String', '_', 'clearTimeout', 'isFinite',
'parseFloat', 'parseInt', 'setTimeout', 'TypeError', 'Uint8Array',
'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap'
];
/** Used to make template sourceURLs easier to identify. */
var templateCounter = -1;
/** Used to identify `toStringTag` values of typed arrays. */
var typedArrayTags = {};
typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
typedArrayTags[uint32Tag] = true;
typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
typedArrayTags[dateTag] = typedArrayTags[errorTag] =
typedArrayTags[funcTag] = typedArrayTags[mapTag] =
typedArrayTags[numberTag] = typedArrayTags[objectTag] =
typedArrayTags[regexpTag] = typedArrayTags[setTag] =
typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
/** Used to identify `toStringTag` values supported by `_.clone`. */
var cloneableTags = {};
cloneableTags[argsTag] = cloneableTags[arrayTag] =
cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
cloneableTags[dateTag] = cloneableTags[float32Tag] =
cloneableTags[float64Tag] = cloneableTags[int8Tag] =
cloneableTags[int16Tag] = cloneableTags[int32Tag] =
cloneableTags[numberTag] = cloneableTags[objectTag] =
cloneableTags[regexpTag] = cloneableTags[stringTag] =
cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
cloneableTags[errorTag] = cloneableTags[funcTag] =
cloneableTags[mapTag] = cloneableTags[setTag] =
cloneableTags[weakMapTag] = false;
/** Used to map latin-1 supplementary letters to basic latin letters. */
var deburredLetters = {
'\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
'\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
'\xc7': 'C', '\xe7': 'c',
'\xd0': 'D', '\xf0': 'd',
'\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
'\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
'\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
'\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
'\xd1': 'N', '\xf1': 'n',
'\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
'\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
'\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
'\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
'\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
'\xc6': 'Ae', '\xe6': 'ae',
'\xde': 'Th', '\xfe': 'th',
'\xdf': 'ss'
};
/** Used to map characters to HTML entities. */
var htmlEscapes = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": ''',
'`': '`'
};
/** Used to map HTML entities to characters. */
var htmlUnescapes = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
''': "'",
'`': '`'
};
/** Used to determine if values are of the language type `Object`. */
var objectTypes = {
'function': true,
'object': true
};
/** Used to escape characters for inclusion in compiled regexes. */
var regexpEscapes = {
'0': 'x30', '1': 'x31', '2': 'x32', '3': 'x33', '4': 'x34',
'5': 'x35', '6': 'x36', '7': 'x37', '8': 'x38', '9': 'x39',
'A': 'x41', 'B': 'x42', 'C': 'x43', 'D': 'x44', 'E': 'x45', 'F': 'x46',
'a': 'x61', 'b': 'x62', 'c': 'x63', 'd': 'x64', 'e': 'x65', 'f': 'x66',
'n': 'x6e', 'r': 'x72', 't': 'x74', 'u': 'x75', 'v': 'x76', 'x': 'x78'
};
/** Used to escape characters for inclusion in compiled string literals. */
var stringEscapes = {
'\\': '\\',
"'": "'",
'\n': 'n',
'\r': 'r',
'\u2028': 'u2028',
'\u2029': 'u2029'
};
/** Detect free variable `exports`. */
var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
/** Detect free variable `module`. */
var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
/** Detect free variable `global` from Node.js. */
var freeGlobal = freeExports && freeModule && typeof global == 'object' && global && global.Object && global;
/** Detect free variable `self`. */
var freeSelf = objectTypes[typeof self] && self && self.Object && self;
/** Detect free variable `window`. */
var freeWindow = objectTypes[typeof window] && window && window.Object && window;
/** Detect the popular CommonJS extension `module.exports`. */
var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
/**
* Used as a reference to the global object.
*
* The `this` value is used if it's the global object to avoid Greasemonkey's
* restricted `window` object, otherwise the `window` object is used.
*/
var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || freeSelf || this;
/*--------------------------------------------------------------------------*/
/**
* The base implementation of `compareAscending` which compares values and
* sorts them in ascending order without guaranteeing a stable sort.
*
* @private
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {number} Returns the sort order indicator for `value`.
*/
function baseCompareAscending(value, other) {
if (value !== other) {
var valIsNull = value === null,
valIsUndef = value === undefined,
valIsReflexive = value === value;
var othIsNull = other === null,
othIsUndef = other === undefined,
othIsReflexive = other === other;
if ((value > other && !othIsNull) || !valIsReflexive ||
(valIsNull && !othIsUndef && othIsReflexive) ||
(valIsUndef && othIsReflexive)) {
return 1;
}
if ((value < other && !valIsNull) || !othIsReflexive ||
(othIsNull && !valIsUndef && valIsReflexive) ||
(othIsUndef && valIsReflexive)) {
return -1;
}
}
return 0;
}
/**
* The base implementation of `_.findIndex` and `_.findLastIndex` without
* support for callback shorthands and `this` binding.
*
* @private
* @param {Array} array The array to search.
* @param {Function} predicate The function invoked per iteration.
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {number} Returns the index of the matched value, else `-1`.
*/
function baseFindIndex(array, predicate, fromRight) {
var length = array.length,
index = fromRight ? length : -1;
while ((fromRight ? index-- : ++index < length)) {
if (predicate(array[index], index, array)) {
return index;
}
}
return -1;
}
/**
* The base implementation of `_.indexOf` without support for binary searches.
*
* @private
* @param {Array} array The array to search.
* @param {*} value The value to search for.
* @param {number} fromIndex The index to search from.
* @returns {number} Returns the index of the matched value, else `-1`.
*/
function baseIndexOf(array, value, fromIndex) {
if (value !== value) {
return indexOfNaN(array, fromIndex);
}
var index = fromIndex - 1,
length = array.length;
while (++index < length) {
if (array[index] === value) {
return index;
}
}
return -1;
}
/**
* The base implementation of `_.isFunction` without support for environments
* with incorrect `typeof` results.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
*/
function baseIsFunction(value) {
// Avoid a Chakra JIT bug in compatibility modes of IE 11.
// See https://github.com/jashkenas/underscore/issues/1621 for more details.
return typeof value == 'function' || false;
}
/**
* Converts `value` to a string if it's not one. An empty string is returned
* for `null` or `undefined` values.
*
* @private
* @param {*} value The value to process.
* @returns {string} Returns the string.
*/
function baseToString(value) {
return value == null ? '' : (value + '');
}
/**
* Used by `_.trim` and `_.trimLeft` to get the index of the first character
* of `string` that is not found in `chars`.
*
* @private
* @param {string} string The string to inspect.
* @param {string} chars The characters to find.
* @returns {number} Returns the index of the first character not found in `chars`.
*/
function charsLeftIndex(string, chars) {
var index = -1,
length = string.length;
while (++index < length && chars.indexOf(string.charAt(index)) > -1) {}
return index;
}
/**
* Used by `_.trim` and `_.trimRight` to get the index of the last character
* of `string` that is not found in `chars`.
*
* @private
* @param {string} string The string to inspect.
* @param {string} chars The characters to find.
* @returns {number} Returns the index of the last character not found in `chars`.
*/
function charsRightIndex(string, chars) {
var index = string.length;
while (index-- && chars.indexOf(string.charAt(index)) > -1) {}
return index;
}
/**
* Used by `_.sortBy` to compare transformed elements of a collection and stable
* sort them in ascending order.
*
* @private
* @param {Object} object The object to compare.
* @param {Object} other The other object to compare.
* @returns {number} Returns the sort order indicator for `object`.
*/
function compareAscending(object, other) {
return baseCompareAscending(object.criteria, other.criteria) || (object.index - other.index);
}
/**
* Used by `_.sortByOrder` to compare multiple properties of a value to another
* and stable sort them.
*
* If `orders` is unspecified, all valuess are sorted in ascending order. Otherwise,
* a value is sorted in ascending order if its corresponding order is "asc", and
* descending if "desc".
*
* @private
* @param {Object} object The object to compare.
* @param {Object} other The other object to compare.
* @param {boolean[]} orders The order to sort by for each property.
* @returns {number} Returns the sort order indicator for `object`.
*/
function compareMultiple(object, other, orders) {
var index = -1,
objCriteria = object.criteria,
othCriteria = other.criteria,
length = objCriteria.length,
ordersLength = orders.length;
while (++index < length) {
var result = baseCompareAscending(objCriteria[index], othCriteria[index]);
if (result) {
if (index >= ordersLength) {
return result;
}
var order = orders[index];
return result * ((order === 'asc' || order === true) ? 1 : -1);
}
}
// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
// that causes it, under certain circumstances, to provide the same value for
// `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
// for more details.
//
// This also ensures a stable sort in V8 and other engines.
// See https://code.google.com/p/v8/issues/detail?id=90 for more details.
return object.index - other.index;
}
/**
* Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
*
* @private
* @param {string} letter The matched letter to deburr.
* @returns {string} Returns the deburred letter.
*/
function deburrLetter(letter) {
return deburredLetters[letter];
}
/**
* Used by `_.escape` to convert characters to HTML entities.
*
* @private
* @param {string} chr The matched character to escape.
* @returns {string} Returns the escaped character.
*/
function escapeHtmlChar(chr) {
return htmlEscapes[chr];
}
/**
* Used by `_.escapeRegExp` to escape characters for inclusion in compiled regexes.
*
* @private
* @param {string} chr The matched character to escape.
* @param {string} leadingChar The capture group for a leading character.
* @param {string} whitespaceChar The capture group for a whitespace character.
* @returns {string} Returns the escaped character.
*/
function escapeRegExpChar(chr, leadingChar, whitespaceChar) {
if (leadingChar) {
chr = regexpEscapes[chr];
} else if (whitespaceChar) {
chr = stringEscapes[chr];
}
return '\\' + chr;
}
/**
* Used by `_.template` to escape characters for inclusion in compiled string literals.
*
* @private
* @param {string} chr The matched character to escape.
* @returns {string} Returns the escaped character.
*/
function escapeStringChar(chr) {
return '\\' + stringEscapes[chr];
}
/**
* Gets the index at which the first occurrence of `NaN` is found in `array`.
*
* @private
* @param {Array} array The array to search.
* @param {number} fromIndex The index to search from.
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {number} Returns the index of the matched `NaN`, else `-1`.
*/
function indexOfNaN(array, fromIndex, fromRight) {
var length = array.length,
index = fromIndex + (fromRight ? 0 : -1);
while ((fromRight ? index-- : ++index < length)) {
var other = array[index];
if (other !== other) {
return index;
}
}
return -1;
}
/**
* Checks if `value` is object-like.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
*/
function isObjectLike(value) {
return !!value && typeof value == 'object';
}
/**
* Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a
* character code is whitespace.
*
* @private
* @param {number} charCode The character code to inspect.
* @returns {boolean} Returns `true` if `charCode` is whitespace, else `false`.
*/
function isSpace(charCode) {
return ((charCode <= 160 && (charCode >= 9 && charCode <= 13) || charCode == 32 || charCode == 160) || charCode == 5760 || charCode == 6158 ||
(charCode >= 8192 && (charCode <= 8202 || charCode == 8232 || charCode == 8233 || charCode == 8239 || charCode == 8287 || charCode == 12288 || charCode == 65279)));
}
/**
* Replaces all `placeholder` elements in `array` with an internal placeholder
* and returns an array of their indexes.
*
* @private
* @param {Array} array The array to modify.
* @param {*} placeholder The placeholder to replace.
* @returns {Array} Returns the new array of placeholder indexes.
*/
function replaceHolders(array, placeholder) {
var index = -1,
length = array.length,
resIndex = -1,
result = [];
while (++index < length) {
if (array[index] === placeholder) {
array[index] = PLACEHOLDER;
result[++resIndex] = index;
}
}
return result;
}
/**
* An implementation of `_.uniq` optimized for sorted arrays without support
* for callback shorthands and `this` binding.
*
* @private
* @param {Array} array The array to inspect.
* @param {Function} [iteratee] The function invoked per iteration.
* @returns {Array} Returns the new duplicate-value-free array.
*/
function sortedUniq(array, iteratee) {
var seen,
index = -1,
length = array.length,
resIndex = -1,
result = [];
while (++index < length) {
var value = array[index],
computed = iteratee ? iteratee(value, index, array) : value;
if (!index || seen !== computed) {
seen = computed;
result[++resIndex] = value;
}
}
return result;
}
/**
* Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace
* character of `string`.
*
* @private
* @param {string} string The string to inspect.
* @returns {number} Returns the index of the first non-whitespace character.
*/
function trimmedLeftIndex(string) {
var index = -1,
length = string.length;
while (++index < length && isSpace(string.charCodeAt(index))) {}
return index;
}
/**
* Used by `_.trim` and `_.trimRight` to get the index of the last non-whitespace
* character of `string`.
*
* @private
* @param {string} string The string to inspect.
* @returns {number} Returns the index of the last non-whitespace character.
*/
function trimmedRightIndex(string) {
var index = string.length;
while (index-- && isSpace(string.charCodeAt(index))) {}
return index;
}
/**
* Used by `_.unescape` to convert HTML entities to characters.
*
* @private
* @param {string} chr The matched character to unescape.
* @returns {string} Returns the unescaped character.
*/
function unescapeHtmlChar(chr) {
return htmlUnescapes[chr];
}
/*--------------------------------------------------------------------------*/
/**
* Create a new pristine `lodash` function using the given `context` object.
*
* @static
* @memberOf _
* @category Utility
* @param {Object} [context=root] The context object.
* @returns {Function} Returns a new `lodash` function.
* @example
*
* _.mixin({ 'foo': _.constant('foo') });
*
* var lodash = _.runInContext();
* lodash.mixin({ 'bar': lodash.constant('bar') });
*
* _.isFunction(_.foo);
* // => true
* _.isFunction(_.bar);
* // => false
*
* lodash.isFunction(lodash.foo);
* // => false
* lodash.isFunction(lodash.bar);
* // => true
*
* // using `context` to mock `Date#getTime` use in `_.now`
* var mock = _.runInContext({
* 'Date': function() {
* return { 'getTime': getTimeMock };
* }
* });
*
* // or creating a suped-up `defer` in Node.js
* var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
*/
function runInContext(context) {
// Avoid issues with some ES3 environments that attempt to use values, named
// after built-in constructors like `Object`, for the creation of literals.
// ES5 clears this up by stating that literals must use built-in constructors.
// See https://es5.github.io/#x11.1.5 for more details.
context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
/** Native constructor references. */
var Array = context.Array,
Date = context.Date,
Error = context.Error,
Function = context.Function,
Math = context.Math,
Number = context.Number,
Object = context.Object,
RegExp = context.RegExp,
String = context.String,
TypeError = context.TypeError;
/** Used for native method references. */
var arrayProto = Array.prototype,
objectProto = Object.prototype,
stringProto = String.prototype;
/** Used to resolve the decompiled source of functions. */
var fnToString = Function.prototype.toString;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
/** Used to generate unique IDs. */
var idCounter = 0;
/**
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
* of values.
*/
var objToString = objectProto.toString;
/** Used to restore the original `_` reference in `_.noConflict`. */
var oldDash = root._;
/** Used to detect if a method is native. */
var reIsNative = RegExp('^' +
fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
);
/** Native method references. */
var ArrayBuffer = context.ArrayBuffer,
clearTimeout = context.clearTimeout,
parseFloat = context.parseFloat,
pow = Math.pow,
propertyIsEnumerable = objectProto.propertyIsEnumerable,
Set = getNative(context, 'Set'),
setTimeout = context.setTimeout,
splice = arrayProto.splice,
Uint8Array = context.Uint8Array,
WeakMap = getNative(context, 'WeakMap');
/* Native method references for those with the same name as other `lodash` methods. */
var nativeCeil = Math.ceil,
nativeCreate = getNative(Object, 'create'),
nativeFloor = Math.floor,
nativeIsArray = getNative(Array, 'isArray'),
nativeIsFinite = context.isFinite,
nativeKeys = getNative(Object, 'keys'),
nativeMax = Math.max,
nativeMin = Math.min,
nativeNow = getNative(Date, 'now'),
nativeParseInt = context.parseInt,
nativeRandom = Math.random;
/** Used as references for `-Infinity` and `Infinity`. */
var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
/** Used as references for the maximum length and index of an array. */
var MAX_ARRAY_LENGTH = 4294967295,
MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
/**
* Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
* of an array-like value.
*/
var MAX_SAFE_INTEGER = 9007199254740991;
/** Used to store function metadata. */
var metaMap = WeakMap && new WeakMap;
/** Used to lookup unminified function names. */
var realNames = {};
/*------------------------------------------------------------------------*/
/**
* Creates a `lodash` object which wraps `value` to enable implicit chaining.
* Methods that operate on and return arrays, collections, and functions can
* be chained together. Methods that retrieve a single value or may return a
* primitive value will automatically end the chain returning the unwrapped
* value. Explicit chaining may be enabled using `_.chain`. The execution of
* chained methods is lazy, that is, execution is deferred until `_#value`
* is implicitly or explicitly called.
*
* Lazy evaluation allows several methods to support shortcut fusion. Shortcut
* fusion is an optimization strategy which merge iteratee calls; this can help
* to avoid the creation of intermediate data structures and greatly reduce the
* number of iteratee executions.
*
* Chaining is supported in custom builds as long as the `_#value` method is
* directly or indirectly included in the build.
*
* In addition to lodash methods, wrappers have `Array` and `String` methods.
*
* The wrapper `Array` methods are:
* `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
* `splice`, and `unshift`
*
* The wrapper `String` methods are:
* `replace` and `split`
*
* The wrapper methods that support shortcut fusion are:
* `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
* `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
* `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
* and `where`
*
* The chainable wrapper methods are:
* `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
* `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
* `countBy`, `create`, `curry`, `debounce`, `defaults`, `defaultsDeep`,
* `defer`, `delay`, `difference`, `drop`, `dropRight`, `dropRightWhile`,
* `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`,
* `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
* `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
* `invoke`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`,
* `matchesProperty`, `memoize`, `merge`, `method`, `methodOf`, `mixin`,
* `modArgs`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
* `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
* `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `restParam`,
* `reverse`, `set`, `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`,
* `sortByOrder`, `splice`, `spread`, `take`, `takeRight`, `takeRightWhile`,
* `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`,
* `transform`, `union`, `uniq`, `unshift`, `unzip`, `unzipWith`, `values`,
* `valuesIn`, `where`, `without`, `wrap`, `xor`, `zip`, `zipObject`, `zipWith`
*
* The wrapper methods that are **not** chainable by default are:
* `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clone`, `cloneDeep`,
* `deburr`, `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`,
* `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`,
* `floor`, `get`, `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`,
* `inRange`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
* `isEmpty`, `isEqual`, `isError`, `isFinite` `isFunction`, `isMatch`,
* `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`, `isPlainObject`,
* `isRegExp`, `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`,
* `last`, `lastIndexOf`, `lt`, `lte`, `max`, `min`, `noConflict`, `noop`,
* `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`, `reduce`,
* `reduceRight`, `repeat`, `result`, `round`, `runInContext`, `shift`, `size`,
* `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`,
* `startsWith`, `sum`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`,
* `unescape`, `uniqueId`, `value`, and `words`
*
* The wrapper method `sample` will return a wrapped value when `n` is provided,
* otherwise an unwrapped value is returned.
*
* @name _
* @constructor
* @category Chain
* @param {*} value The value to wrap in a `lodash` instance.
* @returns {Object} Returns the new `lodash` wrapper instance.
* @example
*
* var wrapped = _([1, 2, 3]);
*
* // returns an unwrapped value
* wrapped.reduce(function(total, n) {
* return total + n;
* });
* // => 6
*
* // returns a wrapped value
* var squares = wrapped.map(function(n) {
* return n * n;
* });
*
* _.isArray(squares);
* // => false
*
* _.isArray(squares.value());
* // => true
*/
function lodash(value) {
if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
if (value instanceof LodashWrapper) {
return value;
}
if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
return wrapperClone(value);
}
}
return new LodashWrapper(value);
}
/**
* The function whose prototype all chaining wrappers inherit from.
*
* @private
*/
function baseLodash() {
// No operation performed.
}
/**
* The base constructor for creating `lodash` wrapper objects.
*
* @private
* @param {*} value The value to wrap.
* @param {boolean} [chainAll] Enable chaining for all wrapper methods.
* @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
*/
function LodashWrapper(value, chainAll, actions) {
this.__wrapped__ = value;
this.__actions__ = actions || [];
this.__chain__ = !!chainAll;
}
/**
* An object environment feature flags.
*
* @static
* @memberOf _
* @type Object
*/
var support = lodash.support = {};
/**
* By default, the template delimiters used by lodash are like those in
* embedded Ruby (ERB). Change the following template settings to use
* alternative delimiters.
*
* @static
* @memberOf _
* @type Object
*/
lodash.templateSettings = {
/**
* Used to detect `data` property values to be HTML-escaped.
*
* @memberOf _.templateSettings
* @type RegExp
*/
'escape': reEscape,
/**
* Used to detect code to be evaluated.
*
* @memberOf _.templateSettings
* @type RegExp
*/
'evaluate': reEvaluate,
/**
* Used to detect `data` property values to inject.
*
* @memberOf _.templateSettings
* @type RegExp
*/
'interpolate': reInterpolate,
/**
* Used to reference the data object in the template text.
*
* @memberOf _.templateSettings
* @type string
*/
'variable': '',
/**
* Used to import variables into the compiled template.
*
* @memberOf _.templateSettings
* @type Object
*/
'imports': {
/**
* A reference to the `lodash` function.
*
* @memberOf _.templateSettings.imports
* @type Function
*/
'_': lodash
}
};
/*------------------------------------------------------------------------*/
/**
* Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
*
* @private
* @param {*} value The value to wrap.
*/
function LazyWrapper(value) {
this.__wrapped__ = value;
this.__actions__ = [];
this.__dir__ = 1;
this.__filtered__ = false;
this.__iteratees__ = [];
this.__takeCount__ = POSITIVE_INFINITY;
this.__views__ = [];
}
/**
* Creates a clone of the lazy wrapper object.
*
* @private
* @name clone
* @memberOf LazyWrapper
* @returns {Object} Returns the cloned `LazyWrapper` object.
*/
function lazyClone() {
var result = new LazyWrapper(this.__wrapped__);
result.__actions__ = arrayCopy(this.__actions__);
result.__dir__ = this.__dir__;
result.__filtered__ = this.__filtered__;
result.__iteratees__ = arrayCopy(this.__iteratees__);
result.__takeCount__ = this.__takeCount__;
result.__views__ = arrayCopy(this.__views__);
return result;
}
/**
* Reverses the direction of lazy iteration.
*
* @private
* @name reverse
* @memberOf LazyWrapper
* @returns {Object} Returns the new reversed `LazyWrapper` object.
*/
function lazyReverse() {
if (this.__filtered__) {
var result = new LazyWrapper(this);
result.__dir__ = -1;
result.__filtered__ = true;
} else {
result = this.clone();
result.__dir__ *= -1;
}
return result;
}
/**
* Extracts the unwrapped value from its lazy wrapper.
*
* @private
* @name value
* @memberOf LazyWrapper
* @returns {*} Returns the unwrapped value.
*/
function lazyValue() {
var array = this.__wrapped__.value(),
dir = this.__dir__,
isArr = isArray(array),
isRight = dir < 0,
arrLength = isArr ? array.length : 0,
view = getView(0, arrLength, this.__views__),
start = view.start,
end = view.end,
length = end - start,
index = isRight ? end : (start - 1),
iteratees = this.__iteratees__,
iterLength = iteratees.length,
resIndex = 0,
takeCount = nativeMin(length, this.__takeCount__);
if (!isArr || arrLength < LARGE_ARRAY_SIZE || (arrLength == length && takeCount == length)) {
return baseWrapperValue((isRight && isArr) ? array.reverse() : array, this.__actions__);
}
var result = [];
outer:
while (length-- && resIndex < takeCount) {
index += dir;
var iterIndex = -1,
value = array[index];
while (++iterIndex < iterLength) {
var data = iteratees[iterIndex],
iteratee = data.iteratee,
type = data.type,
computed = iteratee(value);
if (type == LAZY_MAP_FLAG) {
value = computed;
} else if (!computed) {
if (type == LAZY_FILTER_FLAG) {
continue outer;
} else {
break outer;
}
}
}
result[resIndex++] = value;
}
return result;
}
/*------------------------------------------------------------------------*/
/**
* Creates a cache object to store key/value pairs.
*
* @private
* @static
* @name Cache
* @memberOf _.memoize
*/
function MapCache() {
this.__data__ = {};
}
/**
* Removes `key` and its value from the cache.
*
* @private
* @name delete
* @memberOf _.memoize.Cache
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed successfully, else `false`.
*/
function mapDelete(key) {
return this.has(key) && delete this.__data__[key];
}
/**
* Gets the cached value for `key`.
*
* @private
* @name get
* @memberOf _.memoize.Cache
* @param {string} key The key of the value to get.
* @returns {*} Returns the cached value.
*/
function mapGet(key) {
return key == '__proto__' ? undefined : this.__data__[key];
}
/**
* Checks if a cached value for `key` exists.
*
* @private
* @name has
* @memberOf _.memoize.Cache
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/
function mapHas(key) {
return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
}
/**
* Sets `value` to `key` of the cache.
*
* @private
* @name set
* @memberOf _.memoize.Cache
* @param {string} key The key of the value to cache.
* @param {*} value The value to cache.
* @returns {Object} Returns the cache object.
*/
function mapSet(key, value) {
if (key != '__proto__') {
this.__data__[key] = value;
}
return this;
}
/*------------------------------------------------------------------------*/
/**
*
* Creates a cache object to store unique values.
*
* @private
* @param {Array} [values] The values to cache.
*/
function SetCache(values) {
var length = values ? values.length : 0;
this.data = { 'hash': nativeCreate(null), 'set': new Set };
while (length--) {
this.push(values[length]);
}
}
/**
* Checks if `value` is in `cache` mimicking the return signature of
* `_.indexOf` by returning `0` if the value is found, else `-1`.
*
* @private
* @param {Object} cache The cache to search.
* @param {*} value The value to search for.
* @returns {number} Returns `0` if `value` is found, else `-1`.
*/
function cacheIndexOf(cache, value) {
var data = cache.data,
result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value];
return result ? 0 : -1;
}
/**
* Adds `value` to the cache.
*
* @private
* @name push
* @memberOf SetCache
* @param {*} value The value to cache.
*/
function cachePush(value) {
var data = this.data;
if (typeof value == 'string' || isObject(value)) {
data.set.add(value);
} else {
data.hash[value] = true;
}
}
/*------------------------------------------------------------------------*/
/**
* Creates a new array joining `array` with `other`.
*
* @private
* @param {Array} array The array to join.
* @param {Array} other The other array to join.
* @returns {Array} Returns the new concatenated array.
*/
function arrayConcat(array, other) {
var index = -1,
length = array.length,
othIndex = -1,
othLength = other.length,
result = Array(length + othLength);
while (++index < length) {
result[index] = array[index];
}
while (++othIndex < othLength) {
result[index++] = other[othIndex];
}
return result;
}
/**
* Copies the values of `source` to `array`.
*
* @private
* @param {Array} source The array to copy values from.
* @param {Array} [array=[]] The array to copy values to.
* @returns {Array} Returns `array`.
*/
function arrayCopy(source, array) {
var index = -1,
length = source.length;
array || (array = Array(length));
while (++index < length) {
array[index] = source[index];
}
return array;
}
/**
* A specialized version of `_.forEach` for arrays without support for callback
* shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns `array`.
*/
function arrayEach(array, iteratee) {
var index = -1,
length = array.length;
while (++index < length) {
if (iteratee(array[index], index, array) === false) {
break;
}
}
return array;
}
/**
* A specialized version of `_.forEachRight` for arrays without support for
* callback shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns `array`.
*/
function arrayEachRight(array, iteratee) {
var length = array.length;
while (length--) {
if (iteratee(array[length], length, array) === false) {
break;
}
}
return array;
}
/**
* A specialized version of `_.every` for arrays without support for callback
* shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {boolean} Returns `true` if all elements pass the predicate check,
* else `false`.
*/
function arrayEvery(array, predicate) {
var index = -1,
length = array.length;
while (++index < length) {
if (!predicate(array[index], index, array)) {
return false;
}
}
return true;
}
/**
* A specialized version of `baseExtremum` for arrays which invokes `iteratee`
* with one argument: (value).
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {Function} comparator The function used to compare values.
* @param {*} exValue The initial extremum value.
* @returns {*} Returns the extremum value.
*/
function arrayExtremum(array, iteratee, comparator, exValue) {
var index = -1,
length = array.length,
computed = exValue,
result = computed;
while (++index < length) {
var value = array[index],
current = +iteratee(value);
if (comparator(current, computed)) {
computed = current;
result = value;
}
}
return result;
}
/**
* A specialized version of `_.filter` for arrays without support for callback
* shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the new filtered array.
*/
function arrayFilter(array, predicate) {
var index = -1,
length = array.length,
resIndex = -1,
result = [];
while (++index < length) {
var value = array[index];
if (predicate(value, index, array)) {
result[++resIndex] = value;
}
}
return result;
}
/**
* A specialized version of `_.map` for arrays without support for callback
* shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the new mapped array.
*/
function arrayMap(array, iteratee) {
var index = -1,
length = array.length,
result = Array(length);
while (++index < length) {
result[index] = iteratee(array[index], index, array);
}
return result;
}
/**
* Appends the elements of `values` to `array`.
*
* @private
* @param {Array} array The array to modify.
* @param {Array} values The values to append.
* @returns {Array} Returns `array`.
*/
function arrayPush(array, values) {
var index = -1,
length = values.length,
offset = array.length;
while (++index < length) {
array[offset + index] = values[index];
}
return array;
}
/**
* A specialized version of `_.reduce` for arrays without support for callback
* shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {*} [accumulator] The initial value.
* @param {boolean} [initFromArray] Specify using the first element of `array`
* as the initial value.
* @returns {*} Returns the accumulated value.
*/
function arrayReduce(array, iteratee, accumulator, initFromArray) {
var index = -1,
length = array.length;
if (initFromArray && length) {
accumulator = array[++index];
}
while (++index < length) {
accumulator = iteratee(accumulator, array[index], index, array);
}
return accumulator;
}
/**
* A specialized version of `_.reduceRight` for arrays without support for
* callback shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {*} [accumulator] The initial value.
* @param {boolean} [initFromArray] Specify using the last element of `array`
* as the initial value.
* @returns {*} Returns the accumulated value.
*/
function arrayReduceRight(array, iteratee, accumulator, initFromArray) {
var length = array.length;
if (initFromArray && length) {
accumulator = array[--length];
}
while (length--) {
accumulator = iteratee(accumulator, array[length], length, array);
}
return accumulator;
}
/**
* A specialized version of `_.some` for arrays without support for callback
* shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {boolean} Returns `true` if any element passes the predicate check,
* else `false`.
*/
function arraySome(array, predicate) {
var index = -1,
length = array.length;
while (++index < length) {
if (predicate(array[index], index, array)) {
return true;
}
}
return false;
}
/**
* A specialized version of `_.sum` for arrays without support for callback
* shorthands and `this` binding..
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {number} Returns the sum.
*/
function arraySum(array, iteratee) {
var length = array.length,
result = 0;
while (length--) {
result += +iteratee(array[length]) || 0;
}
return result;
}
/**
* Used by `_.defaults` to customize its `_.assign` use.
*
* @private
* @param {*} objectValue The destination object property value.
* @param {*} sourceValue The source object property value.
* @returns {*} Returns the value to assign to the destination object.
*/
function assignDefaults(objectValue, sourceValue) {
return objectValue === undefined ? sourceValue : objectValue;
}
/**
* Used by `_.template` to customize its `_.assign` use.
*
* **Note:** This function is like `assignDefaults` except that it ignores
* inherited property values when checking if a property is `undefined`.
*
* @private
* @param {*} objectValue The destination object property value.
* @param {*} sourceValue The source object property value.
* @param {string} key The key associated with the object and source values.
* @param {Object} object The destination object.
* @returns {*} Returns the value to assign to the destination object.
*/
function assignOwnDefaults(objectValue, sourceValue, key, object) {
return (objectValue === undefined || !hasOwnProperty.call(object, key))
? sourceValue
: objectValue;
}
/**
* A specialized version of `_.assign` for customizing assigned values without
* support for argument juggling, multiple sources, and `this` binding `customizer`
* functions.
*
* @private
* @param {Object} object The destination object.
* @param {Object} source The source object.
* @param {Function} customizer The function to customize assigned values.
* @returns {Object} Returns `object`.
*/
function assignWith(object, source, customizer) {
var index = -1,
props = keys(source),
length = props.length;
while (++index < length) {
var key = props[index],
value = object[key],
result = customizer(value, source[key], key, object, source);
if ((result === result ? (result !== value) : (value === value)) ||
(value === undefined && !(key in object))) {
object[key] = result;
}
}
return object;
}
/**
* The base implementation of `_.assign` without support for argument juggling,
* multiple sources, and `customizer` functions.
*
* @private
* @param {Object} object The destination object.
* @param {Object} source The source object.
* @returns {Object} Returns `object`.
*/
function baseAssign(object, source) {
return source == null
? object
: baseCopy(source, keys(source), object);
}
/**
* The base implementation of `_.at` without support for string collections
* and individual key arguments.
*
* @private
* @param {Array|Object} collection The collection to iterate over.
* @param {number[]|string[]} props The property names or indexes of elements to pick.
* @returns {Array} Returns the new array of picked elements.
*/
function baseAt(collection, props) {
var index = -1,
isNil = collection == null,
isArr = !isNil && isArrayLike(collection),
length = isArr ? collection.length : 0,
propsLength = props.length,
result = Array(propsLength);
while(++index < propsLength) {
var key = props[index];
if (isArr) {
result[index] = isIndex(key, length) ? collection[key] : undefined;
} else {
result[index] = isNil ? undefined : collection[key];
}
}
return result;
}
/**
* Copies properties of `source` to `object`.
*
* @private
* @param {Object} source The object to copy properties from.
* @param {Array} props The property names to copy.
* @param {Object} [object={}] The object to copy properties to.
* @returns {Object} Returns `object`.
*/
function baseCopy(source, props, object) {
object || (object = {});
var index = -1,
length = props.length;
while (++index < length) {
var key = props[index];
object[key] = source[key];
}
return object;
}
/**
* The base implementation of `_.callback` which supports specifying the
* number of arguments to provide to `func`.
*
* @private
* @param {*} [func=_.identity] The value to convert to a callback.
* @param {*} [thisArg] The `this` binding of `func`.
* @param {number} [argCount] The number of arguments to provide to `func`.
* @returns {Function} Returns the callback.
*/
function baseCallback(func, thisArg, argCount) {
var type = typeof func;
if (type == 'function') {
return thisArg === undefined
? func
: bindCallback(func, thisArg, argCount);
}
if (func == null) {
return identity;
}
if (type == 'object') {
return baseMatches(func);
}
return thisArg === undefined
? property(func)
: baseMatchesProperty(func, thisArg);
}
/**
* The base implementation of `_.clone` without support for argument juggling
* and `this` binding `customizer` functions.
*
* @private
* @param {*} value The value to clone.
* @param {boolean} [isDeep] Specify a deep clone.
* @param {Function} [customizer] The function to customize cloning values.
* @param {string} [key] The key of `value`.
* @param {Object} [object] The object `value` belongs to.
* @param {Array} [stackA=[]] Tracks traversed source objects.
* @param {Array} [stackB=[]] Associates clones with source counterparts.
* @returns {*} Returns the cloned value.
*/
function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
var result;
if (customizer) {
result = object ? customizer(value, key, object) : customizer(value);
}
if (result !== undefined) {
return result;
}
if (!isObject(value)) {
return value;
}
var isArr = isArray(value);
if (isArr) {
result = initCloneArray(value);
if (!isDeep) {
return arrayCopy(value, result);
}
} else {
var tag = objToString.call(value),
isFunc = tag == funcTag;
if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
result = initCloneObject(isFunc ? {} : value);
if (!isDeep) {
return baseAssign(result, value);
}
} else {
return cloneableTags[tag]
? initCloneByTag(value, tag, isDeep)
: (object ? value : {});
}
}
// Check for circular references and return its corresponding clone.
stackA || (stackA = []);
stackB || (stackB = []);
var length = stackA.length;
while (length--) {
if (stackA[length] == value) {
return stackB[length];
}
}
// Add the source value to the stack of traversed objects and associate it with its clone.
stackA.push(value);
stackB.push(result);
// Recursively populate clone (susceptible to call stack limits).
(isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
result[key] = baseClone(subValue, isDeep, customizer, key, value, stackA, stackB);
});
return result;
}
/**
* The base implementation of `_.create` without support for assigning
* properties to the created object.
*
* @private
* @param {Object} prototype The object to inherit from.
* @returns {Object} Returns the new object.
*/
var baseCreate = (function() {
function object() {}
return function(prototype) {
if (isObject(prototype)) {
object.prototype = prototype;
var result = new object;
object.prototype = undefined;
}
return result || {};
};
}());
/**
* The base implementation of `_.delay` and `_.defer` which accepts an index
* of where to slice the arguments to provide to `func`.
*
* @private
* @param {Function} func The function to delay.
* @param {number} wait The number of milliseconds to delay invocation.
* @param {Object} args The arguments provide to `func`.
* @returns {number} Returns the timer id.
*/
function baseDelay(func, wait, args) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
return setTimeout(function() { func.apply(undefined, args); }, wait);
}
/**
* The base implementation of `_.difference` which accepts a single array
* of values to exclude.
*
* @private
* @param {Array} array The array to inspect.
* @param {Array} values The values to exclude.
* @returns {Array} Returns the new array of filtered values.
*/
function baseDifference(array, values) {
var length = array ? array.length : 0,
result = [];
if (!length) {
return result;
}
var index = -1,
indexOf = getIndexOf(),
isCommon = indexOf == baseIndexOf,
cache = (isCommon && values.length >= LARGE_ARRAY_SIZE) ? createCache(values) : null,
valuesLength = values.length;
if (cache) {
indexOf = cacheIndexOf;
isCommon = false;
values = cache;
}
outer:
while (++index < length) {
var value = array[index];
if (isCommon && value === value) {
var valuesIndex = valuesLength;
while (valuesIndex--) {
if (values[valuesIndex] === value) {
continue outer;
}
}
result.push(value);
}
else if (indexOf(values, value, 0) < 0) {
result.push(value);
}
}
return result;
}
/**
* The base implementation of `_.forEach` without support for callback
* shorthands and `this` binding.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array|Object|string} Returns `collection`.
*/
var baseEach = createBaseEach(baseForOwn);
/**
* The base implementation of `_.forEachRight` without support for callback
* shorthands and `this` binding.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array|Object|string} Returns `collection`.
*/
var baseEachRight = createBaseEach(baseForOwnRight, true);
/**
* The base implementation of `_.every` without support for callback
* shorthands and `this` binding.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {boolean} Returns `true` if all elements pass the predicate check,
* else `false`
*/
function baseEvery(collection, predicate) {
var result = true;
baseEach(collection, function(value, index, collection) {
result = !!predicate(value, index, collection);
return result;
});
return result;
}
/**
* Gets the extremum value of `collection` invoking `iteratee` for each value
* in `collection` to generate the criterion by which the value is ranked.
* The `iteratee` is invoked with three arguments: (value, index|key, collection).
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {Function} comparator The function used to compare values.
* @param {*} exValue The initial extremum value.
* @returns {*} Returns the extremum value.
*/
function baseExtremum(collection, iteratee, comparator, exValue) {
var computed = exValue,
result = computed;
baseEach(collection, function(value, index, collection) {
var current = +iteratee(value, index, collection);
if (comparator(current, computed) || (current === exValue && current === result)) {
computed = current;
result = value;
}
});
return result;
}
/**
* The base implementation of `_.fill` without an iteratee call guard.
*
* @private
* @param {Array} array The array to fill.
* @param {*} value The value to fill `array` with.
* @param {number} [start=0] The start position.
* @param {number} [end=array.length] The end position.
* @returns {Array} Returns `array`.
*/
function baseFill(array, value, start, end) {
var length = array.length;
start = start == null ? 0 : (+start || 0);
if (start < 0) {
start = -start > length ? 0 : (length + start);
}
end = (end === undefined || end > length) ? length : (+end || 0);
if (end < 0) {
end += length;
}
length = start > end ? 0 : (end >>> 0);
start >>>= 0;
while (start < length) {
array[start++] = value;
}
return array;
}
/**
* The base implementation of `_.filter` without support for callback
* shorthands and `this` binding.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the new filtered array.
*/
function baseFilter(collection, predicate) {
var result = [];
baseEach(collection, function(value, index, collection) {
if (predicate(value, index, collection)) {
result.push(value);
}
});
return result;
}
/**
* The base implementation of `_.find`, `_.findLast`, `_.findKey`, and `_.findLastKey`,
* without support for callback shorthands and `this` binding, which iterates
* over `collection` using the provided `eachFunc`.
*
* @private
* @param {Array|Object|string} collection The collection to search.
* @param {Function} predicate The function invoked per iteration.
* @param {Function} eachFunc The function to iterate over `collection`.
* @param {boolean} [retKey] Specify returning the key of the found element
* instead of the element itself.
* @returns {*} Returns the found element or its key, else `undefined`.
*/
function baseFind(collection, predicate, eachFunc, retKey) {
var result;
eachFunc(collection, function(value, key, collection) {
if (predicate(value, key, collection)) {
result = retKey ? key : value;
return false;
}
});
return result;
}
/**
* The base implementation of `_.flatten` with added support for restricting
* flattening and specifying the start index.
*
* @private
* @param {Array} array The array to flatten.
* @param {boolean} [isDeep] Specify a deep flatten.
* @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
* @param {Array} [result=[]] The initial result value.
* @returns {Array} Returns the new flattened array.
*/
function baseFlatten(array, isDeep, isStrict, result) {
result || (result = []);
var index = -1,
length = array.length;
while (++index < length) {
var value = array[index];
if (isObjectLike(value) && isArrayLike(value) &&
(isStrict || isArray(value) || isArguments(value))) {
if (isDeep) {
// Recursively flatten arrays (susceptible to call stack limits).
baseFlatten(value, isDeep, isStrict, result);
} else {
arrayPush(result, value);
}
} else if (!isStrict) {
result[result.length] = value;
}
}
return result;
}
/**
* The base implementation of `baseForIn` and `baseForOwn` which iterates
* over `object` properties returned by `keysFunc` invoking `iteratee` for
* each property. Iteratee functions may exit iteration early by explicitly
* returning `false`.
*
* @private
* @param {Object} object The object to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {Function} keysFunc The function to get the keys of `object`.
* @returns {Object} Returns `object`.
*/
var baseFor = createBaseFor();
/**
* This function is like `baseFor` except that it iterates over properties
* in the opposite order.
*
* @private
* @param {Object} object The object to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {Function} keysFunc The function to get the keys of `object`.
* @returns {Object} Returns `object`.
*/
var baseForRight = createBaseFor(true);
/**
* The base implementation of `_.forIn` without support for callback
* shorthands and `this` binding.
*
* @private
* @param {Object} object The object to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Object} Returns `object`.
*/
function baseForIn(object, iteratee) {
return baseFor(object, iteratee, keysIn);
}
/**
* The base implementation of `_.forOwn` without support for callback
* shorthands and `this` binding.
*
* @private
* @param {Object} object The object to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Object} Returns `object`.
*/
function baseForOwn(object, iteratee) {
return baseFor(object, iteratee, keys);
}
/**
* The base implementation of `_.forOwnRight` without support for callback
* shorthands and `this` binding.
*
* @private
* @param {Object} object The object to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Object} Returns `object`.
*/
function baseForOwnRight(object, iteratee) {
return baseForRight(object, iteratee, keys);
}
/**
* The base implementation of `_.functions` which creates an array of
* `object` function property names filtered from those provided.
*
* @private
* @param {Object} object The object to inspect.
* @param {Array} props The property names to filter.
* @returns {Array} Returns the new array of filtered property names.
*/
function baseFunctions(object, props) {
var index = -1,
length = props.length,
resIndex = -1,
result = [];
while (++index < length) {
var key = props[index];
if (isFunction(object[key])) {
result[++resIndex] = key;
}
}
return result;
}
/**
* The base implementation of `get` without support for string paths
* and default values.
*
* @private
* @param {Object} object The object to query.
* @param {Array} path The path of the property to get.
* @param {string} [pathKey] The key representation of path.
* @returns {*} Returns the resolved value.
*/
function baseGet(object, path, pathKey) {
if (object == null) {
return;
}
if (pathKey !== undefined && pathKey in toObject(object)) {
path = [pathKey];
}
var index = 0,
length = path.length;
while (object != null && index < length) {
object = object[path[index++]];
}
return (index && index == length) ? object : undefined;
}
/**
* The base implementation of `_.isEqual` without support for `this` binding
* `customizer` functions.
*
* @private
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @param {Function} [customizer] The function to customize comparing values.
* @param {boolean} [isLoose] Specify performing partial comparisons.
* @param {Array} [stackA] Tracks traversed `value` objects.
* @param {Array} [stackB] Tracks traversed `other` objects.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
*/
function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
if (value === other) {
return true;
}
if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
return value !== value && other !== other;
}
return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
}
/**
* A specialized version of `baseIsEqual` for arrays and objects which performs
* deep comparisons and tracks traversed objects enabling objects with circular
* references to be compared.
*
* @private
* @param {Object} object The object to compare.
* @param {Object} other The other object to compare.
* @param {Function} equalFunc The function to determine equivalents of values.
* @param {Function} [customizer] The function to customize comparing objects.
* @param {boolean} [isLoose] Specify performing partial comparisons.
* @param {Array} [stackA=[]] Tracks traversed `value` objects.
* @param {Array} [stackB=[]] Tracks traversed `other` objects.
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
*/
function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
var objIsArr = isArray(object),
othIsArr = isArray(other),
objTag = arrayTag,
othTag = arrayTag;
if (!objIsArr) {
objTag = objToString.call(object);
if (objTag == argsTag) {
objTag = objectTag;
} else if (objTag != objectTag) {
objIsArr = isTypedArray(object);
}
}
if (!othIsArr) {
othTag = objToString.call(other);
if (othTag == argsTag) {
othTag = objectTag;
} else if (othTag != objectTag) {
othIsArr = isTypedArray(other);
}
}
var objIsObj = objTag == objectTag,
othIsObj = othTag == objectTag,
isSameTag = objTag == othTag;
if (isSameTag && !(objIsArr || objIsObj)) {
return equalByTag(object, other, objTag);
}
if (!isLoose) {
var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
if (objIsWrapped || othIsWrapped) {
return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
}
}
if (!isSameTag) {
return false;
}
// Assume cyclic values are equal.
// For more information on detecting circular references see https://es5.github.io/#JO.
stackA || (stackA = []);
stackB || (stackB = []);
var length = stackA.length;
while (length--) {
if (stackA[length] == object) {
return stackB[length] == other;
}
}
// Add `object` and `other` to the stack of traversed objects.
stackA.push(object);
stackB.push(other);
var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isLoose, stackA, stackB);
stackA.pop();
stackB.pop();
return result;
}
/**
* The base implementation of `_.isMatch` without support for callback
* shorthands and `this` binding.
*
* @private
* @param {Object} object The object to inspect.
* @param {Array} matchData The propery names, values, and compare flags to match.
* @param {Function} [customizer] The function to customize comparing objects.
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
*/
function baseIsMatch(object, matchData, customizer) {
var index = matchData.length,
length = index,
noCustomizer = !customizer;
if (object == null) {
return !length;
}
object = toObject(object);
while (index--) {
var data = matchData[index];
if ((noCustomizer && data[2])
? data[1] !== object[data[0]]
: !(data[0] in object)
) {
return false;
}
}
while (++index < length) {
data = matchData[index];
var key = data[0],
objValue = object[key],
srcValue = data[1];
if (noCustomizer && data[2]) {
if (objValue === undefined && !(key in object)) {
return false;
}
} else {
var result = customizer ? customizer(objValue, srcValue, key) : undefined;
if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, true) : result)) {
return false;
}
}
}
return true;
}
/**
* The base implementation of `_.map` without support for callback shorthands
* and `this` binding.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the new mapped array.
*/
function baseMap(collection, iteratee) {
var index = -1,
result = isArrayLike(collection) ? Array(collection.length) : [];
baseEach(collection, function(value, key, collection) {
result[++index] = iteratee(value, key, collection);
});
return result;
}
/**
* The base implementation of `_.matches` which does not clone `source`.
*
* @private
* @param {Object} source The object of property values to match.
* @returns {Function} Returns the new function.
*/
function baseMatches(source) {
var matchData = getMatchData(source);
if (matchData.length == 1 && matchData[0][2]) {
var key = matchData[0][0],
value = matchData[0][1];
return function(object) {
if (object == null) {
return false;
}
return object[key] === value && (value !== undefined || (key in toObject(object)));
};
}
return function(object) {
return baseIsMatch(object, matchData);
};
}
/**
* The base implementation of `_.matchesProperty` which does not clone `srcValue`.
*
* @private
* @param {string} path The path of the property to get.
* @param {*} srcValue The value to compare.
* @returns {Function} Returns the new function.
*/
function baseMatchesProperty(path, srcValue) {
var isArr = isArray(path),
isCommon = isKey(path) && isStrictComparable(srcValue),
pathKey = (path + '');
path = toPath(path);
return function(object) {
if (object == null) {
return false;
}
var key = pathKey;
object = toObject(object);
if ((isArr || !isCommon) && !(key in object)) {
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
if (object == null) {
return false;
}
key = last(path);
object = toObject(object);
}
return object[key] === srcValue
? (srcValue !== undefined || (key in object))
: baseIsEqual(srcValue, object[key], undefined, true);
};
}
/**
* The base implementation of `_.merge` without support for argument juggling,
* multiple sources, and `this` binding `customizer` functions.
*
* @private
* @param {Object} object The destination object.
* @param {Object} source The source object.
* @param {Function} [customizer] The function to customize merged values.
* @param {Array} [stackA=[]] Tracks traversed source objects.
* @param {Array} [stackB=[]] Associates values with source counterparts.
* @returns {Object} Returns `object`.
*/
function baseMerge(object, source, customizer, stackA, stackB) {
if (!isObject(object)) {
return object;
}
var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)),
props = isSrcArr ? undefined : keys(source);
arrayEach(props || source, function(srcValue, key) {
if (props) {
key = srcValue;
srcValue = source[key];
}
if (isObjectLike(srcValue)) {
stackA || (stackA = []);
stackB || (stackB = []);
baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
}
else {
var value = object[key],
result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
isCommon = result === undefined;
if (isCommon) {
result = srcValue;
}
if ((result !== undefined || (isSrcArr && !(key in object))) &&
(isCommon || (result === result ? (result !== value) : (value === value)))) {
object[key] = result;
}
}
});
return object;
}
/**
* A specialized version of `baseMerge` for arrays and objects which performs
* deep merges and tracks traversed objects enabling objects with circular
* references to be merged.
*
* @private
* @param {Object} object The destination object.
* @param {Object} source The source object.
* @param {string} key The key of the value to merge.
* @param {Function} mergeFunc The function to merge values.
* @param {Function} [customizer] The function to customize merged values.
* @param {Array} [stackA=[]] Tracks traversed source objects.
* @param {Array} [stackB=[]] Associates values with source counterparts.
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
*/
function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stackB) {
var length = stackA.length,
srcValue = source[key];
while (length--) {
if (stackA[length] == srcValue) {
object[key] = stackB[length];
return;
}
}
var value = object[key],
result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
isCommon = result === undefined;
if (isCommon) {
result = srcValue;
if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) {
result = isArray(value)
? value
: (isArrayLike(value) ? arrayCopy(value) : []);
}
else if (isPlainObject(srcValue) || isArguments(srcValue)) {
result = isArguments(value)
? toPlainObject(value)
: (isPlainObject(value) ? value : {});
}
else {
isCommon = false;
}
}
// Add the source value to the stack of traversed objects and associate
// it with its merged value.
stackA.push(srcValue);
stackB.push(result);
if (isCommon) {
// Recursively merge objects and arrays (susceptible to call stack limits).
object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB);
} else if (result === result ? (result !== value) : (value === value)) {
object[key] = result;
}
}
/**
* The base implementation of `_.property` without support for deep paths.
*
* @private
* @param {string} key The key of the property to get.
* @returns {Function} Returns the new function.
*/
function baseProperty(key) {
return function(object) {
return object == null ? undefined : object[key];
};
}
/**
* A specialized version of `baseProperty` which supports deep paths.
*
* @private
* @param {Array|string} path The path of the property to get.
* @returns {Function} Returns the new function.
*/
function basePropertyDeep(path) {
var pathKey = (path + '');
path = toPath(path);
return function(object) {
return baseGet(object, path, pathKey);
};
}
/**
* The base implementation of `_.pullAt` without support for individual
* index arguments and capturing the removed elements.
*
* @private
* @param {Array} array The array to modify.
* @param {number[]} indexes The indexes of elements to remove.
* @returns {Array} Returns `array`.
*/
function basePullAt(array, indexes) {
var length = array ? indexes.length : 0;
while (length--) {
var index = indexes[length];
if (index != previous && isIndex(index)) {
var previous = index;
splice.call(array, index, 1);
}
}
return array;
}
/**
* The base implementation of `_.random` without support for argument juggling
* and returning floating-point numbers.
*
* @private
* @param {number} min The minimum possible value.
* @param {number} max The maximum possible value.
* @returns {number} Returns the random number.
*/
function baseRandom(min, max) {
return min + nativeFloor(nativeRandom() * (max - min + 1));
}
/**
* The base implementation of `_.reduce` and `_.reduceRight` without support
* for callback shorthands and `this` binding, which iterates over `collection`
* using the provided `eachFunc`.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {*} accumulator The initial value.
* @param {boolean} initFromCollection Specify using the first or last element
* of `collection` as the initial value.
* @param {Function} eachFunc The function to iterate over `collection`.
* @returns {*} Returns the accumulated value.
*/
function baseReduce(collection, iteratee, accumulator, initFromCollection, eachFunc) {
eachFunc(collection, function(value, index, collection) {
accumulator = initFromCollection
? (initFromCollection = false, value)
: iteratee(accumulator, value, index, collection);
});
return accumulator;
}
/**
* The base implementation of `setData` without support for hot loop detection.
*
* @private
* @param {Function} func The function to associate metadata with.
* @param {*} data The metadata.
* @returns {Function} Returns `func`.
*/
var baseSetData = !metaMap ? identity : function(func, data) {
metaMap.set(func, data);
return func;
};
/**
* The base implementation of `_.slice` without an iteratee call guard.
*
* @private
* @param {Array} array The array to slice.
* @param {number} [start=0] The start position.
* @param {number} [end=array.length] The end position.
* @returns {Array} Returns the slice of `array`.
*/
function baseSlice(array, start, end) {
var index = -1,
length = array.length;
start = start == null ? 0 : (+start || 0);
if (start < 0) {
start = -start > length ? 0 : (length + start);
}
end = (end === undefined || end > length) ? length : (+end || 0);
if (end < 0) {
end += length;
}
length = start > end ? 0 : ((end - start) >>> 0);
start >>>= 0;
var result = Array(length);
while (++index < length) {
result[index] = array[index + start];
}
return result;
}
/**
* The base implementation of `_.some` without support for callback shorthands
* and `this` binding.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {boolean} Returns `true` if any element passes the predicate check,
* else `false`.
*/
function baseSome(collection, predicate) {
var result;
baseEach(collection, function(value, index, collection) {
result = predicate(value, index, collection);
return !result;
});
return !!result;
}
/**
* The base implementation of `_.sortBy` which uses `comparer` to define
* the sort order of `array` and replaces criteria objects with their
* corresponding values.
*
* @private
* @param {Array} array The array to sort.
* @param {Function} comparer The function to define sort order.
* @returns {Array} Returns `array`.
*/
function baseSortBy(array, comparer) {
var length = array.length;
array.sort(comparer);
while (length--) {
array[length] = array[length].value;
}
return array;
}
/**
* The base implementation of `_.sortByOrder` without param guards.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
* @param {boolean[]} orders The sort orders of `iteratees`.
* @returns {Array} Returns the new sorted array.
*/
function baseSortByOrder(collection, iteratees, orders) {
var callback = getCallback(),
index = -1;
iteratees = arrayMap(iteratees, function(iteratee) { return callback(iteratee); });
var result = baseMap(collection, function(value) {
var criteria = arrayMap(iteratees, function(iteratee) { return iteratee(value); });
return { 'criteria': criteria, 'index': ++index, 'value': value };
});
return baseSortBy(result, function(object, other) {
return compareMultiple(object, other, orders);
});
}
/**
* The base implementation of `_.sum` without support for callback shorthands
* and `this` binding.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {number} Returns the sum.
*/
function baseSum(collection, iteratee) {
var result = 0;
baseEach(collection, function(value, index, collection) {
result += +iteratee(value, index, collection) || 0;
});
return result;
}
/**
* The base implementation of `_.uniq` without support for callback shorthands
* and `this` binding.
*
* @private
* @param {Array} array The array to inspect.
* @param {Function} [iteratee] The function invoked per iteration.
* @returns {Array} Returns the new duplicate-value-free array.
*/
function baseUniq(array, iteratee) {
var index = -1,
indexOf = getIndexOf(),
length = array.length,
isCommon = indexOf == baseIndexOf,
isLarge = isCommon && length >= LARGE_ARRAY_SIZE,
seen = isLarge ? createCache() : null,
result = [];
if (seen) {
indexOf = cacheIndexOf;
isCommon = false;
} else {
isLarge = false;
seen = iteratee ? [] : result;
}
outer:
while (++index < length) {
var value = array[index],
computed = iteratee ? iteratee(value, index, array) : value;
if (isCommon && value === value) {
var seenIndex = seen.length;
while (seenIndex--) {
if (seen[seenIndex] === computed) {
continue outer;
}
}
if (iteratee) {
seen.push(computed);
}
result.push(value);
}
else if (indexOf(seen, computed, 0) < 0) {
if (iteratee || isLarge) {
seen.push(computed);
}
result.push(value);
}
}
return result;
}
/**
* The base implementation of `_.values` and `_.valuesIn` which creates an
* array of `object` property values corresponding to the property names
* of `props`.
*
* @private
* @param {Object} object The object to query.
* @param {Array} props The property names to get values for.
* @returns {Object} Returns the array of property values.
*/
function baseValues(object, props) {
var index = -1,
length = props.length,
result = Array(length);
while (++index < length) {
result[index] = object[props[index]];
}
return result;
}
/**
* The base implementation of `_.dropRightWhile`, `_.dropWhile`, `_.takeRightWhile`,
* and `_.takeWhile` without support for callback shorthands and `this` binding.
*
* @private
* @param {Array} array The array to query.
* @param {Function} predicate The function invoked per iteration.
* @param {boolean} [isDrop] Specify dropping elements instead of taking them.
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Array} Returns the slice of `array`.
*/
function baseWhile(array, predicate, isDrop, fromRight) {
var length = array.length,
index = fromRight ? length : -1;
while ((fromRight ? index-- : ++index < length) && predicate(array[index], index, array)) {}
return isDrop
? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
: baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
}
/**
* The base implementation of `wrapperValue` which returns the result of
* performing a sequence of actions on the unwrapped `value`, where each
* successive action is supplied the return value of the previous.
*
* @private
* @param {*} value The unwrapped value.
* @param {Array} actions Actions to peform to resolve the unwrapped value.
* @returns {*} Returns the resolved value.
*/
function baseWrapperValue(value, actions) {
var result = value;
if (result instanceof LazyWrapper) {
result = result.value();
}
var index = -1,
length = actions.length;
while (++index < length) {
var action = actions[index];
result = action.func.apply(action.thisArg, arrayPush([result], action.args));
}
return result;
}
/**
* Performs a binary search of `array` to determine the index at which `value`
* should be inserted into `array` in order to maintain its sort order.
*
* @private
* @param {Array} array The sorted array to inspect.
* @param {*} value The value to evaluate.
* @param {boolean} [retHighest] Specify returning the highest qualified index.
* @returns {number} Returns the index at which `value` should be inserted
* into `array`.
*/
function binaryIndex(array, value, retHighest) {
var low = 0,
high = array ? array.length : low;
if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
while (low < high) {
var mid = (low + high) >>> 1,
computed = array[mid];
if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) {
low = mid + 1;
} else {
high = mid;
}
}
return high;
}
return binaryIndexBy(array, value, identity, retHighest);
}
/**
* This function is like `binaryIndex` except that it invokes `iteratee` for
* `value` and each element of `array` to compute their sort ranking. The
* iteratee is invoked with one argument; (value).
*
* @private
* @param {Array} array The sorted array to inspect.
* @param {*} value The value to evaluate.
* @param {Function} iteratee The function invoked per iteration.
* @param {boolean} [retHighest] Specify returning the highest qualified index.
* @returns {number} Returns the index at which `value` should be inserted
* into `array`.
*/
function binaryIndexBy(array, value, iteratee, retHighest) {
value = iteratee(value);
var low = 0,
high = array ? array.length : 0,
valIsNaN = value !== value,
valIsNull = value === null,
valIsUndef = value === undefined;
while (low < high) {
var mid = nativeFloor((low + high) / 2),
computed = iteratee(array[mid]),
isDef = computed !== undefined,
isReflexive = computed === computed;
if (valIsNaN) {
var setLow = isReflexive || retHighest;
} else if (valIsNull) {
setLow = isReflexive && isDef && (retHighest || computed != null);
} else if (valIsUndef) {
setLow = isReflexive && (retHighest || isDef);
} else if (computed == null) {
setLow = false;
} else {
setLow = retHighest ? (computed <= value) : (computed < value);
}
if (setLow) {
low = mid + 1;
} else {
high = mid;
}
}
return nativeMin(high, MAX_ARRAY_INDEX);
}
/**
* A specialized version of `baseCallback` which only supports `this` binding
* and specifying the number of arguments to provide to `func`.
*
* @private
* @param {Function} func The function to bind.
* @param {*} thisArg The `this` binding of `func`.
* @param {number} [argCount] The number of arguments to provide to `func`.
* @returns {Function} Returns the callback.
*/
function bindCallback(func, thisArg, argCount) {
if (typeof func != 'function') {
return identity;
}
if (thisArg === undefined) {
return func;
}
switch (argCount) {
case 1: return function(value) {
return func.call(thisArg, value);
};
case 3: return function(value, index, collection) {
return func.call(thisArg, value, index, collection);
};
case 4: return function(accumulator, value, index, collection) {
return func.call(thisArg, accumulator, value, index, collection);
};
case 5: return function(value, other, key, object, source) {
return func.call(thisArg, value, other, key, object, source);
};
}
return function() {
return func.apply(thisArg, arguments);
};
}
/**
* Creates a clone of the given array buffer.
*
* @private
* @param {ArrayBuffer} buffer The array buffer to clone.
* @returns {ArrayBuffer} Returns the cloned array buffer.
*/
function bufferClone(buffer) {
var result = new ArrayBuffer(buffer.byteLength),
view = new Uint8Array(result);
view.set(new Uint8Array(buffer));
return result;
}
/**
* Creates an array that is the composition of partially applied arguments,
* placeholders, and provided arguments into a single array of arguments.
*
* @private
* @param {Array|Object} args The provided arguments.
* @param {Array} partials The arguments to prepend to those provided.
* @param {Array} holders The `partials` placeholder indexes.
* @returns {Array} Returns the new array of composed arguments.
*/
function composeArgs(args, partials, holders) {
var holdersLength = holders.length,
argsIndex = -1,
argsLength = nativeMax(args.length - holdersLength, 0),
leftIndex = -1,
leftLength = partials.length,
result = Array(leftLength + argsLength);
while (++leftIndex < leftLength) {
result[leftIndex] = partials[leftIndex];
}
while (++argsIndex < holdersLength) {
result[holders[argsIndex]] = args[argsIndex];
}
while (argsLength--) {
result[leftIndex++] = args[argsIndex++];
}
return result;
}
/**
* This function is like `composeArgs` except that the arguments composition
* is tailored for `_.partialRight`.
*
* @private
* @param {Array|Object} args The provided arguments.
* @param {Array} partials The arguments to append to those provided.
* @param {Array} holders The `partials` placeholder indexes.
* @returns {Array} Returns the new array of composed arguments.
*/
function composeArgsRight(args, partials, holders) {
var holdersIndex = -1,
holdersLength = holders.length,
argsIndex = -1,
argsLength = nativeMax(args.length - holdersLength, 0),
rightIndex = -1,
rightLength = partials.length,
result = Array(argsLength + rightLength);
while (++argsIndex < argsLength) {
result[argsIndex] = args[argsIndex];
}
var offset = argsIndex;
while (++rightIndex < rightLength) {
result[offset + rightIndex] = partials[rightIndex];
}
while (++holdersIndex < holdersLength) {
result[offset + holders[holdersIndex]] = args[argsIndex++];
}
return result;
}
/**
* Creates a `_.countBy`, `_.groupBy`, `_.indexBy`, or `_.partition` function.
*
* @private
* @param {Function} setter The function to set keys and values of the accumulator object.
* @param {Function} [initializer] The function to initialize the accumulator object.
* @returns {Function} Returns the new aggregator function.
*/
function createAggregator(setter, initializer) {
return function(collection, iteratee, thisArg) {
var result = initializer ? initializer() : {};
iteratee = getCallback(iteratee, thisArg, 3);
if (isArray(collection)) {
var index = -1,
length = collection.length;
while (++index < length) {
var value = collection[index];
setter(result, value, iteratee(value, index, collection), collection);
}
} else {
baseEach(collection, function(value, key, collection) {
setter(result, value, iteratee(value, key, collection), collection);
});
}
return result;
};
}
/**
* Creates a `_.assign`, `_.defaults`, or `_.merge` function.
*
* @private
* @param {Function} assigner The function to assign values.
* @returns {Function} Returns the new assigner function.
*/
function createAssigner(assigner) {
return restParam(function(object, sources) {
var index = -1,
length = object == null ? 0 : sources.length,
customizer = length > 2 ? sources[length - 2] : undefined,
guard = length > 2 ? sources[2] : undefined,
thisArg = length > 1 ? sources[length - 1] : undefined;
if (typeof customizer == 'function') {
customizer = bindCallback(customizer, thisArg, 5);
length -= 2;
} else {
customizer = typeof thisArg == 'function' ? thisArg : undefined;
length -= (customizer ? 1 : 0);
}
if (guard && isIterateeCall(sources[0], sources[1], guard)) {
customizer = length < 3 ? undefined : customizer;
length = 1;
}
while (++index < length) {
var source = sources[index];
if (source) {
assigner(object, source, customizer);
}
}
return object;
});
}
/**
* Creates a `baseEach` or `baseEachRight` function.
*
* @private
* @param {Function} eachFunc The function to iterate over a collection.
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Function} Returns the new base function.
*/
function createBaseEach(eachFunc, fromRight) {
return function(collection, iteratee) {
var length = collection ? getLength(collection) : 0;
if (!isLength(length)) {
return eachFunc(collection, iteratee);
}
var index = fromRight ? length : -1,
iterable = toObject(collection);
while ((fromRight ? index-- : ++index < length)) {
if (iteratee(iterable[index], index, iterable) === false) {
break;
}
}
return collection;
};
}
/**
* Creates a base function for `_.forIn` or `_.forInRight`.
*
* @private
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Function} Returns the new base function.
*/
function createBaseFor(fromRight) {
return function(object, iteratee, keysFunc) {
var iterable = toObject(object),
props = keysFunc(object),
length = props.length,
index = fromRight ? length : -1;
while ((fromRight ? index-- : ++index < length)) {
var key = props[index];
if (iteratee(iterable[key], key, iterable) === false) {
break;
}
}
return object;
};
}
/**
* Creates a function that wraps `func` and invokes it with the `this`
* binding of `thisArg`.
*
* @private
* @param {Function} func The function to bind.
* @param {*} [thisArg] The `this` binding of `func`.
* @returns {Function} Returns the new bound function.
*/
function createBindWrapper(func, thisArg) {
var Ctor = createCtorWrapper(func);
function wrapper() {
var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
return fn.apply(thisArg, arguments);
}
return wrapper;
}
/**
* Creates a `Set` cache object to optimize linear searches of large arrays.
*
* @private
* @param {Array} [values] The values to cache.
* @returns {null|Object} Returns the new cache object if `Set` is supported, else `null`.
*/
function createCache(values) {
return (nativeCreate && Set) ? new SetCache(values) : null;
}
/**
* Creates a function that produces compound words out of the words in a
* given string.
*
* @private
* @param {Function} callback The function to combine each word.
* @returns {Function} Returns the new compounder function.
*/
function createCompounder(callback) {
return function(string) {
var index = -1,
array = words(deburr(string)),
length = array.length,
result = '';
while (++index < length) {
result = callback(result, array[index], index);
}
return result;
};
}
/**
* Creates a function that produces an instance of `Ctor` regardless of
* whether it was invoked as part of a `new` expression or by `call` or `apply`.
*
* @private
* @param {Function} Ctor The constructor to wrap.
* @returns {Function} Returns the new wrapped function.
*/
function createCtorWrapper(Ctor) {
return function() {
// Use a `switch` statement to work with class constructors.
// See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
// for more details.
var args = arguments;
switch (args.length) {
case 0: return new Ctor;
case 1: return new Ctor(args[0]);
case 2: return new Ctor(args[0], args[1]);
case 3: return new Ctor(args[0], args[1], args[2]);
case 4: return new Ctor(args[0], args[1], args[2], args[3]);
case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
}
var thisBinding = baseCreate(Ctor.prototype),
result = Ctor.apply(thisBinding, args);
// Mimic the constructor's `return` behavior.
// See https://es5.github.io/#x13.2.2 for more details.
return isObject(result) ? result : thisBinding;
};
}
/**
* Creates a `_.curry` or `_.curryRight` function.
*
* @private
* @param {boolean} flag The curry bit flag.
* @returns {Function} Returns the new curry function.
*/
function createCurry(flag) {
function curryFunc(func, arity, guard) {
if (guard && isIterateeCall(func, arity, guard)) {
arity = undefined;
}
var result = createWrapper(func, flag, undefined, undefined, undefined, undefined, undefined, arity);
result.placeholder = curryFunc.placeholder;
return result;
}
return curryFunc;
}
/**
* Creates a `_.defaults` or `_.defaultsDeep` function.
*
* @private
* @param {Function} assigner The function to assign values.
* @param {Function} customizer The function to customize assigned values.
* @returns {Function} Returns the new defaults function.
*/
function createDefaults(assigner, customizer) {
return restParam(function(args) {
var object = args[0];
if (object == null) {
return object;
}
args.push(customizer);
return assigner.apply(undefined, args);
});
}
/**
* Creates a `_.max` or `_.min` function.
*
* @private
* @param {Function} comparator The function used to compare values.
* @param {*} exValue The initial extremum value.
* @returns {Function} Returns the new extremum function.
*/
function createExtremum(comparator, exValue) {
return function(collection, iteratee, thisArg) {
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
iteratee = undefined;
}
iteratee = getCallback(iteratee, thisArg, 3);
if (iteratee.length == 1) {
collection = isArray(collection) ? collection : toIterable(collection);
var result = arrayExtremum(collection, iteratee, comparator, exValue);
if (!(collection.length && result === exValue)) {
return result;
}
}
return baseExtremum(collection, iteratee, comparator, exValue);
};
}
/**
* Creates a `_.find` or `_.findLast` function.
*
* @private
* @param {Function} eachFunc The function to iterate over a collection.
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Function} Returns the new find function.
*/
function createFind(eachFunc, fromRight) {
return function(collection, predicate, thisArg) {
predicate = getCallback(predicate, thisArg, 3);
if (isArray(collection)) {
var index = baseFindIndex(collection, predicate, fromRight);
return index > -1 ? collection[index] : undefined;
}
return baseFind(collection, predicate, eachFunc);
};
}
/**
* Creates a `_.findIndex` or `_.findLastIndex` function.
*
* @private
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Function} Returns the new find function.
*/
function createFindIndex(fromRight) {
return function(array, predicate, thisArg) {
if (!(array && array.length)) {
return -1;
}
predicate = getCallback(predicate, thisArg, 3);
return baseFindIndex(array, predicate, fromRight);
};
}
/**
* Creates a `_.findKey` or `_.findLastKey` function.
*
* @private
* @param {Function} objectFunc The function to iterate over an object.
* @returns {Function} Returns the new find function.
*/
function createFindKey(objectFunc) {
return function(object, predicate, thisArg) {
predicate = getCallback(predicate, thisArg, 3);
return baseFind(object, predicate, objectFunc, true);
};
}
/**
* Creates a `_.flow` or `_.flowRight` function.
*
* @private
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Function} Returns the new flow function.
*/
function createFlow(fromRight) {
return function() {
var wrapper,
length = arguments.length,
index = fromRight ? length : -1,
leftIndex = 0,
funcs = Array(length);
while ((fromRight ? index-- : ++index < length)) {
var func = funcs[leftIndex++] = arguments[index];
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
if (!wrapper && LodashWrapper.prototype.thru && getFuncName(func) == 'wrapper') {
wrapper = new LodashWrapper([], true);
}
}
index = wrapper ? -1 : length;
while (++index < length) {
func = funcs[index];
var funcName = getFuncName(func),
data = funcName == 'wrapper' ? getData(func) : undefined;
if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) {
wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
} else {
wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func);
}
}
return function() {
var args = arguments,
value = args[0];
if (wrapper && args.length == 1 && isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
return wrapper.plant(value).value();
}
var index = 0,
result = length ? funcs[index].apply(this, args) : value;
while (++index < length) {
result = funcs[index].call(this, result);
}
return result;
};
};
}
/**
* Creates a function for `_.forEach` or `_.forEachRight`.
*
* @private
* @param {Function} arrayFunc The function to iterate over an array.
* @param {Function} eachFunc The function to iterate over a collection.
* @returns {Function} Returns the new each function.
*/
function createForEach(arrayFunc, eachFunc) {
return function(collection, iteratee, thisArg) {
return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
? arrayFunc(collection, iteratee)
: eachFunc(collection, bindCallback(iteratee, thisArg, 3));
};
}
/**
* Creates a function for `_.forIn` or `_.forInRight`.
*
* @private
* @param {Function} objectFunc The function to iterate over an object.
* @returns {Function} Returns the new each function.
*/
function createForIn(objectFunc) {
return function(object, iteratee, thisArg) {
if (typeof iteratee != 'function' || thisArg !== undefined) {
iteratee = bindCallback(iteratee, thisArg, 3);
}
return objectFunc(object, iteratee, keysIn);
};
}
/**
* Creates a function for `_.forOwn` or `_.forOwnRight`.
*
* @private
* @param {Function} objectFunc The function to iterate over an object.
* @returns {Function} Returns the new each function.
*/
function createForOwn(objectFunc) {
return function(object, iteratee, thisArg) {
if (typeof iteratee != 'function' || thisArg !== undefined) {
iteratee = bindCallback(iteratee, thisArg, 3);
}
return objectFunc(object, iteratee);
};
}
/**
* Creates a function for `_.mapKeys` or `_.mapValues`.
*
* @private
* @param {boolean} [isMapKeys] Specify mapping keys instead of values.
* @returns {Function} Returns the new map function.
*/
function createObjectMapper(isMapKeys) {
return function(object, iteratee, thisArg) {
var result = {};
iteratee = getCallback(iteratee, thisArg, 3);
baseForOwn(object, function(value, key, object) {
var mapped = iteratee(value, key, object);
key = isMapKeys ? mapped : key;
value = isMapKeys ? value : mapped;
result[key] = value;
});
return result;
};
}
/**
* Creates a function for `_.padLeft` or `_.padRight`.
*
* @private
* @param {boolean} [fromRight] Specify padding from the right.
* @returns {Function} Returns the new pad function.
*/
function createPadDir(fromRight) {
return function(string, length, chars) {
string = baseToString(string);
return (fromRight ? string : '') + createPadding(string, length, chars) + (fromRight ? '' : string);
};
}
/**
* Creates a `_.partial` or `_.partialRight` function.
*
* @private
* @param {boolean} flag The partial bit flag.
* @returns {Function} Returns the new partial function.
*/
function createPartial(flag) {
var partialFunc = restParam(function(func, partials) {
var holders = replaceHolders(partials, partialFunc.placeholder);
return createWrapper(func, flag, undefined, partials, holders);
});
return partialFunc;
}
/**
* Creates a function for `_.reduce` or `_.reduceRight`.
*
* @private
* @param {Function} arrayFunc The function to iterate over an array.
* @param {Function} eachFunc The function to iterate over a collection.
* @returns {Function} Returns the new each function.
*/
function createReduce(arrayFunc, eachFunc) {
return function(collection, iteratee, accumulator, thisArg) {
var initFromArray = arguments.length < 3;
return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
? arrayFunc(collection, iteratee, accumulator, initFromArray)
: baseReduce(collection, getCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc);
};
}
/**
* Creates a function that wraps `func` and invokes it with optional `this`
* binding of, partial application, and currying.
*
* @private
* @param {Function|string} func The function or method name to reference.
* @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
* @param {*} [thisArg] The `this` binding of `func`.
* @param {Array} [partials] The arguments to prepend to those provided to the new function.
* @param {Array} [holders] The `partials` placeholder indexes.
* @param {Array} [partialsRight] The arguments to append to those provided to the new function.
* @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
* @param {Array} [argPos] The argument positions of the new function.
* @param {number} [ary] The arity cap of `func`.
* @param {number} [arity] The arity of `func`.
* @returns {Function} Returns the new wrapped function.
*/
function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
var isAry = bitmask & ARY_FLAG,
isBind = bitmask & BIND_FLAG,
isBindKey = bitmask & BIND_KEY_FLAG,
isCurry = bitmask & CURRY_FLAG,
isCurryBound = bitmask & CURRY_BOUND_FLAG,
isCurryRight = bitmask & CURRY_RIGHT_FLAG,
Ctor = isBindKey ? undefined : createCtorWrapper(func);
function wrapper() {
// Avoid `arguments` object use disqualifying optimizations by
// converting it to an array before providing it to other functions.
var length = arguments.length,
index = length,
args = Array(length);
while (index--) {
args[index] = arguments[index];
}
if (partials) {
args = composeArgs(args, partials, holders);
}
if (partialsRight) {
args = composeArgsRight(args, partialsRight, holdersRight);
}
if (isCurry || isCurryRight) {
var placeholder = wrapper.placeholder,
argsHolders = replaceHolders(args, placeholder);
length -= argsHolders.length;
if (length < arity) {
var newArgPos = argPos ? arrayCopy(argPos) : undefined,
newArity = nativeMax(arity - length, 0),
newsHolders = isCurry ? argsHolders : undefined,
newHoldersRight = isCurry ? undefined : argsHolders,
newPartials = isCurry ? args : undefined,
newPartialsRight = isCurry ? undefined : args;
bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
if (!isCurryBound) {
bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
}
var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, newArity],
result = createHybridWrapper.apply(undefined, newData);
if (isLaziable(func)) {
setData(result, newData);
}
result.placeholder = placeholder;
return result;
}
}
var thisBinding = isBind ? thisArg : this,
fn = isBindKey ? thisBinding[func] : func;
if (argPos) {
args = reorder(args, argPos);
}
if (isAry && ary < args.length) {
args.length = ary;
}
if (this && this !== root && this instanceof wrapper) {
fn = Ctor || createCtorWrapper(func);
}
return fn.apply(thisBinding, args);
}
return wrapper;
}
/**
* Creates the padding required for `string` based on the given `length`.
* The `chars` string is truncated if the number of characters exceeds `length`.
*
* @private
* @param {string} string The string to create padding for.
* @param {number} [length=0] The padding length.
* @param {string} [chars=' '] The string used as padding.
* @returns {string} Returns the pad for `string`.
*/
function createPadding(string, length, chars) {
var strLength = string.length;
length = +length;
if (strLength >= length || !nativeIsFinite(length)) {
return '';
}
var padLength = length - strLength;
chars = chars == null ? ' ' : (chars + '');
return repeat(chars, nativeCeil(padLength / chars.length)).slice(0, padLength);
}
/**
* Creates a function that wraps `func` and invokes it with the optional `this`
* binding of `thisArg` and the `partials` prepended to those provided to
* the wrapper.
*
* @private
* @param {Function} func The function to partially apply arguments to.
* @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
* @param {*} thisArg The `this` binding of `func`.
* @param {Array} partials The arguments to prepend to those provided to the new function.
* @returns {Function} Returns the new bound function.
*/
function createPartialWrapper(func, bitmask, thisArg, partials) {
var isBind = bitmask & BIND_FLAG,
Ctor = createCtorWrapper(func);
function wrapper() {
// Avoid `arguments` object use disqualifying optimizations by
// converting it to an array before providing it `func`.
var argsIndex = -1,
argsLength = arguments.length,
leftIndex = -1,
leftLength = partials.length,
args = Array(leftLength + argsLength);
while (++leftIndex < leftLength) {
args[leftIndex] = partials[leftIndex];
}
while (argsLength--) {
args[leftIndex++] = arguments[++argsIndex];
}
var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
return fn.apply(isBind ? thisArg : this, args);
}
return wrapper;
}
/**
* Creates a `_.ceil`, `_.floor`, or `_.round` function.
*
* @private
* @param {string} methodName The name of the `Math` method to use when rounding.
* @returns {Function} Returns the new round function.
*/
function createRound(methodName) {
var func = Math[methodName];
return function(number, precision) {
precision = precision === undefined ? 0 : (+precision || 0);
if (precision) {
precision = pow(10, precision);
return func(number * precision) / precision;
}
return func(number);
};
}
/**
* Creates a `_.sortedIndex` or `_.sortedLastIndex` function.
*
* @private
* @param {boolean} [retHighest] Specify returning the highest qualified index.
* @returns {Function} Returns the new index function.
*/
function createSortedIndex(retHighest) {
return function(array, value, iteratee, thisArg) {
var callback = getCallback(iteratee);
return (iteratee == null && callback === baseCallback)
? binaryIndex(array, value, retHighest)
: binaryIndexBy(array, value, callback(iteratee, thisArg, 1), retHighest);
};
}
/**
* Creates a function that either curries or invokes `func` with optional
* `this` binding and partially applied arguments.
*
* @private
* @param {Function|string} func The function or method name to reference.
* @param {number} bitmask The bitmask of flags.
* The bitmask may be composed of the following flags:
* 1 - `_.bind`
* 2 - `_.bindKey`
* 4 - `_.curry` or `_.curryRight` of a bound function
* 8 - `_.curry`
* 16 - `_.curryRight`
* 32 - `_.partial`
* 64 - `_.partialRight`
* 128 - `_.rearg`
* 256 - `_.ary`
* @param {*} [thisArg] The `this` binding of `func`.
* @param {Array} [partials] The arguments to be partially applied.
* @param {Array} [holders] The `partials` placeholder indexes.
* @param {Array} [argPos] The argument positions of the new function.
* @param {number} [ary] The arity cap of `func`.
* @param {number} [arity] The arity of `func`.
* @returns {Function} Returns the new wrapped function.
*/
function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
var isBindKey = bitmask & BIND_KEY_FLAG;
if (!isBindKey && typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
var length = partials ? partials.length : 0;
if (!length) {
bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
partials = holders = undefined;
}
length -= (holders ? holders.length : 0);
if (bitmask & PARTIAL_RIGHT_FLAG) {
var partialsRight = partials,
holdersRight = holders;
partials = holders = undefined;
}
var data = isBindKey ? undefined : getData(func),
newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
if (data) {
mergeData(newData, data);
bitmask = newData[1];
arity = newData[9];
}
newData[9] = arity == null
? (isBindKey ? 0 : func.length)
: (nativeMax(arity - length, 0) || 0);
if (bitmask == BIND_FLAG) {
var result = createBindWrapper(newData[0], newData[2]);
} else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) {
result = createPartialWrapper.apply(undefined, newData);
} else {
result = createHybridWrapper.apply(undefined, newData);
}
var setter = data ? baseSetData : setData;
return setter(result, newData);
}
/**
* A specialized version of `baseIsEqualDeep` for arrays with support for
* partial deep comparisons.
*
* @private
* @param {Array} array The array to compare.
* @param {Array} other The other array to compare.
* @param {Function} equalFunc The function to determine equivalents of values.
* @param {Function} [customizer] The function to customize comparing arrays.
* @param {boolean} [isLoose] Specify performing partial comparisons.
* @param {Array} [stackA] Tracks traversed `value` objects.
* @param {Array} [stackB] Tracks traversed `other` objects.
* @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
*/
function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) {
var index = -1,
arrLength = array.length,
othLength = other.length;
if (arrLength != othLength && !(isLoose && othLength > arrLength)) {
return false;
}
// Ignore non-index properties.
while (++index < arrLength) {
var arrValue = array[index],
othValue = other[index],
result = customizer ? customizer(isLoose ? othValue : arrValue, isLoose ? arrValue : othValue, index) : undefined;
if (result !== undefined) {
if (result) {
continue;
}
return false;
}
// Recursively compare arrays (susceptible to call stack limits).
if (isLoose) {
if (!arraySome(other, function(othValue) {
return arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
})) {
return false;
}
} else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB))) {
return false;
}
}
return true;
}
/**
* A specialized version of `baseIsEqualDeep` for comparing objects of
* the same `toStringTag`.
*
* **Note:** This function only supports comparing values with tags of
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
*
* @private
* @param {Object} object The object to compare.
* @param {Object} other The other object to compare.
* @param {string} tag The `toStringTag` of the objects to compare.
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
*/
function equalByTag(object, other, tag) {
switch (tag) {
case boolTag:
case dateTag:
// Coerce dates and booleans to numbers, dates to milliseconds and booleans
// to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
return +object == +other;
case errorTag:
return object.name == other.name && object.message == other.message;
case numberTag:
// Treat `NaN` vs. `NaN` as equal.
return (object != +object)
? other != +other
: object == +other;
case regexpTag:
case stringTag:
// Coerce regexes to strings and treat strings primitives and string
// objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
return object == (other + '');
}
return false;
}
/**
* A specialized version of `baseIsEqualDeep` for objects with support for
* partial deep comparisons.
*
* @private
* @param {Object} object The object to compare.
* @param {Object} other The other object to compare.
* @param {Function} equalFunc The function to determine equivalents of values.
* @param {Function} [customizer] The function to customize comparing values.
* @param {boolean} [isLoose] Specify performing partial comparisons.
* @param {Array} [stackA] Tracks traversed `value` objects.
* @param {Array} [stackB] Tracks traversed `other` objects.
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
*/
function equalObjects(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
var objProps = keys(object),
objLength = objProps.length,
othProps = keys(other),
othLength = othProps.length;
if (objLength != othLength && !isLoose) {
return false;
}
var index = objLength;
while (index--) {
var key = objProps[index];
if (!(isLoose ? key in other : hasOwnProperty.call(other, key))) {
return false;
}
}
var skipCtor = isLoose;
while (++index < objLength) {
key = objProps[index];
var objValue = object[key],
othValue = other[key],
result = customizer ? customizer(isLoose ? othValue : objValue, isLoose? objValue : othValue, key) : undefined;
// Recursively compare objects (susceptible to call stack limits).
if (!(result === undefined ? equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB) : result)) {
return false;
}
skipCtor || (skipCtor = key == 'constructor');
}
if (!skipCtor) {
var objCtor = object.constructor,
othCtor = other.constructor;
// Non `Object` object instances with different constructors are not equal.
if (objCtor != othCtor &&
('constructor' in object && 'constructor' in other) &&
!(typeof objCtor == 'function' && objCtor instanceof objCtor &&
typeof othCtor == 'function' && othCtor instanceof othCtor)) {
return false;
}
}
return true;
}
/**
* Gets the appropriate "callback" function. If the `_.callback` method is
* customized this function returns the custom method, otherwise it returns
* the `baseCallback` function. If arguments are provided the chosen function
* is invoked with them and its result is returned.
*
* @private
* @returns {Function} Returns the chosen function or its result.
*/
function getCallback(func, thisArg, argCount) {
var result = lodash.callback || callback;
result = result === callback ? baseCallback : result;
return argCount ? result(func, thisArg, argCount) : result;
}
/**
* Gets metadata for `func`.
*
* @private
* @param {Function} func The function to query.
* @returns {*} Returns the metadata for `func`.
*/
var getData = !metaMap ? noop : function(func) {
return metaMap.get(func);
};
/**
* Gets the name of `func`.
*
* @private
* @param {Function} func The function to query.
* @returns {string} Returns the function name.
*/
function getFuncName(func) {
var result = func.name,
array = realNames[result],
length = array ? array.length : 0;
while (length--) {
var data = array[length],
otherFunc = data.func;
if (otherFunc == null || otherFunc == func) {
return data.name;
}
}
return result;
}
/**
* Gets the appropriate "indexOf" function. If the `_.indexOf` method is
* customized this function returns the custom method, otherwise it returns
* the `baseIndexOf` function. If arguments are provided the chosen function
* is invoked with them and its result is returned.
*
* @private
* @returns {Function|number} Returns the chosen function or its result.
*/
function getIndexOf(collection, target, fromIndex) {
var result = lodash.indexOf || indexOf;
result = result === indexOf ? baseIndexOf : result;
return collection ? result(collection, target, fromIndex) : result;
}
/**
* Gets the "length" property value of `object`.
*
* **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
* that affects Safari on at least iOS 8.1-8.3 ARM64.
*
* @private
* @param {Object} object The object to query.
* @returns {*} Returns the "length" value.
*/
var getLength = baseProperty('length');
/**
* Gets the propery names, values, and compare flags of `object`.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the match data of `object`.
*/
function getMatchData(object) {
var result = pairs(object),
length = result.length;
while (length--) {
result[length][2] = isStrictComparable(result[length][1]);
}
return result;
}
/**
* Gets the native function at `key` of `object`.
*
* @private
* @param {Object} object The object to query.
* @param {string} key The key of the method to get.
* @returns {*} Returns the function if it's native, else `undefined`.
*/
function getNative(object, key) {
var value = object == null ? undefined : object[key];
return isNative(value) ? value : undefined;
}
/**
* Gets the view, applying any `transforms` to the `start` and `end` positions.
*
* @private
* @param {number} start The start of the view.
* @param {number} end The end of the view.
* @param {Array} transforms The transformations to apply to the view.
* @returns {Object} Returns an object containing the `start` and `end`
* positions of the view.
*/
function getView(start, end, transforms) {
var index = -1,
length = transforms.length;
while (++index < length) {
var data = transforms[index],
size = data.size;
switch (data.type) {
case 'drop': start += size; break;
case 'dropRight': end -= size; break;
case 'take': end = nativeMin(end, start + size); break;
case 'takeRight': start = nativeMax(start, end - size); break;
}
}
return { 'start': start, 'end': end };
}
/**
* Initializes an array clone.
*
* @private
* @param {Array} array The array to clone.
* @returns {Array} Returns the initialized clone.
*/
function initCloneArray(array) {
var length = array.length,
result = new array.constructor(length);
// Add array properties assigned by `RegExp#exec`.
if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
result.index = array.index;
result.input = array.input;
}
return result;
}
/**
* Initializes an object clone.
*
* @private
* @param {Object} object The object to clone.
* @returns {Object} Returns the initialized clone.
*/
function initCloneObject(object) {
var Ctor = object.constructor;
if (!(typeof Ctor == 'function' && Ctor instanceof Ctor)) {
Ctor = Object;
}
return new Ctor;
}
/**
* Initializes an object clone based on its `toStringTag`.
*
* **Note:** This function only supports cloning values with tags of
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
*
* @private
* @param {Object} object The object to clone.
* @param {string} tag The `toStringTag` of the object to clone.
* @param {boolean} [isDeep] Specify a deep clone.
* @returns {Object} Returns the initialized clone.
*/
function initCloneByTag(object, tag, isDeep) {
var Ctor = object.constructor;
switch (tag) {
case arrayBufferTag:
return bufferClone(object);
case boolTag:
case dateTag:
return new Ctor(+object);
case float32Tag: case float64Tag:
case int8Tag: case int16Tag: case int32Tag:
case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
var buffer = object.buffer;
return new Ctor(isDeep ? bufferClone(buffer) : buffer, object.byteOffset, object.length);
case numberTag:
case stringTag:
return new Ctor(object);
case regexpTag:
var result = new Ctor(object.source, reFlags.exec(object));
result.lastIndex = object.lastIndex;
}
return result;
}
/**
* Invokes the method at `path` on `object`.
*
* @private
* @param {Object} object The object to query.
* @param {Array|string} path The path of the method to invoke.
* @param {Array} args The arguments to invoke the method with.
* @returns {*} Returns the result of the invoked method.
*/
function invokePath(object, path, args) {
if (object != null && !isKey(path, object)) {
path = toPath(path);
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
path = last(path);
}
var func = object == null ? object : object[path];
return func == null ? undefined : func.apply(object, args);
}
/**
* Checks if `value` is array-like.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
*/
function isArrayLike(value) {
return value != null && isLength(getLength(value));
}
/**
* Checks if `value` is a valid array-like index.
*
* @private
* @param {*} value The value to check.
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
*/
function isIndex(value, length) {
value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
length = length == null ? MAX_SAFE_INTEGER : length;
return value > -1 && value % 1 == 0 && value < length;
}
/**
* Checks if the provided arguments are from an iteratee call.
*
* @private
* @param {*} value The potential iteratee value argument.
* @param {*} index The potential iteratee index or key argument.
* @param {*} object The potential iteratee object argument.
* @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
*/
function isIterateeCall(value, index, object) {
if (!isObject(object)) {
return false;
}
var type = typeof index;
if (type == 'number'
? (isArrayLike(object) && isIndex(index, object.length))
: (type == 'string' && index in object)) {
var other = object[index];
return value === value ? (value === other) : (other !== other);
}
return false;
}
/**
* Checks if `value` is a property name and not a property path.
*
* @private
* @param {*} value The value to check.
* @param {Object} [object] The object to query keys on.
* @returns {boolean} Returns `true` if `value` is a property name, else `false`.
*/
function isKey(value, object) {
var type = typeof value;
if ((type == 'string' && reIsPlainProp.test(value)) || type == 'number') {
return true;
}
if (isArray(value)) {
return false;
}
var result = !reIsDeepProp.test(value);
return result || (object != null && value in toObject(object));
}
/**
* Checks if `func` has a lazy counterpart.
*
* @private
* @param {Function} func The function to check.
* @returns {boolean} Returns `true` if `func` has a lazy counterpart, else `false`.
*/
function isLaziable(func) {
var funcName = getFuncName(func);
if (!(funcName in LazyWrapper.prototype)) {
return false;
}
var other = lodash[funcName];
if (func === other) {
return true;
}
var data = getData(other);
return !!data && func === data[0];
}
/**
* Checks if `value` is a valid array-like length.
*
* **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
*/
function isLength(value) {
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
}
/**
* Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` if suitable for strict
* equality comparisons, else `false`.
*/
function isStrictComparable(value) {
return value === value && !isObject(value);
}
/**
* Merges the function metadata of `source` into `data`.
*
* Merging metadata reduces the number of wrappers required to invoke a function.
* This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
* may be applied regardless of execution order. Methods like `_.ary` and `_.rearg`
* augment function arguments, making the order in which they are executed important,
* preventing the merging of metadata. However, we make an exception for a safe
* common case where curried functions have `_.ary` and or `_.rearg` applied.
*
* @private
* @param {Array} data The destination metadata.
* @param {Array} source The source metadata.
* @returns {Array} Returns `data`.
*/
function mergeData(data, source) {
var bitmask = data[1],
srcBitmask = source[1],
newBitmask = bitmask | srcBitmask,
isCommon = newBitmask < ARY_FLAG;
var isCombo =
(srcBitmask == ARY_FLAG && bitmask == CURRY_FLAG) ||
(srcBitmask == ARY_FLAG && bitmask == REARG_FLAG && data[7].length <= source[8]) ||
(srcBitmask == (ARY_FLAG | REARG_FLAG) && bitmask == CURRY_FLAG);
// Exit early if metadata can't be merged.
if (!(isCommon || isCombo)) {
return data;
}
// Use source `thisArg` if available.
if (srcBitmask & BIND_FLAG) {
data[2] = source[2];
// Set when currying a bound function.
newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG;
}
// Compose partial arguments.
var value = source[3];
if (value) {
var partials = data[3];
data[3] = partials ? composeArgs(partials, value, source[4]) : arrayCopy(value);
data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : arrayCopy(source[4]);
}
// Compose partial right arguments.
value = source[5];
if (value) {
partials = data[5];
data[5] = partials ? composeArgsRight(partials, value, source[6]) : arrayCopy(value);
data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : arrayCopy(source[6]);
}
// Use source `argPos` if available.
value = source[7];
if (value) {
data[7] = arrayCopy(value);
}
// Use source `ary` if it's smaller.
if (srcBitmask & ARY_FLAG) {
data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
}
// Use source `arity` if one is not provided.
if (data[9] == null) {
data[9] = source[9];
}
// Use source `func` and merge bitmasks.
data[0] = source[0];
data[1] = newBitmask;
return data;
}
/**
* Used by `_.defaultsDeep` to customize its `_.merge` use.
*
* @private
* @param {*} objectValue The destination object property value.
* @param {*} sourceValue The source object property value.
* @returns {*} Returns the value to assign to the destination object.
*/
function mergeDefaults(objectValue, sourceValue) {
return objectValue === undefined ? sourceValue : merge(objectValue, sourceValue, mergeDefaults);
}
/**
* A specialized version of `_.pick` which picks `object` properties specified
* by `props`.
*
* @private
* @param {Object} object The source object.
* @param {string[]} props The property names to pick.
* @returns {Object} Returns the new object.
*/
function pickByArray(object, props) {
object = toObject(object);
var index = -1,
length = props.length,
result = {};
while (++index < length) {
var key = props[index];
if (key in object) {
result[key] = object[key];
}
}
return result;
}
/**
* A specialized version of `_.pick` which picks `object` properties `predicate`
* returns truthy for.
*
* @private
* @param {Object} object The source object.
* @param {Function} predicate The function invoked per iteration.
* @returns {Object} Returns the new object.
*/
function pickByCallback(object, predicate) {
var result = {};
baseForIn(object, function(value, key, object) {
if (predicate(value, key, object)) {
result[key] = value;
}
});
return result;
}
/**
* Reorder `array` according to the specified indexes where the element at
* the first index is assigned as the first element, the element at
* the second index is assigned as the second element, and so on.
*
* @private
* @param {Array} array The array to reorder.
* @param {Array} indexes The arranged array indexes.
* @returns {Array} Returns `array`.
*/
function reorder(array, indexes) {
var arrLength = array.length,
length = nativeMin(indexes.length, arrLength),
oldArray = arrayCopy(array);
while (length--) {
var index = indexes[length];
array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
}
return array;
}
/**
* Sets metadata for `func`.
*
* **Note:** If this function becomes hot, i.e. is invoked a lot in a short
* period of time, it will trip its breaker and transition to an identity function
* to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070)
* for more details.
*
* @private
* @param {Function} func The function to associate metadata with.
* @param {*} data The metadata.
* @returns {Function} Returns `func`.
*/
var setData = (function() {
var count = 0,
lastCalled = 0;
return function(key, value) {
var stamp = now(),
remaining = HOT_SPAN - (stamp - lastCalled);
lastCalled = stamp;
if (remaining > 0) {
if (++count >= HOT_COUNT) {
return key;
}
} else {
count = 0;
}
return baseSetData(key, value);
};
}());
/**
* A fallback implementation of `Object.keys` which creates an array of the
* own enumerable property names of `object`.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
*/
function shimKeys(object) {
var props = keysIn(object),
propsLength = props.length,
length = propsLength && object.length;
var allowIndexes = !!length && isLength(length) &&
(isArray(object) || isArguments(object));
var index = -1,
result = [];
while (++index < propsLength) {
var key = props[index];
if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
result.push(key);
}
}
return result;
}
/**
* Converts `value` to an array-like object if it's not one.
*
* @private
* @param {*} value The value to process.
* @returns {Array|Object} Returns the array-like object.
*/
function toIterable(value) {
if (value == null) {
return [];
}
if (!isArrayLike(value)) {
return values(value);
}
return isObject(value) ? value : Object(value);
}
/**
* Converts `value` to an object if it's not one.
*
* @private
* @param {*} value The value to process.
* @returns {Object} Returns the object.
*/
function toObject(value) {
return isObject(value) ? value : Object(value);
}
/**
* Converts `value` to property path array if it's not one.
*
* @private
* @param {*} value The value to process.
* @returns {Array} Returns the property path array.
*/
function toPath(value) {
if (isArray(value)) {
return value;
}
var result = [];
baseToString(value).replace(rePropName, function(match, number, quote, string) {
result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
});
return result;
}
/**
* Creates a clone of `wrapper`.
*
* @private
* @param {Object} wrapper The wrapper to clone.
* @returns {Object} Returns the cloned wrapper.
*/
function wrapperClone(wrapper) {
return wrapper instanceof LazyWrapper
? wrapper.clone()
: new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__));
}
/*------------------------------------------------------------------------*/
/**
* Creates an array of elements split into groups the length of `size`.
* If `collection` can't be split evenly, the final chunk will be the remaining
* elements.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to process.
* @param {number} [size=1] The length of each chunk.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {Array} Returns the new array containing chunks.
* @example
*
* _.chunk(['a', 'b', 'c', 'd'], 2);
* // => [['a', 'b'], ['c', 'd']]
*
* _.chunk(['a', 'b', 'c', 'd'], 3);
* // => [['a', 'b', 'c'], ['d']]
*/
function chunk(array, size, guard) {
if (guard ? isIterateeCall(array, size, guard) : size == null) {
size = 1;
} else {
size = nativeMax(nativeFloor(size) || 1, 1);
}
var index = 0,
length = array ? array.length : 0,
resIndex = -1,
result = Array(nativeCeil(length / size));
while (index < length) {
result[++resIndex] = baseSlice(array, index, (index += size));
}
return result;
}
/**
* Creates an array with all falsey values removed. The values `false`, `null`,
* `0`, `""`, `undefined`, and `NaN` are falsey.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to compact.
* @returns {Array} Returns the new array of filtered values.
* @example
*
* _.compact([0, 1, false, 2, '', 3]);
* // => [1, 2, 3]
*/
function compact(array) {
var index = -1,
length = array ? array.length : 0,
resIndex = -1,
result = [];
while (++index < length) {
var value = array[index];
if (value) {
result[++resIndex] = value;
}
}
return result;
}
/**
* Creates an array of unique `array` values not included in the other
* provided arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
* for equality comparisons.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to inspect.
* @param {...Array} [values] The arrays of values to exclude.
* @returns {Array} Returns the new array of filtered values.
* @example
*
* _.difference([1, 2, 3], [4, 2]);
* // => [1, 3]
*/
var difference = restParam(function(array, values) {
return (isObjectLike(array) && isArrayLike(array))
? baseDifference(array, baseFlatten(values, false, true))
: [];
});
/**
* Creates a slice of `array` with `n` elements dropped from the beginning.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to drop.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {Array} Returns the slice of `array`.
* @example
*
* _.drop([1, 2, 3]);
* // => [2, 3]
*
* _.drop([1, 2, 3], 2);
* // => [3]
*
* _.drop([1, 2, 3], 5);
* // => []
*
* _.drop([1, 2, 3], 0);
* // => [1, 2, 3]
*/
function drop(array, n, guard) {
var length = array ? array.length : 0;
if (!length) {
return [];
}
if (guard ? isIterateeCall(array, n, guard) : n == null) {
n = 1;
}
return baseSlice(array, n < 0 ? 0 : n);
}
/**
* Creates a slice of `array` with `n` elements dropped from the end.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to drop.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {Array} Returns the slice of `array`.
* @example
*
* _.dropRight([1, 2, 3]);
* // => [1, 2]
*
* _.dropRight([1, 2, 3], 2);
* // => [1]
*
* _.dropRight([1, 2, 3], 5);
* // => []
*
* _.dropRight([1, 2, 3], 0);
* // => [1, 2, 3]
*/
function dropRight(array, n, guard) {
var length = array ? array.length : 0;
if (!length) {
return [];
}
if (guard ? isIterateeCall(array, n, guard) : n == null) {
n = 1;
}
n = length - (+n || 0);
return baseSlice(array, 0, n < 0 ? 0 : n);
}
/**
* Creates a slice of `array` excluding elements dropped from the end.
* Elements are dropped until `predicate` returns falsey. The predicate is
* bound to `thisArg` and invoked with three arguments: (value, index, array).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that match the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to query.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the slice of `array`.
* @example
*
* _.dropRightWhile([1, 2, 3], function(n) {
* return n > 1;
* });
* // => [1]
*
* var users = [
* { 'user': 'barney', 'active': true },
* { 'user': 'fred', 'active': false },
* { 'user': 'pebbles', 'active': false }
* ];
*
* // using the `_.matches` callback shorthand
* _.pluck(_.dropRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
* // => ['barney', 'fred']
*
* // using the `_.matchesProperty` callback shorthand
* _.pluck(_.dropRightWhile(users, 'active', false), 'user');
* // => ['barney']
*
* // using the `_.property` callback shorthand
* _.pluck(_.dropRightWhile(users, 'active'), 'user');
* // => ['barney', 'fred', 'pebbles']
*/
function dropRightWhile(array, predicate, thisArg) {
return (array && array.length)
? baseWhile(array, getCallback(predicate, thisArg, 3), true, true)
: [];
}
/**
* Creates a slice of `array` excluding elements dropped from the beginning.
* Elements are dropped until `predicate` returns falsey. The predicate is
* bound to `thisArg` and invoked with three arguments: (value, index, array).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to query.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the slice of `array`.
* @example
*
* _.dropWhile([1, 2, 3], function(n) {
* return n < 3;
* });
* // => [3]
*
* var users = [
* { 'user': 'barney', 'active': false },
* { 'user': 'fred', 'active': false },
* { 'user': 'pebbles', 'active': true }
* ];
*
* // using the `_.matches` callback shorthand
* _.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user');
* // => ['fred', 'pebbles']
*
* // using the `_.matchesProperty` callback shorthand
* _.pluck(_.dropWhile(users, 'active', false), 'user');
* // => ['pebbles']
*
* // using the `_.property` callback shorthand
* _.pluck(_.dropWhile(users, 'active'), 'user');
* // => ['barney', 'fred', 'pebbles']
*/
function dropWhile(array, predicate, thisArg) {
return (array && array.length)
? baseWhile(array, getCallback(predicate, thisArg, 3), true)
: [];
}
/**
* Fills elements of `array` with `value` from `start` up to, but not
* including, `end`.
*
* **Note:** This method mutates `array`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to fill.
* @param {*} value The value to fill `array` with.
* @param {number} [start=0] The start position.
* @param {number} [end=array.length] The end position.
* @returns {Array} Returns `array`.
* @example
*
* var array = [1, 2, 3];
*
* _.fill(array, 'a');
* console.log(array);
* // => ['a', 'a', 'a']
*
* _.fill(Array(3), 2);
* // => [2, 2, 2]
*
* _.fill([4, 6, 8], '*', 1, 2);
* // => [4, '*', 8]
*/
function fill(array, value, start, end) {
var length = array ? array.length : 0;
if (!length) {
return [];
}
if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
start = 0;
end = length;
}
return baseFill(array, value, start, end);
}
/**
* This method is like `_.find` except that it returns the index of the first
* element `predicate` returns truthy for instead of the element itself.
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to search.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {number} Returns the index of the found element, else `-1`.
* @example
*
* var users = [
* { 'user': 'barney', 'active': false },
* { 'user': 'fred', 'active': false },
* { 'user': 'pebbles', 'active': true }
* ];
*
* _.findIndex(users, function(chr) {
* return chr.user == 'barney';
* });
* // => 0
*
* // using the `_.matches` callback shorthand
* _.findIndex(users, { 'user': 'fred', 'active': false });
* // => 1
*
* // using the `_.matchesProperty` callback shorthand
* _.findIndex(users, 'active', false);
* // => 0
*
* // using the `_.property` callback shorthand
* _.findIndex(users, 'active');
* // => 2
*/
var findIndex = createFindIndex();
/**
* This method is like `_.findIndex` except that it iterates over elements
* of `collection` from right to left.
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to search.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {number} Returns the index of the found element, else `-1`.
* @example
*
* var users = [
* { 'user': 'barney', 'active': true },
* { 'user': 'fred', 'active': false },
* { 'user': 'pebbles', 'active': false }
* ];
*
* _.findLastIndex(users, function(chr) {
* return chr.user == 'pebbles';
* });
* // => 2
*
* // using the `_.matches` callback shorthand
* _.findLastIndex(users, { 'user': 'barney', 'active': true });
* // => 0
*
* // using the `_.matchesProperty` callback shorthand
* _.findLastIndex(users, 'active', false);
* // => 2
*
* // using the `_.property` callback shorthand
* _.findLastIndex(users, 'active');
* // => 0
*/
var findLastIndex = createFindIndex(true);
/**
* Gets the first element of `array`.
*
* @static
* @memberOf _
* @alias head
* @category Array
* @param {Array} array The array to query.
* @returns {*} Returns the first element of `array`.
* @example
*
* _.first([1, 2, 3]);
* // => 1
*
* _.first([]);
* // => undefined
*/
function first(array) {
return array ? array[0] : undefined;
}
/**
* Flattens a nested array. If `isDeep` is `true` the array is recursively
* flattened, otherwise it is only flattened a single level.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to flatten.
* @param {boolean} [isDeep] Specify a deep flatten.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {Array} Returns the new flattened array.
* @example
*
* _.flatten([1, [2, 3, [4]]]);
* // => [1, 2, 3, [4]]
*
* // using `isDeep`
* _.flatten([1, [2, 3, [4]]], true);
* // => [1, 2, 3, 4]
*/
function flatten(array, isDeep, guard) {
var length = array ? array.length : 0;
if (guard && isIterateeCall(array, isDeep, guard)) {
isDeep = false;
}
return length ? baseFlatten(array, isDeep) : [];
}
/**
* Recursively flattens a nested array.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to recursively flatten.
* @returns {Array} Returns the new flattened array.
* @example
*
* _.flattenDeep([1, [2, 3, [4]]]);
* // => [1, 2, 3, 4]
*/
function flattenDeep(array) {
var length = array ? array.length : 0;
return length ? baseFlatten(array, true) : [];
}
/**
* Gets the index at which the first occurrence of `value` is found in `array`
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
* for equality comparisons. If `fromIndex` is negative, it is used as the offset
* from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
* performs a faster binary search.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to search.
* @param {*} value The value to search for.
* @param {boolean|number} [fromIndex=0] The index to search from or `true`
* to perform a binary search on a sorted array.
* @returns {number} Returns the index of the matched value, else `-1`.
* @example
*
* _.indexOf([1, 2, 1, 2], 2);
* // => 1
*
* // using `fromIndex`
* _.indexOf([1, 2, 1, 2], 2, 2);
* // => 3
*
* // performing a binary search
* _.indexOf([1, 1, 2, 2], 2, true);
* // => 2
*/
function indexOf(array, value, fromIndex) {
var length = array ? array.length : 0;
if (!length) {
return -1;
}
if (typeof fromIndex == 'number') {
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
} else if (fromIndex) {
var index = binaryIndex(array, value);
if (index < length &&
(value === value ? (value === array[index]) : (array[index] !== array[index]))) {
return index;
}
return -1;
}
return baseIndexOf(array, value, fromIndex || 0);
}
/**
* Gets all but the last element of `array`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to query.
* @returns {Array} Returns the slice of `array`.
* @example
*
* _.initial([1, 2, 3]);
* // => [1, 2]
*/
function initial(array) {
return dropRight(array, 1);
}
/**
* Creates an array of unique values that are included in all of the provided
* arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
* for equality comparisons.
*
* @static
* @memberOf _
* @category Array
* @param {...Array} [arrays] The arrays to inspect.
* @returns {Array} Returns the new array of shared values.
* @example
* _.intersection([1, 2], [4, 2], [2, 1]);
* // => [2]
*/
var intersection = restParam(function(arrays) {
var othLength = arrays.length,
othIndex = othLength,
caches = Array(length),
indexOf = getIndexOf(),
isCommon = indexOf == baseIndexOf,
result = [];
while (othIndex--) {
var value = arrays[othIndex] = isArrayLike(value = arrays[othIndex]) ? value : [];
caches[othIndex] = (isCommon && value.length >= 120) ? createCache(othIndex && value) : null;
}
var array = arrays[0],
index = -1,
length = array ? array.length : 0,
seen = caches[0];
outer:
while (++index < length) {
value = array[index];
if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
var othIndex = othLength;
while (--othIndex) {
var cache = caches[othIndex];
if ((cache ? cacheIndexOf(cache, value) : indexOf(arrays[othIndex], value, 0)) < 0) {
continue outer;
}
}
if (seen) {
seen.push(value);
}
result.push(value);
}
}
return result;
});
/**
* Gets the last element of `array`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to query.
* @returns {*} Returns the last element of `array`.
* @example
*
* _.last([1, 2, 3]);
* // => 3
*/
function last(array) {
var length = array ? array.length : 0;
return length ? array[length - 1] : undefined;
}
/**
* This method is like `_.indexOf` except that it iterates over elements of
* `array` from right to left.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to search.
* @param {*} value The value to search for.
* @param {boolean|number} [fromIndex=array.length-1] The index to search from
* or `true` to perform a binary search on a sorted array.
* @returns {number} Returns the index of the matched value, else `-1`.
* @example
*
* _.lastIndexOf([1, 2, 1, 2], 2);
* // => 3
*
* // using `fromIndex`
* _.lastIndexOf([1, 2, 1, 2], 2, 2);
* // => 1
*
* // performing a binary search
* _.lastIndexOf([1, 1, 2, 2], 2, true);
* // => 3
*/
function lastIndexOf(array, value, fromIndex) {
var length = array ? array.length : 0;
if (!length) {
return -1;
}
var index = length;
if (typeof fromIndex == 'number') {
index = (fromIndex < 0 ? nativeMax(length + fromIndex, 0) : nativeMin(fromIndex || 0, length - 1)) + 1;
} else if (fromIndex) {
index = binaryIndex(array, value, true) - 1;
var other = array[index];
if (value === value ? (value === other) : (other !== other)) {
return index;
}
return -1;
}
if (value !== value) {
return indexOfNaN(array, index, true);
}
while (index--) {
if (array[index] === value) {
return index;
}
}
return -1;
}
/**
* Removes all provided values from `array` using
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
* for equality comparisons.
*
* **Note:** Unlike `_.without`, this method mutates `array`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to modify.
* @param {...*} [values] The values to remove.
* @returns {Array} Returns `array`.
* @example
*
* var array = [1, 2, 3, 1, 2, 3];
*
* _.pull(array, 2, 3);
* console.log(array);
* // => [1, 1]
*/
function pull() {
var args = arguments,
array = args[0];
if (!(array && array.length)) {
return array;
}
var index = 0,
indexOf = getIndexOf(),
length = args.length;
while (++index < length) {
var fromIndex = 0,
value = args[index];
while ((fromIndex = indexOf(array, value, fromIndex)) > -1) {
splice.call(array, fromIndex, 1);
}
}
return array;
}
/**
* Removes elements from `array` corresponding to the given indexes and returns
* an array of the removed elements. Indexes may be specified as an array of
* indexes or as individual arguments.
*
* **Note:** Unlike `_.at`, this method mutates `array`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to modify.
* @param {...(number|number[])} [indexes] The indexes of elements to remove,
* specified as individual indexes or arrays of indexes.
* @returns {Array} Returns the new array of removed elements.
* @example
*
* var array = [5, 10, 15, 20];
* var evens = _.pullAt(array, 1, 3);
*
* console.log(array);
* // => [5, 15]
*
* console.log(evens);
* // => [10, 20]
*/
var pullAt = restParam(function(array, indexes) {
indexes = baseFlatten(indexes);
var result = baseAt(array, indexes);
basePullAt(array, indexes.sort(baseCompareAscending));
return result;
});
/**
* Removes all elements from `array` that `predicate` returns truthy for
* and returns an array of the removed elements. The predicate is bound to
* `thisArg` and invoked with three arguments: (value, index, array).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* **Note:** Unlike `_.filter`, this method mutates `array`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to modify.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the new array of removed elements.
* @example
*
* var array = [1, 2, 3, 4];
* var evens = _.remove(array, function(n) {
* return n % 2 == 0;
* });
*
* console.log(array);
* // => [1, 3]
*
* console.log(evens);
* // => [2, 4]
*/
function remove(array, predicate, thisArg) {
var result = [];
if (!(array && array.length)) {
return result;
}
var index = -1,
indexes = [],
length = array.length;
predicate = getCallback(predicate, thisArg, 3);
while (++index < length) {
var value = array[index];
if (predicate(value, index, array)) {
result.push(value);
indexes.push(index);
}
}
basePullAt(array, indexes);
return result;
}
/**
* Gets all but the first element of `array`.
*
* @static
* @memberOf _
* @alias tail
* @category Array
* @param {Array} array The array to query.
* @returns {Array} Returns the slice of `array`.
* @example
*
* _.rest([1, 2, 3]);
* // => [2, 3]
*/
function rest(array) {
return drop(array, 1);
}
/**
* Creates a slice of `array` from `start` up to, but not including, `end`.
*
* **Note:** This method is used instead of `Array#slice` to support node
* lists in IE < 9 and to ensure dense arrays are returned.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to slice.
* @param {number} [start=0] The start position.
* @param {number} [end=array.length] The end position.
* @returns {Array} Returns the slice of `array`.
*/
function slice(array, start, end) {
var length = array ? array.length : 0;
if (!length) {
return [];
}
if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
start = 0;
end = length;
}
return baseSlice(array, start, end);
}
/**
* Uses a binary search to determine the lowest index at which `value` should
* be inserted into `array` in order to maintain its sort order. If an iteratee
* function is provided it is invoked for `value` and each element of `array`
* to compute their sort ranking. The iteratee is bound to `thisArg` and
* invoked with one argument; (value).
*
* If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The sorted array to inspect.
* @param {*} value The value to evaluate.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {number} Returns the index at which `value` should be inserted
* into `array`.
* @example
*
* _.sortedIndex([30, 50], 40);
* // => 1
*
* _.sortedIndex([4, 4, 5, 5], 5);
* // => 2
*
* var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
*
* // using an iteratee function
* _.sortedIndex(['thirty', 'fifty'], 'forty', function(word) {
* return this.data[word];
* }, dict);
* // => 1
*
* // using the `_.property` callback shorthand
* _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
* // => 1
*/
var sortedIndex = createSortedIndex();
/**
* This method is like `_.sortedIndex` except that it returns the highest
* index at which `value` should be inserted into `array` in order to
* maintain its sort order.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The sorted array to inspect.
* @param {*} value The value to evaluate.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {number} Returns the index at which `value` should be inserted
* into `array`.
* @example
*
* _.sortedLastIndex([4, 4, 5, 5], 5);
* // => 4
*/
var sortedLastIndex = createSortedIndex(true);
/**
* Creates a slice of `array` with `n` elements taken from the beginning.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to take.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {Array} Returns the slice of `array`.
* @example
*
* _.take([1, 2, 3]);
* // => [1]
*
* _.take([1, 2, 3], 2);
* // => [1, 2]
*
* _.take([1, 2, 3], 5);
* // => [1, 2, 3]
*
* _.take([1, 2, 3], 0);
* // => []
*/
function take(array, n, guard) {
var length = array ? array.length : 0;
if (!length) {
return [];
}
if (guard ? isIterateeCall(array, n, guard) : n == null) {
n = 1;
}
return baseSlice(array, 0, n < 0 ? 0 : n);
}
/**
* Creates a slice of `array` with `n` elements taken from the end.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to take.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {Array} Returns the slice of `array`.
* @example
*
* _.takeRight([1, 2, 3]);
* // => [3]
*
* _.takeRight([1, 2, 3], 2);
* // => [2, 3]
*
* _.takeRight([1, 2, 3], 5);
* // => [1, 2, 3]
*
* _.takeRight([1, 2, 3], 0);
* // => []
*/
function takeRight(array, n, guard) {
var length = array ? array.length : 0;
if (!length) {
return [];
}
if (guard ? isIterateeCall(array, n, guard) : n == null) {
n = 1;
}
n = length - (+n || 0);
return baseSlice(array, n < 0 ? 0 : n);
}
/**
* Creates a slice of `array` with elements taken from the end. Elements are
* taken until `predicate` returns falsey. The predicate is bound to `thisArg`
* and invoked with three arguments: (value, index, array).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to query.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the slice of `array`.
* @example
*
* _.takeRightWhile([1, 2, 3], function(n) {
* return n > 1;
* });
* // => [2, 3]
*
* var users = [
* { 'user': 'barney', 'active': true },
* { 'user': 'fred', 'active': false },
* { 'user': 'pebbles', 'active': false }
* ];
*
* // using the `_.matches` callback shorthand
* _.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
* // => ['pebbles']
*
* // using the `_.matchesProperty` callback shorthand
* _.pluck(_.takeRightWhile(users, 'active', false), 'user');
* // => ['fred', 'pebbles']
*
* // using the `_.property` callback shorthand
* _.pluck(_.takeRightWhile(users, 'active'), 'user');
* // => []
*/
function takeRightWhile(array, predicate, thisArg) {
return (array && array.length)
? baseWhile(array, getCallback(predicate, thisArg, 3), false, true)
: [];
}
/**
* Creates a slice of `array` with elements taken from the beginning. Elements
* are taken until `predicate` returns falsey. The predicate is bound to
* `thisArg` and invoked with three arguments: (value, index, array).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to query.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the slice of `array`.
* @example
*
* _.takeWhile([1, 2, 3], function(n) {
* return n < 3;
* });
* // => [1, 2]
*
* var users = [
* { 'user': 'barney', 'active': false },
* { 'user': 'fred', 'active': false},
* { 'user': 'pebbles', 'active': true }
* ];
*
* // using the `_.matches` callback shorthand
* _.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user');
* // => ['barney']
*
* // using the `_.matchesProperty` callback shorthand
* _.pluck(_.takeWhile(users, 'active', false), 'user');
* // => ['barney', 'fred']
*
* // using the `_.property` callback shorthand
* _.pluck(_.takeWhile(users, 'active'), 'user');
* // => []
*/
function takeWhile(array, predicate, thisArg) {
return (array && array.length)
? baseWhile(array, getCallback(predicate, thisArg, 3))
: [];
}
/**
* Creates an array of unique values, in order, from all of the provided arrays
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
* for equality comparisons.
*
* @static
* @memberOf _
* @category Array
* @param {...Array} [arrays] The arrays to inspect.
* @returns {Array} Returns the new array of combined values.
* @example
*
* _.union([1, 2], [4, 2], [2, 1]);
* // => [1, 2, 4]
*/
var union = restParam(function(arrays) {
return baseUniq(baseFlatten(arrays, false, true));
});
/**
* Creates a duplicate-free version of an array, using
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
* for equality comparisons, in which only the first occurence of each element
* is kept. Providing `true` for `isSorted` performs a faster search algorithm
* for sorted arrays. If an iteratee function is provided it is invoked for
* each element in the array to generate the criterion by which uniqueness
* is computed. The `iteratee` is bound to `thisArg` and invoked with three
* arguments: (value, index, array).
*
* If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @alias unique
* @category Array
* @param {Array} array The array to inspect.
* @param {boolean} [isSorted] Specify the array is sorted.
* @param {Function|Object|string} [iteratee] The function invoked per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new duplicate-value-free array.
* @example
*
* _.uniq([2, 1, 2]);
* // => [2, 1]
*
* // using `isSorted`
* _.uniq([1, 1, 2], true);
* // => [1, 2]
*
* // using an iteratee function
* _.uniq([1, 2.5, 1.5, 2], function(n) {
* return this.floor(n);
* }, Math);
* // => [1, 2.5]
*
* // using the `_.property` callback shorthand
* _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
* // => [{ 'x': 1 }, { 'x': 2 }]
*/
function uniq(array, isSorted, iteratee, thisArg) {
var length = array ? array.length : 0;
if (!length) {
return [];
}
if (isSorted != null && typeof isSorted != 'boolean') {
thisArg = iteratee;
iteratee = isIterateeCall(array, isSorted, thisArg) ? undefined : isSorted;
isSorted = false;
}
var callback = getCallback();
if (!(iteratee == null && callback === baseCallback)) {
iteratee = callback(iteratee, thisArg, 3);
}
return (isSorted && getIndexOf() == baseIndexOf)
? sortedUniq(array, iteratee)
: baseUniq(array, iteratee);
}
/**
* This method is like `_.zip` except that it accepts an array of grouped
* elements and creates an array regrouping the elements to their pre-zip
* configuration.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array of grouped elements to process.
* @returns {Array} Returns the new array of regrouped elements.
* @example
*
* var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
* // => [['fred', 30, true], ['barney', 40, false]]
*
* _.unzip(zipped);
* // => [['fred', 'barney'], [30, 40], [true, false]]
*/
function unzip(array) {
if (!(array && array.length)) {
return [];
}
var index = -1,
length = 0;
array = arrayFilter(array, function(group) {
if (isArrayLike(group)) {
length = nativeMax(group.length, length);
return true;
}
});
var result = Array(length);
while (++index < length) {
result[index] = arrayMap(array, baseProperty(index));
}
return result;
}
/**
* This method is like `_.unzip` except that it accepts an iteratee to specify
* how regrouped values should be combined. The `iteratee` is bound to `thisArg`
* and invoked with four arguments: (accumulator, value, index, group).
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array of grouped elements to process.
* @param {Function} [iteratee] The function to combine regrouped values.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new array of regrouped elements.
* @example
*
* var zipped = _.zip([1, 2], [10, 20], [100, 200]);
* // => [[1, 10, 100], [2, 20, 200]]
*
* _.unzipWith(zipped, _.add);
* // => [3, 30, 300]
*/
function unzipWith(array, iteratee, thisArg) {
var length = array ? array.length : 0;
if (!length) {
return [];
}
var result = unzip(array);
if (iteratee == null) {
return result;
}
iteratee = bindCallback(iteratee, thisArg, 4);
return arrayMap(result, function(group) {
return arrayReduce(group, iteratee, undefined, true);
});
}
/**
* Creates an array excluding all provided values using
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
* for equality comparisons.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to filter.
* @param {...*} [values] The values to exclude.
* @returns {Array} Returns the new array of filtered values.
* @example
*
* _.without([1, 2, 1, 3], 1, 2);
* // => [3]
*/
var without = restParam(function(array, values) {
return isArrayLike(array)
? baseDifference(array, values)
: [];
});
/**
* Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
* of the provided arrays.
*
* @static
* @memberOf _
* @category Array
* @param {...Array} [arrays] The arrays to inspect.
* @returns {Array} Returns the new array of values.
* @example
*
* _.xor([1, 2], [4, 2]);
* // => [1, 4]
*/
function xor() {
var index = -1,
length = arguments.length;
while (++index < length) {
var array = arguments[index];
if (isArrayLike(array)) {
var result = result
? arrayPush(baseDifference(result, array), baseDifference(array, result))
: array;
}
}
return result ? baseUniq(result) : [];
}
/**
* Creates an array of grouped elements, the first of which contains the first
* elements of the given arrays, the second of which contains the second elements
* of the given arrays, and so on.
*
* @static
* @memberOf _
* @category Array
* @param {...Array} [arrays] The arrays to process.
* @returns {Array} Returns the new array of grouped elements.
* @example
*
* _.zip(['fred', 'barney'], [30, 40], [true, false]);
* // => [['fred', 30, true], ['barney', 40, false]]
*/
var zip = restParam(unzip);
/**
* The inverse of `_.pairs`; this method returns an object composed from arrays
* of property names and values. Provide either a single two dimensional array,
* e.g. `[[key1, value1], [key2, value2]]` or two arrays, one of property names
* and one of corresponding values.
*
* @static
* @memberOf _
* @alias object
* @category Array
* @param {Array} props The property names.
* @param {Array} [values=[]] The property values.
* @returns {Object} Returns the new object.
* @example
*
* _.zipObject([['fred', 30], ['barney', 40]]);
* // => { 'fred': 30, 'barney': 40 }
*
* _.zipObject(['fred', 'barney'], [30, 40]);
* // => { 'fred': 30, 'barney': 40 }
*/
function zipObject(props, values) {
var index = -1,
length = props ? props.length : 0,
result = {};
if (length && !values && !isArray(props[0])) {
values = [];
}
while (++index < length) {
var key = props[index];
if (values) {
result[key] = values[index];
} else if (key) {
result[key[0]] = key[1];
}
}
return result;
}
/**
* This method is like `_.zip` except that it accepts an iteratee to specify
* how grouped values should be combined. The `iteratee` is bound to `thisArg`
* and invoked with four arguments: (accumulator, value, index, group).
*
* @static
* @memberOf _
* @category Array
* @param {...Array} [arrays] The arrays to process.
* @param {Function} [iteratee] The function to combine grouped values.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new array of grouped elements.
* @example
*
* _.zipWith([1, 2], [10, 20], [100, 200], _.add);
* // => [111, 222]
*/
var zipWith = restParam(function(arrays) {
var length = arrays.length,
iteratee = length > 2 ? arrays[length - 2] : undefined,
thisArg = length > 1 ? arrays[length - 1] : undefined;
if (length > 2 && typeof iteratee == 'function') {
length -= 2;
} else {
iteratee = (length > 1 && typeof thisArg == 'function') ? (--length, thisArg) : undefined;
thisArg = undefined;
}
arrays.length = length;
return unzipWith(arrays, iteratee, thisArg);
});
/*------------------------------------------------------------------------*/
/**
* Creates a `lodash` object that wraps `value` with explicit method
* chaining enabled.
*
* @static
* @memberOf _
* @category Chain
* @param {*} value The value to wrap.
* @returns {Object} Returns the new `lodash` wrapper instance.
* @example
*
* var users = [
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 40 },
* { 'user': 'pebbles', 'age': 1 }
* ];
*
* var youngest = _.chain(users)
* .sortBy('age')
* .map(function(chr) {
* return chr.user + ' is ' + chr.age;
* })
* .first()
* .value();
* // => 'pebbles is 1'
*/
function chain(value) {
var result = lodash(value);
result.__chain__ = true;
return result;
}
/**
* This method invokes `interceptor` and returns `value`. The interceptor is
* bound to `thisArg` and invoked with one argument; (value). The purpose of
* this method is to "tap into" a method chain in order to perform operations
* on intermediate results within the chain.
*
* @static
* @memberOf _
* @category Chain
* @param {*} value The value to provide to `interceptor`.
* @param {Function} interceptor The function to invoke.
* @param {*} [thisArg] The `this` binding of `interceptor`.
* @returns {*} Returns `value`.
* @example
*
* _([1, 2, 3])
* .tap(function(array) {
* array.pop();
* })
* .reverse()
* .value();
* // => [2, 1]
*/
function tap(value, interceptor, thisArg) {
interceptor.call(thisArg, value);
return value;
}
/**
* This method is like `_.tap` except that it returns the result of `interceptor`.
*
* @static
* @memberOf _
* @category Chain
* @param {*} value The value to provide to `interceptor`.
* @param {Function} interceptor The function to invoke.
* @param {*} [thisArg] The `this` binding of `interceptor`.
* @returns {*} Returns the result of `interceptor`.
* @example
*
* _(' abc ')
* .chain()
* .trim()
* .thru(function(value) {
* return [value];
* })
* .value();
* // => ['abc']
*/
function thru(value, interceptor, thisArg) {
return interceptor.call(thisArg, value);
}
/**
* Enables explicit method chaining on the wrapper object.
*
* @name chain
* @memberOf _
* @category Chain
* @returns {Object} Returns the new `lodash` wrapper instance.
* @example
*
* var users = [
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 40 }
* ];
*
* // without explicit chaining
* _(users).first();
* // => { 'user': 'barney', 'age': 36 }
*
* // with explicit chaining
* _(users).chain()
* .first()
* .pick('user')
* .value();
* // => { 'user': 'barney' }
*/
function wrapperChain() {
return chain(this);
}
/**
* Executes the chained sequence and returns the wrapped result.
*
* @name commit
* @memberOf _
* @category Chain
* @returns {Object} Returns the new `lodash` wrapper instance.
* @example
*
* var array = [1, 2];
* var wrapped = _(array).push(3);
*
* console.log(array);
* // => [1, 2]
*
* wrapped = wrapped.commit();
* console.log(array);
* // => [1, 2, 3]
*
* wrapped.last();
* // => 3
*
* console.log(array);
* // => [1, 2, 3]
*/
function wrapperCommit() {
return new LodashWrapper(this.value(), this.__chain__);
}
/**
* Creates a new array joining a wrapped array with any additional arrays
* and/or values.
*
* @name concat
* @memberOf _
* @category Chain
* @param {...*} [values] The values to concatenate.
* @returns {Array} Returns the new concatenated array.
* @example
*
* var array = [1];
* var wrapped = _(array).concat(2, [3], [[4]]);
*
* console.log(wrapped.value());
* // => [1, 2, 3, [4]]
*
* console.log(array);
* // => [1]
*/
var wrapperConcat = restParam(function(values) {
values = baseFlatten(values);
return this.thru(function(array) {
return arrayConcat(isArray(array) ? array : [toObject(array)], values);
});
});
/**
* Creates a clone of the chained sequence planting `value` as the wrapped value.
*
* @name plant
* @memberOf _
* @category Chain
* @returns {Object} Returns the new `lodash` wrapper instance.
* @example
*
* var array = [1, 2];
* var wrapped = _(array).map(function(value) {
* return Math.pow(value, 2);
* });
*
* var other = [3, 4];
* var otherWrapped = wrapped.plant(other);
*
* otherWrapped.value();
* // => [9, 16]
*
* wrapped.value();
* // => [1, 4]
*/
function wrapperPlant(value) {
var result,
parent = this;
while (parent instanceof baseLodash) {
var clone = wrapperClone(parent);
if (result) {
previous.__wrapped__ = clone;
} else {
result = clone;
}
var previous = clone;
parent = parent.__wrapped__;
}
previous.__wrapped__ = value;
return result;
}
/**
* Reverses the wrapped array so the first element becomes the last, the
* second element becomes the second to last, and so on.
*
* **Note:** This method mutates the wrapped array.
*
* @name reverse
* @memberOf _
* @category Chain
* @returns {Object} Returns the new reversed `lodash` wrapper instance.
* @example
*
* var array = [1, 2, 3];
*
* _(array).reverse().value()
* // => [3, 2, 1]
*
* console.log(array);
* // => [3, 2, 1]
*/
function wrapperReverse() {
var value = this.__wrapped__;
var interceptor = function(value) {
return (wrapped && wrapped.__dir__ < 0) ? value : value.reverse();
};
if (value instanceof LazyWrapper) {
var wrapped = value;
if (this.__actions__.length) {
wrapped = new LazyWrapper(this);
}
wrapped = wrapped.reverse();
wrapped.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
return new LodashWrapper(wrapped, this.__chain__);
}
return this.thru(interceptor);
}
/**
* Produces the result of coercing the unwrapped value to a string.
*
* @name toString
* @memberOf _
* @category Chain
* @returns {string} Returns the coerced string value.
* @example
*
* _([1, 2, 3]).toString();
* // => '1,2,3'
*/
function wrapperToString() {
return (this.value() + '');
}
/**
* Executes the chained sequence to extract the unwrapped value.
*
* @name value
* @memberOf _
* @alias run, toJSON, valueOf
* @category Chain
* @returns {*} Returns the resolved unwrapped value.
* @example
*
* _([1, 2, 3]).value();
* // => [1, 2, 3]
*/
function wrapperValue() {
return baseWrapperValue(this.__wrapped__, this.__actions__);
}
/*------------------------------------------------------------------------*/
/**
* Creates an array of elements corresponding to the given keys, or indexes,
* of `collection`. Keys may be specified as individual arguments or as arrays
* of keys.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {...(number|number[]|string|string[])} [props] The property names
* or indexes of elements to pick, specified individually or in arrays.
* @returns {Array} Returns the new array of picked elements.
* @example
*
* _.at(['a', 'b', 'c'], [0, 2]);
* // => ['a', 'c']
*
* _.at(['barney', 'fred', 'pebbles'], 0, 2);
* // => ['barney', 'pebbles']
*/
var at = restParam(function(collection, props) {
return baseAt(collection, baseFlatten(props));
});
/**
* Creates an object composed of keys generated from the results of running
* each element of `collection` through `iteratee`. The corresponding value
* of each key is the number of times the key was returned by `iteratee`.
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection).
*
* If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Object} Returns the composed aggregate object.
* @example
*
* _.countBy([4.3, 6.1, 6.4], function(n) {
* return Math.floor(n);
* });
* // => { '4': 1, '6': 2 }
*
* _.countBy([4.3, 6.1, 6.4], function(n) {
* return this.floor(n);
* }, Math);
* // => { '4': 1, '6': 2 }
*
* _.countBy(['one', 'two', 'three'], 'length');
* // => { '3': 2, '5': 1 }
*/
var countBy = createAggregator(function(result, value, key) {
hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
});
/**
* Checks if `predicate` returns truthy for **all** elements of `collection`.
* The predicate is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @alias all
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {boolean} Returns `true` if all elements pass the predicate check,
* else `false`.
* @example
*
* _.every([true, 1, null, 'yes'], Boolean);
* // => false
*
* var users = [
* { 'user': 'barney', 'active': false },
* { 'user': 'fred', 'active': false }
* ];
*
* // using the `_.matches` callback shorthand
* _.every(users, { 'user': 'barney', 'active': false });
* // => false
*
* // using the `_.matchesProperty` callback shorthand
* _.every(users, 'active', false);
* // => true
*
* // using the `_.property` callback shorthand
* _.every(users, 'active');
* // => false
*/
function every(collection, predicate, thisArg) {
var func = isArray(collection) ? arrayEvery : baseEvery;
if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
predicate = undefined;
}
if (typeof predicate != 'function' || thisArg !== undefined) {
predicate = getCallback(predicate, thisArg, 3);
}
return func(collection, predicate);
}
/**
* Iterates over elements of `collection`, returning an array of all elements
* `predicate` returns truthy for. The predicate is bound to `thisArg` and
* invoked with three arguments: (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @alias select
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the new filtered array.
* @example
*
* _.filter([4, 5, 6], function(n) {
* return n % 2 == 0;
* });
* // => [4, 6]
*
* var users = [
* { 'user': 'barney', 'age': 36, 'active': true },
* { 'user': 'fred', 'age': 40, 'active': false }
* ];
*
* // using the `_.matches` callback shorthand
* _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user');
* // => ['barney']
*
* // using the `_.matchesProperty` callback shorthand
* _.pluck(_.filter(users, 'active', false), 'user');
* // => ['fred']
*
* // using the `_.property` callback shorthand
* _.pluck(_.filter(users, 'active'), 'user');
* // => ['barney']
*/
function filter(collection, predicate, thisArg) {
var func = isArray(collection) ? arrayFilter : baseFilter;
predicate = getCallback(predicate, thisArg, 3);
return func(collection, predicate);
}
/**
* Iterates over elements of `collection`, returning the first element
* `predicate` returns truthy for. The predicate is bound to `thisArg` and
* invoked with three arguments: (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @alias detect
* @category Collection
* @param {Array|Object|string} collection The collection to search.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {*} Returns the matched element, else `undefined`.
* @example
*
* var users = [
* { 'user': 'barney', 'age': 36, 'active': true },
* { 'user': 'fred', 'age': 40, 'active': false },
* { 'user': 'pebbles', 'age': 1, 'active': true }
* ];
*
* _.result(_.find(users, function(chr) {
* return chr.age < 40;
* }), 'user');
* // => 'barney'
*
* // using the `_.matches` callback shorthand
* _.result(_.find(users, { 'age': 1, 'active': true }), 'user');
* // => 'pebbles'
*
* // using the `_.matchesProperty` callback shorthand
* _.result(_.find(users, 'active', false), 'user');
* // => 'fred'
*
* // using the `_.property` callback shorthand
* _.result(_.find(users, 'active'), 'user');
* // => 'barney'
*/
var find = createFind(baseEach);
/**
* This method is like `_.find` except that it iterates over elements of
* `collection` from right to left.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to search.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {*} Returns the matched element, else `undefined`.
* @example
*
* _.findLast([1, 2, 3, 4], function(n) {
* return n % 2 == 1;
* });
* // => 3
*/
var findLast = createFind(baseEachRight, true);
/**
* Performs a deep comparison between each element in `collection` and the
* source object, returning the first element that has equivalent property
* values.
*
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
* numbers, `Object` objects, regexes, and strings. Objects are compared by
* their own, not inherited, enumerable properties. For comparing a single
* own or inherited property value see `_.matchesProperty`.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to search.
* @param {Object} source The object of property values to match.
* @returns {*} Returns the matched element, else `undefined`.
* @example
*
* var users = [
* { 'user': 'barney', 'age': 36, 'active': true },
* { 'user': 'fred', 'age': 40, 'active': false }
* ];
*
* _.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user');
* // => 'barney'
*
* _.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user');
* // => 'fred'
*/
function findWhere(collection, source) {
return find(collection, baseMatches(source));
}
/**
* Iterates over elements of `collection` invoking `iteratee` for each element.
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection). Iteratee functions may exit iteration early
* by explicitly returning `false`.
*
* **Note:** As with other "Collections" methods, objects with a "length" property
* are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
* may be used for object iteration.
*
* @static
* @memberOf _
* @alias each
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array|Object|string} Returns `collection`.
* @example
*
* _([1, 2]).forEach(function(n) {
* console.log(n);
* }).value();
* // => logs each value from left to right and returns the array
*
* _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
* console.log(n, key);
* });
* // => logs each value-key pair and returns the object (iteration order is not guaranteed)
*/
var forEach = createForEach(arrayEach, baseEach);
/**
* This method is like `_.forEach` except that it iterates over elements of
* `collection` from right to left.
*
* @static
* @memberOf _
* @alias eachRight
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array|Object|string} Returns `collection`.
* @example
*
* _([1, 2]).forEachRight(function(n) {
* console.log(n);
* }).value();
* // => logs each value from right to left and returns the array
*/
var forEachRight = createForEach(arrayEachRight, baseEachRight);
/**
* Creates an object composed of keys generated from the results of running
* each element of `collection` through `iteratee`. The corresponding value
* of each key is an array of the elements responsible for generating the key.
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection).
*
* If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Object} Returns the composed aggregate object.
* @example
*
* _.groupBy([4.2, 6.1, 6.4], function(n) {
* return Math.floor(n);
* });
* // => { '4': [4.2], '6': [6.1, 6.4] }
*
* _.groupBy([4.2, 6.1, 6.4], function(n) {
* return this.floor(n);
* }, Math);
* // => { '4': [4.2], '6': [6.1, 6.4] }
*
* // using the `_.property` callback shorthand
* _.groupBy(['one', 'two', 'three'], 'length');
* // => { '3': ['one', 'two'], '5': ['three'] }
*/
var groupBy = createAggregator(function(result, value, key) {
if (hasOwnProperty.call(result, key)) {
result[key].push(value);
} else {
result[key] = [value];
}
});
/**
* Checks if `value` is in `collection` using
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
* for equality comparisons. If `fromIndex` is negative, it is used as the offset
* from the end of `collection`.
*
* @static
* @memberOf _
* @alias contains, include
* @category Collection
* @param {Array|Object|string} collection The collection to search.
* @param {*} target The value to search for.
* @param {number} [fromIndex=0] The index to search from.
* @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
* @returns {boolean} Returns `true` if a matching element is found, else `false`.
* @example
*
* _.includes([1, 2, 3], 1);
* // => true
*
* _.includes([1, 2, 3], 1, 2);
* // => false
*
* _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
* // => true
*
* _.includes('pebbles', 'eb');
* // => true
*/
function includes(collection, target, fromIndex, guard) {
var length = collection ? getLength(collection) : 0;
if (!isLength(length)) {
collection = values(collection);
length = collection.length;
}
if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {
fromIndex = 0;
} else {
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
}
return (typeof collection == 'string' || !isArray(collection) && isString(collection))
? (fromIndex <= length && collection.indexOf(target, fromIndex) > -1)
: (!!length && getIndexOf(collection, target, fromIndex) > -1);
}
/**
* Creates an object composed of keys generated from the results of running
* each element of `collection` through `iteratee`. The corresponding value
* of each key is the last element responsible for generating the key. The
* iteratee function is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection).
*
* If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Object} Returns the composed aggregate object.
* @example
*
* var keyData = [
* { 'dir': 'left', 'code': 97 },
* { 'dir': 'right', 'code': 100 }
* ];
*
* _.indexBy(keyData, 'dir');
* // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
*
* _.indexBy(keyData, function(object) {
* return String.fromCharCode(object.code);
* });
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
*
* _.indexBy(keyData, function(object) {
* return this.fromCharCode(object.code);
* }, String);
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
*/
var indexBy = createAggregator(function(result, value, key) {
result[key] = value;
});
/**
* Invokes the method at `path` of each element in `collection`, returning
* an array of the results of each invoked method. Any additional arguments
* are provided to each invoked method. If `methodName` is a function it is
* invoked for, and `this` bound to, each element in `collection`.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Array|Function|string} path The path of the method to invoke or
* the function invoked per iteration.
* @param {...*} [args] The arguments to invoke the method with.
* @returns {Array} Returns the array of results.
* @example
*
* _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
* // => [[1, 5, 7], [1, 2, 3]]
*
* _.invoke([123, 456], String.prototype.split, '');
* // => [['1', '2', '3'], ['4', '5', '6']]
*/
var invoke = restParam(function(collection, path, args) {
var index = -1,
isFunc = typeof path == 'function',
isProp = isKey(path),
result = isArrayLike(collection) ? Array(collection.length) : [];
baseEach(collection, function(value) {
var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
result[++index] = func ? func.apply(value, args) : invokePath(value, path, args);
});
return result;
});
/**
* Creates an array of values by running each element in `collection` through
* `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
* arguments: (value, index|key, collection).
*
* If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* Many lodash methods are guarded to work as iteratees for methods like
* `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
*
* The guarded methods are:
* `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`,
* `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`,
* `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`,
* `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`,
* `sum`, `uniq`, and `words`
*
* @static
* @memberOf _
* @alias collect
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new mapped array.
* @example
*
* function timesThree(n) {
* return n * 3;
* }
*
* _.map([1, 2], timesThree);
* // => [3, 6]
*
* _.map({ 'a': 1, 'b': 2 }, timesThree);
* // => [3, 6] (iteration order is not guaranteed)
*
* var users = [
* { 'user': 'barney' },
* { 'user': 'fred' }
* ];
*
* // using the `_.property` callback shorthand
* _.map(users, 'user');
* // => ['barney', 'fred']
*/
function map(collection, iteratee, thisArg) {
var func = isArray(collection) ? arrayMap : baseMap;
iteratee = getCallback(iteratee, thisArg, 3);
return func(collection, iteratee);
}
/**
* Creates an array of elements split into two groups, the first of which
* contains elements `predicate` returns truthy for, while the second of which
* contains elements `predicate` returns falsey for. The predicate is bound
* to `thisArg` and invoked with three arguments: (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the array of grouped elements.
* @example
*
* _.partition([1, 2, 3], function(n) {
* return n % 2;
* });
* // => [[1, 3], [2]]
*
* _.partition([1.2, 2.3, 3.4], function(n) {
* return this.floor(n) % 2;
* }, Math);
* // => [[1.2, 3.4], [2.3]]
*
* var users = [
* { 'user': 'barney', 'age': 36, 'active': false },
* { 'user': 'fred', 'age': 40, 'active': true },
* { 'user': 'pebbles', 'age': 1, 'active': false }
* ];
*
* var mapper = function(array) {
* return _.pluck(array, 'user');
* };
*
* // using the `_.matches` callback shorthand
* _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
* // => [['pebbles'], ['barney', 'fred']]
*
* // using the `_.matchesProperty` callback shorthand
* _.map(_.partition(users, 'active', false), mapper);
* // => [['barney', 'pebbles'], ['fred']]
*
* // using the `_.property` callback shorthand
* _.map(_.partition(users, 'active'), mapper);
* // => [['fred'], ['barney', 'pebbles']]
*/
var partition = createAggregator(function(result, value, key) {
result[key ? 0 : 1].push(value);
}, function() { return [[], []]; });
/**
* Gets the property value of `path` from all elements in `collection`.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Array|string} path The path of the property to pluck.
* @returns {Array} Returns the property values.
* @example
*
* var users = [
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 40 }
* ];
*
* _.pluck(users, 'user');
* // => ['barney', 'fred']
*
* var userIndex = _.indexBy(users, 'user');
* _.pluck(userIndex, 'age');
* // => [36, 40] (iteration order is not guaranteed)
*/
function pluck(collection, path) {
return map(collection, property(path));
}
/**
* Reduces `collection` to a value which is the accumulated result of running
* each element in `collection` through `iteratee`, where each successive
* invocation is supplied the return value of the previous. If `accumulator`
* is not provided the first element of `collection` is used as the initial
* value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
* (accumulator, value, index|key, collection).
*
* Many lodash methods are guarded to work as iteratees for methods like
* `_.reduce`, `_.reduceRight`, and `_.transform`.
*
* The guarded methods are:
* `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `sortByAll`,
* and `sortByOrder`
*
* @static
* @memberOf _
* @alias foldl, inject
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {*} [accumulator] The initial value.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {*} Returns the accumulated value.
* @example
*
* _.reduce([1, 2], function(total, n) {
* return total + n;
* });
* // => 3
*
* _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
* result[key] = n * 3;
* return result;
* }, {});
* // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
*/
var reduce = createReduce(arrayReduce, baseEach);
/**
* This method is like `_.reduce` except that it iterates over elements of
* `collection` from right to left.
*
* @static
* @memberOf _
* @alias foldr
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {*} [accumulator] The initial value.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {*} Returns the accumulated value.
* @example
*
* var array = [[0, 1], [2, 3], [4, 5]];
*
* _.reduceRight(array, function(flattened, other) {
* return flattened.concat(other);
* }, []);
* // => [4, 5, 2, 3, 0, 1]
*/
var reduceRight = createReduce(arrayReduceRight, baseEachRight);
/**
* The opposite of `_.filter`; this method returns the elements of `collection`
* that `predicate` does **not** return truthy for.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the new filtered array.
* @example
*
* _.reject([1, 2, 3, 4], function(n) {
* return n % 2 == 0;
* });
* // => [1, 3]
*
* var users = [
* { 'user': 'barney', 'age': 36, 'active': false },
* { 'user': 'fred', 'age': 40, 'active': true }
* ];
*
* // using the `_.matches` callback shorthand
* _.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user');
* // => ['barney']
*
* // using the `_.matchesProperty` callback shorthand
* _.pluck(_.reject(users, 'active', false), 'user');
* // => ['fred']
*
* // using the `_.property` callback shorthand
* _.pluck(_.reject(users, 'active'), 'user');
* // => ['barney']
*/
function reject(collection, predicate, thisArg) {
var func = isArray(collection) ? arrayFilter : baseFilter;
predicate = getCallback(predicate, thisArg, 3);
return func(collection, function(value, index, collection) {
return !predicate(value, index, collection);
});
}
/**
* Gets a random element or `n` random elements from a collection.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to sample.
* @param {number} [n] The number of elements to sample.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {*} Returns the random sample(s).
* @example
*
* _.sample([1, 2, 3, 4]);
* // => 2
*
* _.sample([1, 2, 3, 4], 2);
* // => [3, 1]
*/
function sample(collection, n, guard) {
if (guard ? isIterateeCall(collection, n, guard) : n == null) {
collection = toIterable(collection);
var length = collection.length;
return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
}
var index = -1,
result = toArray(collection),
length = result.length,
lastIndex = length - 1;
n = nativeMin(n < 0 ? 0 : (+n || 0), length);
while (++index < n) {
var rand = baseRandom(index, lastIndex),
value = result[rand];
result[rand] = result[index];
result[index] = value;
}
result.length = n;
return result;
}
/**
* Creates an array of shuffled values, using a version of the
* [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to shuffle.
* @returns {Array} Returns the new shuffled array.
* @example
*
* _.shuffle([1, 2, 3, 4]);
* // => [4, 1, 3, 2]
*/
function shuffle(collection) {
return sample(collection, POSITIVE_INFINITY);
}
/**
* Gets the size of `collection` by returning its length for array-like
* values or the number of own enumerable properties for objects.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to inspect.
* @returns {number} Returns the size of `collection`.
* @example
*
* _.size([1, 2, 3]);
* // => 3
*
* _.size({ 'a': 1, 'b': 2 });
* // => 2
*
* _.size('pebbles');
* // => 7
*/
function size(collection) {
var length = collection ? getLength(collection) : 0;
return isLength(length) ? length : keys(collection).length;
}
/**
* Checks if `predicate` returns truthy for **any** element of `collection`.
* The function returns as soon as it finds a passing value and does not iterate
* over the entire collection. The predicate is bound to `thisArg` and invoked
* with three arguments: (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @alias any
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {boolean} Returns `true` if any element passes the predicate check,
* else `false`.
* @example
*
* _.some([null, 0, 'yes', false], Boolean);
* // => true
*
* var users = [
* { 'user': 'barney', 'active': true },
* { 'user': 'fred', 'active': false }
* ];
*
* // using the `_.matches` callback shorthand
* _.some(users, { 'user': 'barney', 'active': false });
* // => false
*
* // using the `_.matchesProperty` callback shorthand
* _.some(users, 'active', false);
* // => true
*
* // using the `_.property` callback shorthand
* _.some(users, 'active');
* // => true
*/
function some(collection, predicate, thisArg) {
var func = isArray(collection) ? arraySome : baseSome;
if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
predicate = undefined;
}
if (typeof predicate != 'function' || thisArg !== undefined) {
predicate = getCallback(predicate, thisArg, 3);
}
return func(collection, predicate);
}
/**
* Creates an array of elements, sorted in ascending order by the results of
* running each element in a collection through `iteratee`. This method performs
* a stable sort, that is, it preserves the original sort order of equal elements.
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection).
*
* If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new sorted array.
* @example
*
* _.sortBy([1, 2, 3], function(n) {
* return Math.sin(n);
* });
* // => [3, 1, 2]
*
* _.sortBy([1, 2, 3], function(n) {
* return this.sin(n);
* }, Math);
* // => [3, 1, 2]
*
* var users = [
* { 'user': 'fred' },
* { 'user': 'pebbles' },
* { 'user': 'barney' }
* ];
*
* // using the `_.property` callback shorthand
* _.pluck(_.sortBy(users, 'user'), 'user');
* // => ['barney', 'fred', 'pebbles']
*/
function sortBy(collection, iteratee, thisArg) {
if (collection == null) {
return [];
}
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
iteratee = undefined;
}
var index = -1;
iteratee = getCallback(iteratee, thisArg, 3);
var result = baseMap(collection, function(value, key, collection) {
return { 'criteria': iteratee(value, key, collection), 'index': ++index, 'value': value };
});
return baseSortBy(result, compareAscending);
}
/**
* This method is like `_.sortBy` except that it can sort by multiple iteratees
* or property names.
*
* If a property name is provided for an iteratee the created `_.property`
* style callback returns the property value of the given element.
*
* If an object is provided for an iteratee the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {...(Function|Function[]|Object|Object[]|string|string[])} iteratees
* The iteratees to sort by, specified as individual values or arrays of values.
* @returns {Array} Returns the new sorted array.
* @example
*
* var users = [
* { 'user': 'fred', 'age': 48 },
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 42 },
* { 'user': 'barney', 'age': 34 }
* ];
*
* _.map(_.sortByAll(users, ['user', 'age']), _.values);
* // => [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
*
* _.map(_.sortByAll(users, 'user', function(chr) {
* return Math.floor(chr.age / 10);
* }), _.values);
* // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
*/
var sortByAll = restParam(function(collection, iteratees) {
if (collection == null) {
return [];
}
var guard = iteratees[2];
if (guard && isIterateeCall(iteratees[0], iteratees[1], guard)) {
iteratees.length = 1;
}
return baseSortByOrder(collection, baseFlatten(iteratees), []);
});
/**
* This method is like `_.sortByAll` except that it allows specifying the
* sort orders of the iteratees to sort by. If `orders` is unspecified, all
* values are sorted in ascending order. Otherwise, a value is sorted in
* ascending order if its corresponding order is "asc", and descending if "desc".
*
* If a property name is provided for an iteratee the created `_.property`
* style callback returns the property value of the given element.
*
* If an object is provided for an iteratee the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
* @param {boolean[]} [orders] The sort orders of `iteratees`.
* @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
* @returns {Array} Returns the new sorted array.
* @example
*
* var users = [
* { 'user': 'fred', 'age': 48 },
* { 'user': 'barney', 'age': 34 },
* { 'user': 'fred', 'age': 42 },
* { 'user': 'barney', 'age': 36 }
* ];
*
* // sort by `user` in ascending order and by `age` in descending order
* _.map(_.sortByOrder(users, ['user', 'age'], ['asc', 'desc']), _.values);
* // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
*/
function sortByOrder(collection, iteratees, orders, guard) {
if (collection == null) {
return [];
}
if (guard && isIterateeCall(iteratees, orders, guard)) {
orders = undefined;
}
if (!isArray(iteratees)) {
iteratees = iteratees == null ? [] : [iteratees];
}
if (!isArray(orders)) {
orders = orders == null ? [] : [orders];
}
return baseSortByOrder(collection, iteratees, orders);
}
/**
* Performs a deep comparison between each element in `collection` and the
* source object, returning an array of all elements that have equivalent
* property values.
*
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
* numbers, `Object` objects, regexes, and strings. Objects are compared by
* their own, not inherited, enumerable properties. For comparing a single
* own or inherited property value see `_.matchesProperty`.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to search.
* @param {Object} source The object of property values to match.
* @returns {Array} Returns the new filtered array.
* @example
*
* var users = [
* { 'user': 'barney', 'age': 36, 'active': false, 'pets': ['hoppy'] },
* { 'user': 'fred', 'age': 40, 'active': true, 'pets': ['baby puss', 'dino'] }
* ];
*
* _.pluck(_.where(users, { 'age': 36, 'active': false }), 'user');
* // => ['barney']
*
* _.pluck(_.where(users, { 'pets': ['dino'] }), 'user');
* // => ['fred']
*/
function where(collection, source) {
return filter(collection, baseMatches(source));
}
/*------------------------------------------------------------------------*/
/**
* Gets the number of milliseconds that have elapsed since the Unix epoch
* (1 January 1970 00:00:00 UTC).
*
* @static
* @memberOf _
* @category Date
* @example
*
* _.defer(function(stamp) {
* console.log(_.now() - stamp);
* }, _.now());
* // => logs the number of milliseconds it took for the deferred function to be invoked
*/
var now = nativeNow || function() {
return new Date().getTime();
};
/*------------------------------------------------------------------------*/
/**
* The opposite of `_.before`; this method creates a function that invokes
* `func` once it is called `n` or more times.
*
* @static
* @memberOf _
* @category Function
* @param {number} n The number of calls before `func` is invoked.
* @param {Function} func The function to restrict.
* @returns {Function} Returns the new restricted function.
* @example
*
* var saves = ['profile', 'settings'];
*
* var done = _.after(saves.length, function() {
* console.log('done saving!');
* });
*
* _.forEach(saves, function(type) {
* asyncSave({ 'type': type, 'complete': done });
* });
* // => logs 'done saving!' after the two async saves have completed
*/
function after(n, func) {
if (typeof func != 'function') {
if (typeof n == 'function') {
var temp = n;
n = func;
func = temp;
} else {
throw new TypeError(FUNC_ERROR_TEXT);
}
}
n = nativeIsFinite(n = +n) ? n : 0;
return function() {
if (--n < 1) {
return func.apply(this, arguments);
}
};
}
/**
* Creates a function that accepts up to `n` arguments ignoring any
* additional arguments.
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to cap arguments for.
* @param {number} [n=func.length] The arity cap.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {Function} Returns the new function.
* @example
*
* _.map(['6', '8', '10'], _.ary(parseInt, 1));
* // => [6, 8, 10]
*/
function ary(func, n, guard) {
if (guard && isIterateeCall(func, n, guard)) {
n = undefined;
}
n = (func && n == null) ? func.length : nativeMax(+n || 0, 0);
return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
}
/**
* Creates a function that invokes `func`, with the `this` binding and arguments
* of the created function, while it is called less than `n` times. Subsequent
* calls to the created function return the result of the last `func` invocation.
*
* @static
* @memberOf _
* @category Function
* @param {number} n The number of calls at which `func` is no longer invoked.
* @param {Function} func The function to restrict.
* @returns {Function} Returns the new restricted function.
* @example
*
* jQuery('#add').on('click', _.before(5, addContactToList));
* // => allows adding up to 4 contacts to the list
*/
function before(n, func) {
var result;
if (typeof func != 'function') {
if (typeof n == 'function') {
var temp = n;
n = func;
func = temp;
} else {
throw new TypeError(FUNC_ERROR_TEXT);
}
}
return function() {
if (--n > 0) {
result = func.apply(this, arguments);
}
if (n <= 1) {
func = undefined;
}
return result;
};
}
/**
* Creates a function that invokes `func` with the `this` binding of `thisArg`
* and prepends any additional `_.bind` arguments to those provided to the
* bound function.
*
* The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
* may be used as a placeholder for partially applied arguments.
*
* **Note:** Unlike native `Function#bind` this method does not set the "length"
* property of bound functions.
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to bind.
* @param {*} thisArg The `this` binding of `func`.
* @param {...*} [partials] The arguments to be partially applied.
* @returns {Function} Returns the new bound function.
* @example
*
* var greet = function(greeting, punctuation) {
* return greeting + ' ' + this.user + punctuation;
* };
*
* var object = { 'user': 'fred' };
*
* var bound = _.bind(greet, object, 'hi');
* bound('!');
* // => 'hi fred!'
*
* // using placeholders
* var bound = _.bind(greet, object, _, '!');
* bound('hi');
* // => 'hi fred!'
*/
var bind = restParam(function(func, thisArg, partials) {
var bitmask = BIND_FLAG;
if (partials.length) {
var holders = replaceHolders(partials, bind.placeholder);
bitmask |= PARTIAL_FLAG;
}
return createWrapper(func, bitmask, thisArg, partials, holders);
});
/**
* Binds methods of an object to the object itself, overwriting the existing
* method. Method names may be specified as individual arguments or as arrays
* of method names. If no method names are provided all enumerable function
* properties, own and inherited, of `object` are bound.
*
* **Note:** This method does not set the "length" property of bound functions.
*
* @static
* @memberOf _
* @category Function
* @param {Object} object The object to bind and assign the bound methods to.
* @param {...(string|string[])} [methodNames] The object method names to bind,
* specified as individual method names or arrays of method names.
* @returns {Object} Returns `object`.
* @example
*
* var view = {
* 'label': 'docs',
* 'onClick': function() {
* console.log('clicked ' + this.label);
* }
* };
*
* _.bindAll(view);
* jQuery('#docs').on('click', view.onClick);
* // => logs 'clicked docs' when the element is clicked
*/
var bindAll = restParam(function(object, methodNames) {
methodNames = methodNames.length ? baseFlatten(methodNames) : functions(object);
var index = -1,
length = methodNames.length;
while (++index < length) {
var key = methodNames[index];
object[key] = createWrapper(object[key], BIND_FLAG, object);
}
return object;
});
/**
* Creates a function that invokes the method at `object[key]` and prepends
* any additional `_.bindKey` arguments to those provided to the bound function.
*
* This method differs from `_.bind` by allowing bound functions to reference
* methods that may be redefined or don't yet exist.
* See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
* for more details.
*
* The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
* builds, may be used as a placeholder for partially applied arguments.
*
* @static
* @memberOf _
* @category Function
* @param {Object} object The object the method belongs to.
* @param {string} key The key of the method.
* @param {...*} [partials] The arguments to be partially applied.
* @returns {Function} Returns the new bound function.
* @example
*
* var object = {
* 'user': 'fred',
* 'greet': function(greeting, punctuation) {
* return greeting + ' ' + this.user + punctuation;
* }
* };
*
* var bound = _.bindKey(object, 'greet', 'hi');
* bound('!');
* // => 'hi fred!'
*
* object.greet = function(greeting, punctuation) {
* return greeting + 'ya ' + this.user + punctuation;
* };
*
* bound('!');
* // => 'hiya fred!'
*
* // using placeholders
* var bound = _.bindKey(object, 'greet', _, '!');
* bound('hi');
* // => 'hiya fred!'
*/
var bindKey = restParam(function(object, key, partials) {
var bitmask = BIND_FLAG | BIND_KEY_FLAG;
if (partials.length) {
var holders = replaceHolders(partials, bindKey.placeholder);
bitmask |= PARTIAL_FLAG;
}
return createWrapper(key, bitmask, object, partials, holders);
});
/**
* Creates a function that accepts one or more arguments of `func` that when
* called either invokes `func` returning its result, if all `func` arguments
* have been provided, or returns a function that accepts one or more of the
* remaining `func` arguments, and so on. The arity of `func` may be specified
* if `func.length` is not sufficient.
*
* The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
* may be used as a placeholder for provided arguments.
*
* **Note:** This method does not set the "length" property of curried functions.
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to curry.
* @param {number} [arity=func.length] The arity of `func`.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {Function} Returns the new curried function.
* @example
*
* var abc = function(a, b, c) {
* return [a, b, c];
* };
*
* var curried = _.curry(abc);
*
* curried(1)(2)(3);
* // => [1, 2, 3]
*
* curried(1, 2)(3);
* // => [1, 2, 3]
*
* curried(1, 2, 3);
* // => [1, 2, 3]
*
* // using placeholders
* curried(1)(_, 3)(2);
* // => [1, 2, 3]
*/
var curry = createCurry(CURRY_FLAG);
/**
* This method is like `_.curry` except that arguments are applied to `func`
* in the manner of `_.partialRight` instead of `_.partial`.
*
* The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
* builds, may be used as a placeholder for provided arguments.
*
* **Note:** This method does not set the "length" property of curried functions.
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to curry.
* @param {number} [arity=func.length] The arity of `func`.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {Function} Returns the new curried function.
* @example
*
* var abc = function(a, b, c) {
* return [a, b, c];
* };
*
* var curried = _.curryRight(abc);
*
* curried(3)(2)(1);
* // => [1, 2, 3]
*
* curried(2, 3)(1);
* // => [1, 2, 3]
*
* curried(1, 2, 3);
* // => [1, 2, 3]
*
* // using placeholders
* curried(3)(1, _)(2);
* // => [1, 2, 3]
*/
var curryRight = createCurry(CURRY_RIGHT_FLAG);
/**
* Creates a debounced function that delays invoking `func` until after `wait`
* milliseconds have elapsed since the last time the debounced function was
* invoked. The debounced function comes with a `cancel` method to cancel
* delayed invocations. Provide an options object to indicate that `func`
* should be invoked on the leading and/or trailing edge of the `wait` timeout.
* Subsequent calls to the debounced function return the result of the last
* `func` invocation.
*
* **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
* on the trailing edge of the timeout only if the the debounced function is
* invoked more than once during the `wait` timeout.
*
* See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
* for details over the differences between `_.debounce` and `_.throttle`.
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to debounce.
* @param {number} [wait=0] The number of milliseconds to delay.
* @param {Object} [options] The options object.
* @param {boolean} [options.leading=false] Specify invoking on the leading
* edge of the timeout.
* @param {number} [options.maxWait] The maximum time `func` is allowed to be
* delayed before it is invoked.
* @param {boolean} [options.trailing=true] Specify invoking on the trailing
* edge of the timeout.
* @returns {Function} Returns the new debounced function.
* @example
*
* // avoid costly calculations while the window size is in flux
* jQuery(window).on('resize', _.debounce(calculateLayout, 150));
*
* // invoke `sendMail` when the click event is fired, debouncing subsequent calls
* jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
* 'leading': true,
* 'trailing': false
* }));
*
* // ensure `batchLog` is invoked once after 1 second of debounced calls
* var source = new EventSource('/stream');
* jQuery(source).on('message', _.debounce(batchLog, 250, {
* 'maxWait': 1000
* }));
*
* // cancel a debounced call
* var todoChanges = _.debounce(batchLog, 1000);
* Object.observe(models.todo, todoChanges);
*
* Object.observe(models, function(changes) {
* if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
* todoChanges.cancel();
* }
* }, ['delete']);
*
* // ...at some point `models.todo` is changed
* models.todo.completed = true;
*
* // ...before 1 second has passed `models.todo` is deleted
* // which cancels the debounced `todoChanges` call
* delete models.todo;
*/
function debounce(func, wait, options) {
var args,
maxTimeoutId,
result,
stamp,
thisArg,
timeoutId,
trailingCall,
lastCalled = 0,
maxWait = false,
trailing = true;
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
wait = wait < 0 ? 0 : (+wait || 0);
if (options === true) {
var leading = true;
trailing = false;
} else if (isObject(options)) {
leading = !!options.leading;
maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait);
trailing = 'trailing' in options ? !!options.trailing : trailing;
}
function cancel() {
if (timeoutId) {
clearTimeout(timeoutId);
}
if (maxTimeoutId) {
clearTimeout(maxTimeoutId);
}
lastCalled = 0;
maxTimeoutId = timeoutId = trailingCall = undefined;
}
function complete(isCalled, id) {
if (id) {
clearTimeout(id);
}
maxTimeoutId = timeoutId = trailingCall = undefined;
if (isCalled) {
lastCalled = now();
result = func.apply(thisArg, args);
if (!timeoutId && !maxTimeoutId) {
args = thisArg = undefined;
}
}
}
function delayed() {
var remaining = wait - (now() - stamp);
if (remaining <= 0 || remaining > wait) {
complete(trailingCall, maxTimeoutId);
} else {
timeoutId = setTimeout(delayed, remaining);
}
}
function maxDelayed() {
complete(trailing, timeoutId);
}
function debounced() {
args = arguments;
stamp = now();
thisArg = this;
trailingCall = trailing && (timeoutId || !leading);
if (maxWait === false) {
var leadingCall = leading && !timeoutId;
} else {
if (!maxTimeoutId && !leading) {
lastCalled = stamp;
}
var remaining = maxWait - (stamp - lastCalled),
isCalled = remaining <= 0 || remaining > maxWait;
if (isCalled) {
if (maxTimeoutId) {
maxTimeoutId = clearTimeout(maxTimeoutId);
}
lastCalled = stamp;
result = func.apply(thisArg, args);
}
else if (!maxTimeoutId) {
maxTimeoutId = setTimeout(maxDelayed, remaining);
}
}
if (isCalled && timeoutId) {
timeoutId = clearTimeout(timeoutId);
}
else if (!timeoutId && wait !== maxWait) {
timeoutId = setTimeout(delayed, wait);
}
if (leadingCall) {
isCalled = true;
result = func.apply(thisArg, args);
}
if (isCalled && !timeoutId && !maxTimeoutId) {
args = thisArg = undefined;
}
return result;
}
debounced.cancel = cancel;
return debounced;
}
/**
* Defers invoking the `func` until the current call stack has cleared. Any
* additional arguments are provided to `func` when it is invoked.
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to defer.
* @param {...*} [args] The arguments to invoke the function with.
* @returns {number} Returns the timer id.
* @example
*
* _.defer(function(text) {
* console.log(text);
* }, 'deferred');
* // logs 'deferred' after one or more milliseconds
*/
var defer = restParam(function(func, args) {
return baseDelay(func, 1, args);
});
/**
* Invokes `func` after `wait` milliseconds. Any additional arguments are
* provided to `func` when it is invoked.
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to delay.
* @param {number} wait The number of milliseconds to delay invocation.
* @param {...*} [args] The arguments to invoke the function with.
* @returns {number} Returns the timer id.
* @example
*
* _.delay(function(text) {
* console.log(text);
* }, 1000, 'later');
* // => logs 'later' after one second
*/
var delay = restParam(function(func, wait, args) {
return baseDelay(func, wait, args);
});
/**
* Creates a function that returns the result of invoking the provided
* functions with the `this` binding of the created function, where each
* successive invocation is supplied the return value of the previous.
*
* @static
* @memberOf _
* @category Function
* @param {...Function} [funcs] Functions to invoke.
* @returns {Function} Returns the new function.
* @example
*
* function square(n) {
* return n * n;
* }
*
* var addSquare = _.flow(_.add, square);
* addSquare(1, 2);
* // => 9
*/
var flow = createFlow();
/**
* This method is like `_.flow` except that it creates a function that
* invokes the provided functions from right to left.
*
* @static
* @memberOf _
* @alias backflow, compose
* @category Function
* @param {...Function} [funcs] Functions to invoke.
* @returns {Function} Returns the new function.
* @example
*
* function square(n) {
* return n * n;
* }
*
* var addSquare = _.flowRight(square, _.add);
* addSquare(1, 2);
* // => 9
*/
var flowRight = createFlow(true);
/**
* Creates a function that memoizes the result of `func`. If `resolver` is
* provided it determines the cache key for storing the result based on the
* arguments provided to the memoized function. By default, the first argument
* provided to the memoized function is coerced to a string and used as the
* cache key. The `func` is invoked with the `this` binding of the memoized
* function.
*
* **Note:** The cache is exposed as the `cache` property on the memoized
* function. Its creation may be customized by replacing the `_.memoize.Cache`
* constructor with one whose instances implement the [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
* method interface of `get`, `has`, and `set`.
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to have its output memoized.
* @param {Function} [resolver] The function to resolve the cache key.
* @returns {Function} Returns the new memoizing function.
* @example
*
* var upperCase = _.memoize(function(string) {
* return string.toUpperCase();
* });
*
* upperCase('fred');
* // => 'FRED'
*
* // modifying the result cache
* upperCase.cache.set('fred', 'BARNEY');
* upperCase('fred');
* // => 'BARNEY'
*
* // replacing `_.memoize.Cache`
* var object = { 'user': 'fred' };
* var other = { 'user': 'barney' };
* var identity = _.memoize(_.identity);
*
* identity(object);
* // => { 'user': 'fred' }
* identity(other);
* // => { 'user': 'fred' }
*
* _.memoize.Cache = WeakMap;
* var identity = _.memoize(_.identity);
*
* identity(object);
* // => { 'user': 'fred' }
* identity(other);
* // => { 'user': 'barney' }
*/
function memoize(func, resolver) {
if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
throw new TypeError(FUNC_ERROR_TEXT);
}
var memoized = function() {
var args = arguments,
key = resolver ? resolver.apply(this, args) : args[0],
cache = memoized.cache;
if (cache.has(key)) {
return cache.get(key);
}
var result = func.apply(this, args);
memoized.cache = cache.set(key, result);
return result;
};
memoized.cache = new memoize.Cache;
return memoized;
}
/**
* Creates a function that runs each argument through a corresponding
* transform function.
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to wrap.
* @param {...(Function|Function[])} [transforms] The functions to transform
* arguments, specified as individual functions or arrays of functions.
* @returns {Function} Returns the new function.
* @example
*
* function doubled(n) {
* return n * 2;
* }
*
* function square(n) {
* return n * n;
* }
*
* var modded = _.modArgs(function(x, y) {
* return [x, y];
* }, square, doubled);
*
* modded(1, 2);
* // => [1, 4]
*
* modded(5, 10);
* // => [25, 20]
*/
var modArgs = restParam(function(func, transforms) {
transforms = baseFlatten(transforms);
if (typeof func != 'function' || !arrayEvery(transforms, baseIsFunction)) {
throw new TypeError(FUNC_ERROR_TEXT);
}
var length = transforms.length;
return restParam(function(args) {
var index = nativeMin(args.length, length);
while (index--) {
args[index] = transforms[index](args[index]);
}
return func.apply(this, args);
});
});
/**
* Creates a function that negates the result of the predicate `func`. The
* `func` predicate is invoked with the `this` binding and arguments of the
* created function.
*
* @static
* @memberOf _
* @category Function
* @param {Function} predicate The predicate to negate.
* @returns {Function} Returns the new function.
* @example
*
* function isEven(n) {
* return n % 2 == 0;
* }
*
* _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
* // => [1, 3, 5]
*/
function negate(predicate) {
if (typeof predicate != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
return function() {
return !predicate.apply(this, arguments);
};
}
/**
* Creates a function that is restricted to invoking `func` once. Repeat calls
* to the function return the value of the first call. The `func` is invoked
* with the `this` binding and arguments of the created function.
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to restrict.
* @returns {Function} Returns the new restricted function.
* @example
*
* var initialize = _.once(createApplication);
* initialize();
* initialize();
* // `initialize` invokes `createApplication` once
*/
function once(func) {
return before(2, func);
}
/**
* Creates a function that invokes `func` with `partial` arguments prepended
* to those provided to the new function. This method is like `_.bind` except
* it does **not** alter the `this` binding.
*
* The `_.partial.placeholder` value, which defaults to `_` in monolithic
* builds, may be used as a placeholder for partially applied arguments.
*
* **Note:** This method does not set the "length" property of partially
* applied functions.
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to partially apply arguments to.
* @param {...*} [partials] The arguments to be partially applied.
* @returns {Function} Returns the new partially applied function.
* @example
*
* var greet = function(greeting, name) {
* return greeting + ' ' + name;
* };
*
* var sayHelloTo = _.partial(greet, 'hello');
* sayHelloTo('fred');
* // => 'hello fred'
*
* // using placeholders
* var greetFred = _.partial(greet, _, 'fred');
* greetFred('hi');
* // => 'hi fred'
*/
var partial = createPartial(PARTIAL_FLAG);
/**
* This method is like `_.partial` except that partially applied arguments
* are appended to those provided to the new function.
*
* The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
* builds, may be used as a placeholder for partially applied arguments.
*
* **Note:** This method does not set the "length" property of partially
* applied functions.
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to partially apply arguments to.
* @param {...*} [partials] The arguments to be partially applied.
* @returns {Function} Returns the new partially applied function.
* @example
*
* var greet = function(greeting, name) {
* return greeting + ' ' + name;
* };
*
* var greetFred = _.partialRight(greet, 'fred');
* greetFred('hi');
* // => 'hi fred'
*
* // using placeholders
* var sayHelloTo = _.partialRight(greet, 'hello', _);
* sayHelloTo('fred');
* // => 'hello fred'
*/
var partialRight = createPartial(PARTIAL_RIGHT_FLAG);
/**
* Creates a function that invokes `func` with arguments arranged according
* to the specified indexes where the argument value at the first index is
* provided as the first argument, the argument value at the second index is
* provided as the second argument, and so on.
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to rearrange arguments for.
* @param {...(number|number[])} indexes The arranged argument indexes,
* specified as individual indexes or arrays of indexes.
* @returns {Function} Returns the new function.
* @example
*
* var rearged = _.rearg(function(a, b, c) {
* return [a, b, c];
* }, 2, 0, 1);
*
* rearged('b', 'c', 'a')
* // => ['a', 'b', 'c']
*
* var map = _.rearg(_.map, [1, 0]);
* map(function(n) {
* return n * 3;
* }, [1, 2, 3]);
* // => [3, 6, 9]
*/
var rearg = restParam(function(func, indexes) {
return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes));
});
/**
* Creates a function that invokes `func` with the `this` binding of the
* created function and arguments from `start` and beyond provided as an array.
*
* **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to apply a rest parameter to.
* @param {number} [start=func.length-1] The start position of the rest parameter.
* @returns {Function} Returns the new function.
* @example
*
* var say = _.restParam(function(what, names) {
* return what + ' ' + _.initial(names).join(', ') +
* (_.size(names) > 1 ? ', & ' : '') + _.last(names);
* });
*
* say('hello', 'fred', 'barney', 'pebbles');
* // => 'hello fred, barney, & pebbles'
*/
function restParam(func, start) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
return function() {
var args = arguments,
index = -1,
length = nativeMax(args.length - start, 0),
rest = Array(length);
while (++index < length) {
rest[index] = args[start + index];
}
switch (start) {
case 0: return func.call(this, rest);
case 1: return func.call(this, args[0], rest);
case 2: return func.call(this, args[0], args[1], rest);
}
var otherArgs = Array(start + 1);
index = -1;
while (++index < start) {
otherArgs[index] = args[index];
}
otherArgs[start] = rest;
return func.apply(this, otherArgs);
};
}
/**
* Creates a function that invokes `func` with the `this` binding of the created
* function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
*
* **Note:** This method is based on the [spread operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator).
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to spread arguments over.
* @returns {Function} Returns the new function.
* @example
*
* var say = _.spread(function(who, what) {
* return who + ' says ' + what;
* });
*
* say(['fred', 'hello']);
* // => 'fred says hello'
*
* // with a Promise
* var numbers = Promise.all([
* Promise.resolve(40),
* Promise.resolve(36)
* ]);
*
* numbers.then(_.spread(function(x, y) {
* return x + y;
* }));
* // => a Promise of 76
*/
function spread(func) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
return function(array) {
return func.apply(this, array);
};
}
/**
* Creates a throttled function that only invokes `func` at most once per
* every `wait` milliseconds. The throttled function comes with a `cancel`
* method to cancel delayed invocations. Provide an options object to indicate
* that `func` should be invoked on the leading and/or trailing edge of the
* `wait` timeout. Subsequent calls to the throttled function return the
* result of the last `func` call.
*
* **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
* on the trailing edge of the timeout only if the the throttled function is
* invoked more than once during the `wait` timeout.
*
* See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
* for details over the differences between `_.throttle` and `_.debounce`.
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to throttle.
* @param {number} [wait=0] The number of milliseconds to throttle invocations to.
* @param {Object} [options] The options object.
* @param {boolean} [options.leading=true] Specify invoking on the leading
* edge of the timeout.
* @param {boolean} [options.trailing=true] Specify invoking on the trailing
* edge of the timeout.
* @returns {Function} Returns the new throttled function.
* @example
*
* // avoid excessively updating the position while scrolling
* jQuery(window).on('scroll', _.throttle(updatePosition, 100));
*
* // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
* jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
* 'trailing': false
* }));
*
* // cancel a trailing throttled call
* jQuery(window).on('popstate', throttled.cancel);
*/
function throttle(func, wait, options) {
var leading = true,
trailing = true;
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
if (options === false) {
leading = false;
} else if (isObject(options)) {
leading = 'leading' in options ? !!options.leading : leading;
trailing = 'trailing' in options ? !!options.trailing : trailing;
}
return debounce(func, wait, { 'leading': leading, 'maxWait': +wait, 'trailing': trailing });
}
/**
* Creates a function that provides `value` to the wrapper function as its
* first argument. Any additional arguments provided to the function are
* appended to those provided to the wrapper function. The wrapper is invoked
* with the `this` binding of the created function.
*
* @static
* @memberOf _
* @category Function
* @param {*} value The value to wrap.
* @param {Function} wrapper The wrapper function.
* @returns {Function} Returns the new function.
* @example
*
* var p = _.wrap(_.escape, function(func, text) {
* return '<p>' + func(text) + '</p>';
* });
*
* p('fred, barney, & pebbles');
* // => '<p>fred, barney, & pebbles</p>'
*/
function wrap(value, wrapper) {
wrapper = wrapper == null ? identity : wrapper;
return createWrapper(wrapper, PARTIAL_FLAG, undefined, [value], []);
}
/*------------------------------------------------------------------------*/
/**
* Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned,
* otherwise they are assigned by reference. If `customizer` is provided it is
* invoked to produce the cloned values. If `customizer` returns `undefined`
* cloning is handled by the method instead. The `customizer` is bound to
* `thisArg` and invoked with two argument; (value [, index|key, object]).
*
* **Note:** This method is loosely based on the
* [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
* The enumerable properties of `arguments` objects and objects created by
* constructors other than `Object` are cloned to plain `Object` objects. An
* empty object is returned for uncloneable values such as functions, DOM nodes,
* Maps, Sets, and WeakMaps.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to clone.
* @param {boolean} [isDeep] Specify a deep clone.
* @param {Function} [customizer] The function to customize cloning values.
* @param {*} [thisArg] The `this` binding of `customizer`.
* @returns {*} Returns the cloned value.
* @example
*
* var users = [
* { 'user': 'barney' },
* { 'user': 'fred' }
* ];
*
* var shallow = _.clone(users);
* shallow[0] === users[0];
* // => true
*
* var deep = _.clone(users, true);
* deep[0] === users[0];
* // => false
*
* // using a customizer callback
* var el = _.clone(document.body, function(value) {
* if (_.isElement(value)) {
* return value.cloneNode(false);
* }
* });
*
* el === document.body
* // => false
* el.nodeName
* // => BODY
* el.childNodes.length;
* // => 0
*/
function clone(value, isDeep, customizer, thisArg) {
if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {
isDeep = false;
}
else if (typeof isDeep == 'function') {
thisArg = customizer;
customizer = isDeep;
isDeep = false;
}
return typeof customizer == 'function'
? baseClone(value, isDeep, bindCallback(customizer, thisArg, 1))
: baseClone(value, isDeep);
}
/**
* Creates a deep clone of `value`. If `customizer` is provided it is invoked
* to produce the cloned values. If `customizer` returns `undefined` cloning
* is handled by the method instead. The `customizer` is bound to `thisArg`
* and invoked with two argument; (value [, index|key, object]).
*
* **Note:** This method is loosely based on the
* [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
* The enumerable properties of `arguments` objects and objects created by
* constructors other than `Object` are cloned to plain `Object` objects. An
* empty object is returned for uncloneable values such as functions, DOM nodes,
* Maps, Sets, and WeakMaps.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to deep clone.
* @param {Function} [customizer] The function to customize cloning values.
* @param {*} [thisArg] The `this` binding of `customizer`.
* @returns {*} Returns the deep cloned value.
* @example
*
* var users = [
* { 'user': 'barney' },
* { 'user': 'fred' }
* ];
*
* var deep = _.cloneDeep(users);
* deep[0] === users[0];
* // => false
*
* // using a customizer callback
* var el = _.cloneDeep(document.body, function(value) {
* if (_.isElement(value)) {
* return value.cloneNode(true);
* }
* });
*
* el === document.body
* // => false
* el.nodeName
* // => BODY
* el.childNodes.length;
* // => 20
*/
function cloneDeep(value, customizer, thisArg) {
return typeof customizer == 'function'
? baseClone(value, true, bindCallback(customizer, thisArg, 1))
: baseClone(value, true);
}
/**
* Checks if `value` is greater than `other`.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
* @example
*
* _.gt(3, 1);
* // => true
*
* _.gt(3, 3);
* // => false
*
* _.gt(1, 3);
* // => false
*/
function gt(value, other) {
return value > other;
}
/**
* Checks if `value` is greater than or equal to `other`.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`.
* @example
*
* _.gte(3, 1);
* // => true
*
* _.gte(3, 3);
* // => true
*
* _.gte(1, 3);
* // => false
*/
function gte(value, other) {
return value >= other;
}
/**
* Checks if `value` is classified as an `arguments` object.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
* @example
*
* _.isArguments(function() { return arguments; }());
* // => true
*
* _.isArguments([1, 2, 3]);
* // => false
*/
function isArguments(value) {
return isObjectLike(value) && isArrayLike(value) &&
hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
}
/**
* Checks if `value` is classified as an `Array` object.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
* @example
*
* _.isArray([1, 2, 3]);
* // => true
*
* _.isArray(function() { return arguments; }());
* // => false
*/
var isArray = nativeIsArray || function(value) {
return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
};
/**
* Checks if `value` is classified as a boolean primitive or object.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
* @example
*
* _.isBoolean(false);
* // => true
*
* _.isBoolean(null);
* // => false
*/
function isBoolean(value) {
return value === true || value === false || (isObjectLike(value) && objToString.call(value) == boolTag);
}
/**
* Checks if `value` is classified as a `Date` object.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
* @example
*
* _.isDate(new Date);
* // => true
*
* _.isDate('Mon April 23 2012');
* // => false
*/
function isDate(value) {
return isObjectLike(value) && objToString.call(value) == dateTag;
}
/**
* Checks if `value` is a DOM element.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
* @example
*
* _.isElement(document.body);
* // => true
*
* _.isElement('<body>');
* // => false
*/
function isElement(value) {
return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
}
/**
* Checks if `value` is empty. A value is considered empty unless it is an
* `arguments` object, array, string, or jQuery-like collection with a length
* greater than `0` or an object with own enumerable properties.
*
* @static
* @memberOf _
* @category Lang
* @param {Array|Object|string} value The value to inspect.
* @returns {boolean} Returns `true` if `value` is empty, else `false`.
* @example
*
* _.isEmpty(null);
* // => true
*
* _.isEmpty(true);
* // => true
*
* _.isEmpty(1);
* // => true
*
* _.isEmpty([1, 2, 3]);
* // => false
*
* _.isEmpty({ 'a': 1 });
* // => false
*/
function isEmpty(value) {
if (value == null) {
return true;
}
if (isArrayLike(value) && (isArray(value) || isString(value) || isArguments(value) ||
(isObjectLike(value) && isFunction(value.splice)))) {
return !value.length;
}
return !keys(value).length;
}
/**
* Performs a deep comparison between two values to determine if they are
* equivalent. If `customizer` is provided it is invoked to compare values.
* If `customizer` returns `undefined` comparisons are handled by the method
* instead. The `customizer` is bound to `thisArg` and invoked with three
* arguments: (value, other [, index|key]).
*
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
* numbers, `Object` objects, regexes, and strings. Objects are compared by
* their own, not inherited, enumerable properties. Functions and DOM nodes
* are **not** supported. Provide a customizer function to extend support
* for comparing other values.
*
* @static
* @memberOf _
* @alias eq
* @category Lang
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @param {Function} [customizer] The function to customize value comparisons.
* @param {*} [thisArg] The `this` binding of `customizer`.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
* @example
*
* var object = { 'user': 'fred' };
* var other = { 'user': 'fred' };
*
* object == other;
* // => false
*
* _.isEqual(object, other);
* // => true
*
* // using a customizer callback
* var array = ['hello', 'goodbye'];
* var other = ['hi', 'goodbye'];
*
* _.isEqual(array, other, function(value, other) {
* if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
* return true;
* }
* });
* // => true
*/
function isEqual(value, other, customizer, thisArg) {
customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
var result = customizer ? customizer(value, other) : undefined;
return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
}
/**
* Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
* `SyntaxError`, `TypeError`, or `URIError` object.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an error object, else `false`.
* @example
*
* _.isError(new Error);
* // => true
*
* _.isError(Error);
* // => false
*/
function isError(value) {
return isObjectLike(value) && typeof value.message == 'string' && objToString.call(value) == errorTag;
}
/**
* Checks if `value` is a finite primitive number.
*
* **Note:** This method is based on [`Number.isFinite`](http://ecma-international.org/ecma-262/6.0/#sec-number.isfinite).
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
* @example
*
* _.isFinite(10);
* // => true
*
* _.isFinite('10');
* // => false
*
* _.isFinite(true);
* // => false
*
* _.isFinite(Object(10));
* // => false
*
* _.isFinite(Infinity);
* // => false
*/
function isFinite(value) {
return typeof value == 'number' && nativeIsFinite(value);
}
/**
* Checks if `value` is classified as a `Function` object.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
* @example
*
* _.isFunction(_);
* // => true
*
* _.isFunction(/abc/);
* // => false
*/
function isFunction(value) {
// The use of `Object#toString` avoids issues with the `typeof` operator
// in older versions of Chrome and Safari which return 'function' for regexes
// and Safari 8 equivalents which return 'object' for typed array constructors.
return isObject(value) && objToString.call(value) == funcTag;
}
/**
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
* @example
*
* _.isObject({});
* // => true
*
* _.isObject([1, 2, 3]);
* // => true
*
* _.isObject(1);
* // => false
*/
function isObject(value) {
// Avoid a V8 JIT bug in Chrome 19-20.
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
var type = typeof value;
return !!value && (type == 'object' || type == 'function');
}
/**
* Performs a deep comparison between `object` and `source` to determine if
* `object` contains equivalent property values. If `customizer` is provided
* it is invoked to compare values. If `customizer` returns `undefined`
* comparisons are handled by the method instead. The `customizer` is bound
* to `thisArg` and invoked with three arguments: (value, other, index|key).
*
* **Note:** This method supports comparing properties of arrays, booleans,
* `Date` objects, numbers, `Object` objects, regexes, and strings. Functions
* and DOM nodes are **not** supported. Provide a customizer function to extend
* support for comparing other values.
*
* @static
* @memberOf _
* @category Lang
* @param {Object} object The object to inspect.
* @param {Object} source The object of property values to match.
* @param {Function} [customizer] The function to customize value comparisons.
* @param {*} [thisArg] The `this` binding of `customizer`.
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
* @example
*
* var object = { 'user': 'fred', 'age': 40 };
*
* _.isMatch(object, { 'age': 40 });
* // => true
*
* _.isMatch(object, { 'age': 36 });
* // => false
*
* // using a customizer callback
* var object = { 'greeting': 'hello' };
* var source = { 'greeting': 'hi' };
*
* _.isMatch(object, source, function(value, other) {
* return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
* });
* // => true
*/
function isMatch(object, source, customizer, thisArg) {
customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
return baseIsMatch(object, getMatchData(source), customizer);
}
/**
* Checks if `value` is `NaN`.
*
* **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
* which returns `true` for `undefined` and other non-numeric values.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
* @example
*
* _.isNaN(NaN);
* // => true
*
* _.isNaN(new Number(NaN));
* // => true
*
* isNaN(undefined);
* // => true
*
* _.isNaN(undefined);
* // => false
*/
function isNaN(value) {
// An `NaN` primitive is the only value that is not equal to itself.
// Perform the `toStringTag` check first to avoid errors with some host objects in IE.
return isNumber(value) && value != +value;
}
/**
* Checks if `value` is a native function.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a native function, else `false`.
* @example
*
* _.isNative(Array.prototype.push);
* // => true
*
* _.isNative(_);
* // => false
*/
function isNative(value) {
if (value == null) {
return false;
}
if (isFunction(value)) {
return reIsNative.test(fnToString.call(value));
}
return isObjectLike(value) && reIsHostCtor.test(value);
}
/**
* Checks if `value` is `null`.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is `null`, else `false`.
* @example
*
* _.isNull(null);
* // => true
*
* _.isNull(void 0);
* // => false
*/
function isNull(value) {
return value === null;
}
/**
* Checks if `value` is classified as a `Number` primitive or object.
*
* **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
* as numbers, use the `_.isFinite` method.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
* @example
*
* _.isNumber(8.4);
* // => true
*
* _.isNumber(NaN);
* // => true
*
* _.isNumber('8.4');
* // => false
*/
function isNumber(value) {
return typeof value == 'number' || (isObjectLike(value) && objToString.call(value) == numberTag);
}
/**
* Checks if `value` is a plain object, that is, an object created by the
* `Object` constructor or one with a `[[Prototype]]` of `null`.
*
* **Note:** This method assumes objects created by the `Object` constructor
* have no inherited enumerable properties.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
* @example
*
* function Foo() {
* this.a = 1;
* }
*
* _.isPlainObject(new Foo);
* // => false
*
* _.isPlainObject([1, 2, 3]);
* // => false
*
* _.isPlainObject({ 'x': 0, 'y': 0 });
* // => true
*
* _.isPlainObject(Object.create(null));
* // => true
*/
function isPlainObject(value) {
var Ctor;
// Exit early for non `Object` objects.
if (!(isObjectLike(value) && objToString.call(value) == objectTag && !isArguments(value)) ||
(!hasOwnProperty.call(value, 'constructor') && (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
return false;
}
// IE < 9 iterates inherited properties before own properties. If the first
// iterated property is an object's own property then there are no inherited
// enumerable properties.
var result;
// In most environments an object's own properties are iterated before
// its inherited properties. If the last iterated property is an object's
// own property then there are no inherited enumerable properties.
baseForIn(value, function(subValue, key) {
result = key;
});
return result === undefined || hasOwnProperty.call(value, result);
}
/**
* Checks if `value` is classified as a `RegExp` object.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
* @example
*
* _.isRegExp(/abc/);
* // => true
*
* _.isRegExp('/abc/');
* // => false
*/
function isRegExp(value) {
return isObject(value) && objToString.call(value) == regexpTag;
}
/**
* Checks if `value` is classified as a `String` primitive or object.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
* @example
*
* _.isString('abc');
* // => true
*
* _.isString(1);
* // => false
*/
function isString(value) {
return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag);
}
/**
* Checks if `value` is classified as a typed array.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
* @example
*
* _.isTypedArray(new Uint8Array);
* // => true
*
* _.isTypedArray([]);
* // => false
*/
function isTypedArray(value) {
return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objToString.call(value)];
}
/**
* Checks if `value` is `undefined`.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
* @example
*
* _.isUndefined(void 0);
* // => true
*
* _.isUndefined(null);
* // => false
*/
function isUndefined(value) {
return value === undefined;
}
/**
* Checks if `value` is less than `other`.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
* @example
*
* _.lt(1, 3);
* // => true
*
* _.lt(3, 3);
* // => false
*
* _.lt(3, 1);
* // => false
*/
function lt(value, other) {
return value < other;
}
/**
* Checks if `value` is less than or equal to `other`.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`.
* @example
*
* _.lte(1, 3);
* // => true
*
* _.lte(3, 3);
* // => true
*
* _.lte(3, 1);
* // => false
*/
function lte(value, other) {
return value <= other;
}
/**
* Converts `value` to an array.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to convert.
* @returns {Array} Returns the converted array.
* @example
*
* (function() {
* return _.toArray(arguments).slice(1);
* }(1, 2, 3));
* // => [2, 3]
*/
function toArray(value) {
var length = value ? getLength(value) : 0;
if (!isLength(length)) {
return values(value);
}
if (!length) {
return [];
}
return arrayCopy(value);
}
/**
* Converts `value` to a plain object flattening inherited enumerable
* properties of `value` to own properties of the plain object.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to convert.
* @returns {Object} Returns the converted plain object.
* @example
*
* function Foo() {
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* _.assign({ 'a': 1 }, new Foo);
* // => { 'a': 1, 'b': 2 }
*
* _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
* // => { 'a': 1, 'b': 2, 'c': 3 }
*/
function toPlainObject(value) {
return baseCopy(value, keysIn(value));
}
/*------------------------------------------------------------------------*/
/**
* Recursively merges own enumerable properties of the source object(s), that
* don't resolve to `undefined` into the destination object. Subsequent sources
* overwrite property assignments of previous sources. If `customizer` is
* provided it is invoked to produce the merged values of the destination and
* source properties. If `customizer` returns `undefined` merging is handled
* by the method instead. The `customizer` is bound to `thisArg` and invoked
* with five arguments: (objectValue, sourceValue, key, object, source).
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The destination object.
* @param {...Object} [sources] The source objects.
* @param {Function} [customizer] The function to customize assigned values.
* @param {*} [thisArg] The `this` binding of `customizer`.
* @returns {Object} Returns `object`.
* @example
*
* var users = {
* 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
* };
*
* var ages = {
* 'data': [{ 'age': 36 }, { 'age': 40 }]
* };
*
* _.merge(users, ages);
* // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
*
* // using a customizer callback
* var object = {
* 'fruits': ['apple'],
* 'vegetables': ['beet']
* };
*
* var other = {
* 'fruits': ['banana'],
* 'vegetables': ['carrot']
* };
*
* _.merge(object, other, function(a, b) {
* if (_.isArray(a)) {
* return a.concat(b);
* }
* });
* // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
*/
var merge = createAssigner(baseMerge);
/**
* Assigns own enumerable properties of source object(s) to the destination
* object. Subsequent sources overwrite property assignments of previous sources.
* If `customizer` is provided it is invoked to produce the assigned values.
* The `customizer` is bound to `thisArg` and invoked with five arguments:
* (objectValue, sourceValue, key, object, source).
*
* **Note:** This method mutates `object` and is based on
* [`Object.assign`](http://ecma-international.org/ecma-262/6.0/#sec-object.assign).
*
* @static
* @memberOf _
* @alias extend
* @category Object
* @param {Object} object The destination object.
* @param {...Object} [sources] The source objects.
* @param {Function} [customizer] The function to customize assigned values.
* @param {*} [thisArg] The `this` binding of `customizer`.
* @returns {Object} Returns `object`.
* @example
*
* _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' });
* // => { 'user': 'fred', 'age': 40 }
*
* // using a customizer callback
* var defaults = _.partialRight(_.assign, function(value, other) {
* return _.isUndefined(value) ? other : value;
* });
*
* defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
* // => { 'user': 'barney', 'age': 36 }
*/
var assign = createAssigner(function(object, source, customizer) {
return customizer
? assignWith(object, source, customizer)
: baseAssign(object, source);
});
/**
* Creates an object that inherits from the given `prototype` object. If a
* `properties` object is provided its own enumerable properties are assigned
* to the created object.
*
* @static
* @memberOf _
* @category Object
* @param {Object} prototype The object to inherit from.
* @param {Object} [properties] The properties to assign to the object.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {Object} Returns the new object.
* @example
*
* function Shape() {
* this.x = 0;
* this.y = 0;
* }
*
* function Circle() {
* Shape.call(this);
* }
*
* Circle.prototype = _.create(Shape.prototype, {
* 'constructor': Circle
* });
*
* var circle = new Circle;
* circle instanceof Circle;
* // => true
*
* circle instanceof Shape;
* // => true
*/
function create(prototype, properties, guard) {
var result = baseCreate(prototype);
if (guard && isIterateeCall(prototype, properties, guard)) {
properties = undefined;
}
return properties ? baseAssign(result, properties) : result;
}
/**
* Assigns own enumerable properties of source object(s) to the destination
* object for all destination properties that resolve to `undefined`. Once a
* property is set, additional values of the same property are ignored.
*
* **Note:** This method mutates `object`.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The destination object.
* @param {...Object} [sources] The source objects.
* @returns {Object} Returns `object`.
* @example
*
* _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
* // => { 'user': 'barney', 'age': 36 }
*/
var defaults = createDefaults(assign, assignDefaults);
/**
* This method is like `_.defaults` except that it recursively assigns
* default properties.
*
* **Note:** This method mutates `object`.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The destination object.
* @param {...Object} [sources] The source objects.
* @returns {Object} Returns `object`.
* @example
*
* _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } });
* // => { 'user': { 'name': 'barney', 'age': 36 } }
*
*/
var defaultsDeep = createDefaults(merge, mergeDefaults);
/**
* This method is like `_.find` except that it returns the key of the first
* element `predicate` returns truthy for instead of the element itself.
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to search.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {string|undefined} Returns the key of the matched element, else `undefined`.
* @example
*
* var users = {
* 'barney': { 'age': 36, 'active': true },
* 'fred': { 'age': 40, 'active': false },
* 'pebbles': { 'age': 1, 'active': true }
* };
*
* _.findKey(users, function(chr) {
* return chr.age < 40;
* });
* // => 'barney' (iteration order is not guaranteed)
*
* // using the `_.matches` callback shorthand
* _.findKey(users, { 'age': 1, 'active': true });
* // => 'pebbles'
*
* // using the `_.matchesProperty` callback shorthand
* _.findKey(users, 'active', false);
* // => 'fred'
*
* // using the `_.property` callback shorthand
* _.findKey(users, 'active');
* // => 'barney'
*/
var findKey = createFindKey(baseForOwn);
/**
* This method is like `_.findKey` except that it iterates over elements of
* a collection in the opposite order.
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to search.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {string|undefined} Returns the key of the matched element, else `undefined`.
* @example
*
* var users = {
* 'barney': { 'age': 36, 'active': true },
* 'fred': { 'age': 40, 'active': false },
* 'pebbles': { 'age': 1, 'active': true }
* };
*
* _.findLastKey(users, function(chr) {
* return chr.age < 40;
* });
* // => returns `pebbles` assuming `_.findKey` returns `barney`
*
* // using the `_.matches` callback shorthand
* _.findLastKey(users, { 'age': 36, 'active': true });
* // => 'barney'
*
* // using the `_.matchesProperty` callback shorthand
* _.findLastKey(users, 'active', false);
* // => 'fred'
*
* // using the `_.property` callback shorthand
* _.findLastKey(users, 'active');
* // => 'pebbles'
*/
var findLastKey = createFindKey(baseForOwnRight);
/**
* Iterates over own and inherited enumerable properties of an object invoking
* `iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked
* with three arguments: (value, key, object). Iteratee functions may exit
* iteration early by explicitly returning `false`.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Object} Returns `object`.
* @example
*
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* _.forIn(new Foo, function(value, key) {
* console.log(key);
* });
* // => logs 'a', 'b', and 'c' (iteration order is not guaranteed)
*/
var forIn = createForIn(baseFor);
/**
* This method is like `_.forIn` except that it iterates over properties of
* `object` in the opposite order.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Object} Returns `object`.
* @example
*
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* _.forInRight(new Foo, function(value, key) {
* console.log(key);
* });
* // => logs 'c', 'b', and 'a' assuming `_.forIn ` logs 'a', 'b', and 'c'
*/
var forInRight = createForIn(baseForRight);
/**
* Iterates over own enumerable properties of an object invoking `iteratee`
* for each property. The `iteratee` is bound to `thisArg` and invoked with
* three arguments: (value, key, object). Iteratee functions may exit iteration
* early by explicitly returning `false`.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Object} Returns `object`.
* @example
*
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* _.forOwn(new Foo, function(value, key) {
* console.log(key);
* });
* // => logs 'a' and 'b' (iteration order is not guaranteed)
*/
var forOwn = createForOwn(baseForOwn);
/**
* This method is like `_.forOwn` except that it iterates over properties of
* `object` in the opposite order.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Object} Returns `object`.
* @example
*
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* _.forOwnRight(new Foo, function(value, key) {
* console.log(key);
* });
* // => logs 'b' and 'a' assuming `_.forOwn` logs 'a' and 'b'
*/
var forOwnRight = createForOwn(baseForOwnRight);
/**
* Creates an array of function property names from all enumerable properties,
* own and inherited, of `object`.
*
* @static
* @memberOf _
* @alias methods
* @category Object
* @param {Object} object The object to inspect.
* @returns {Array} Returns the new array of property names.
* @example
*
* _.functions(_);
* // => ['after', 'ary', 'assign', ...]
*/
function functions(object) {
return baseFunctions(object, keysIn(object));
}
/**
* Gets the property value at `path` of `object`. If the resolved value is
* `undefined` the `defaultValue` is used in its place.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @param {Array|string} path The path of the property to get.
* @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
* @returns {*} Returns the resolved value.
* @example
*
* var object = { 'a': [{ 'b': { 'c': 3 } }] };
*
* _.get(object, 'a[0].b.c');
* // => 3
*
* _.get(object, ['a', '0', 'b', 'c']);
* // => 3
*
* _.get(object, 'a.b.c', 'default');
* // => 'default'
*/
function get(object, path, defaultValue) {
var result = object == null ? undefined : baseGet(object, toPath(path), path + '');
return result === undefined ? defaultValue : result;
}
/**
* Checks if `path` is a direct property.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @param {Array|string} path The path to check.
* @returns {boolean} Returns `true` if `path` is a direct property, else `false`.
* @example
*
* var object = { 'a': { 'b': { 'c': 3 } } };
*
* _.has(object, 'a');
* // => true
*
* _.has(object, 'a.b.c');
* // => true
*
* _.has(object, ['a', 'b', 'c']);
* // => true
*/
function has(object, path) {
if (object == null) {
return false;
}
var result = hasOwnProperty.call(object, path);
if (!result && !isKey(path)) {
path = toPath(path);
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
if (object == null) {
return false;
}
path = last(path);
result = hasOwnProperty.call(object, path);
}
return result || (isLength(object.length) && isIndex(path, object.length) &&
(isArray(object) || isArguments(object)));
}
/**
* Creates an object composed of the inverted keys and values of `object`.
* If `object` contains duplicate values, subsequent values overwrite property
* assignments of previous values unless `multiValue` is `true`.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to invert.
* @param {boolean} [multiValue] Allow multiple values per key.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {Object} Returns the new inverted object.
* @example
*
* var object = { 'a': 1, 'b': 2, 'c': 1 };
*
* _.invert(object);
* // => { '1': 'c', '2': 'b' }
*
* // with `multiValue`
* _.invert(object, true);
* // => { '1': ['a', 'c'], '2': ['b'] }
*/
function invert(object, multiValue, guard) {
if (guard && isIterateeCall(object, multiValue, guard)) {
multiValue = undefined;
}
var index = -1,
props = keys(object),
length = props.length,
result = {};
while (++index < length) {
var key = props[index],
value = object[key];
if (multiValue) {
if (hasOwnProperty.call(result, value)) {
result[value].push(key);
} else {
result[value] = [key];
}
}
else {
result[value] = key;
}
}
return result;
}
/**
* Creates an array of the own enumerable property names of `object`.
*
* **Note:** Non-object values are coerced to objects. See the
* [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
* for more details.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
* @example
*
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* _.keys(new Foo);
* // => ['a', 'b'] (iteration order is not guaranteed)
*
* _.keys('hi');
* // => ['0', '1']
*/
var keys = !nativeKeys ? shimKeys : function(object) {
var Ctor = object == null ? undefined : object.constructor;
if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
(typeof object != 'function' && isArrayLike(object))) {
return shimKeys(object);
}
return isObject(object) ? nativeKeys(object) : [];
};
/**
* Creates an array of the own and inherited enumerable property names of `object`.
*
* **Note:** Non-object values are coerced to objects.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
* @example
*
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* _.keysIn(new Foo);
* // => ['a', 'b', 'c'] (iteration order is not guaranteed)
*/
function keysIn(object) {
if (object == null) {
return [];
}
if (!isObject(object)) {
object = Object(object);
}
var length = object.length;
length = (length && isLength(length) &&
(isArray(object) || isArguments(object)) && length) || 0;
var Ctor = object.constructor,
index = -1,
isProto = typeof Ctor == 'function' && Ctor.prototype === object,
result = Array(length),
skipIndexes = length > 0;
while (++index < length) {
result[index] = (index + '');
}
for (var key in object) {
if (!(skipIndexes && isIndex(key, length)) &&
!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
result.push(key);
}
}
return result;
}
/**
* The opposite of `_.mapValues`; this method creates an object with the
* same values as `object` and keys generated by running each own enumerable
* property of `object` through `iteratee`.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Object} Returns the new mapped object.
* @example
*
* _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
* return key + value;
* });
* // => { 'a1': 1, 'b2': 2 }
*/
var mapKeys = createObjectMapper(true);
/**
* Creates an object with the same keys as `object` and values generated by
* running each own enumerable property of `object` through `iteratee`. The
* iteratee function is bound to `thisArg` and invoked with three arguments:
* (value, key, object).
*
* If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Object} Returns the new mapped object.
* @example
*
* _.mapValues({ 'a': 1, 'b': 2 }, function(n) {
* return n * 3;
* });
* // => { 'a': 3, 'b': 6 }
*
* var users = {
* 'fred': { 'user': 'fred', 'age': 40 },
* 'pebbles': { 'user': 'pebbles', 'age': 1 }
* };
*
* // using the `_.property` callback shorthand
* _.mapValues(users, 'age');
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
*/
var mapValues = createObjectMapper();
/**
* The opposite of `_.pick`; this method creates an object composed of the
* own and inherited enumerable properties of `object` that are not omitted.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The source object.
* @param {Function|...(string|string[])} [predicate] The function invoked per
* iteration or property names to omit, specified as individual property
* names or arrays of property names.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Object} Returns the new object.
* @example
*
* var object = { 'user': 'fred', 'age': 40 };
*
* _.omit(object, 'age');
* // => { 'user': 'fred' }
*
* _.omit(object, _.isNumber);
* // => { 'user': 'fred' }
*/
var omit = restParam(function(object, props) {
if (object == null) {
return {};
}
if (typeof props[0] != 'function') {
var props = arrayMap(baseFlatten(props), String);
return pickByArray(object, baseDifference(keysIn(object), props));
}
var predicate = bindCallback(props[0], props[1], 3);
return pickByCallback(object, function(value, key, object) {
return !predicate(value, key, object);
});
});
/**
* Creates a two dimensional array of the key-value pairs for `object`,
* e.g. `[[key1, value1], [key2, value2]]`.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @returns {Array} Returns the new array of key-value pairs.
* @example
*
* _.pairs({ 'barney': 36, 'fred': 40 });
* // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
*/
function pairs(object) {
object = toObject(object);
var index = -1,
props = keys(object),
length = props.length,
result = Array(length);
while (++index < length) {
var key = props[index];
result[index] = [key, object[key]];
}
return result;
}
/**
* Creates an object composed of the picked `object` properties. Property
* names may be specified as individual arguments or as arrays of property
* names. If `predicate` is provided it is invoked for each property of `object`
* picking the properties `predicate` returns truthy for. The predicate is
* bound to `thisArg` and invoked with three arguments: (value, key, object).
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The source object.
* @param {Function|...(string|string[])} [predicate] The function invoked per
* iteration or property names to pick, specified as individual property
* names or arrays of property names.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Object} Returns the new object.
* @example
*
* var object = { 'user': 'fred', 'age': 40 };
*
* _.pick(object, 'user');
* // => { 'user': 'fred' }
*
* _.pick(object, _.isString);
* // => { 'user': 'fred' }
*/
var pick = restParam(function(object, props) {
if (object == null) {
return {};
}
return typeof props[0] == 'function'
? pickByCallback(object, bindCallback(props[0], props[1], 3))
: pickByArray(object, baseFlatten(props));
});
/**
* This method is like `_.get` except that if the resolved value is a function
* it is invoked with the `this` binding of its parent object and its result
* is returned.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @param {Array|string} path The path of the property to resolve.
* @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
* @returns {*} Returns the resolved value.
* @example
*
* var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
*
* _.result(object, 'a[0].b.c1');
* // => 3
*
* _.result(object, 'a[0].b.c2');
* // => 4
*
* _.result(object, 'a.b.c', 'default');
* // => 'default'
*
* _.result(object, 'a.b.c', _.constant('default'));
* // => 'default'
*/
function result(object, path, defaultValue) {
var result = object == null ? undefined : object[path];
if (result === undefined) {
if (object != null && !isKey(path, object)) {
path = toPath(path);
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
result = object == null ? undefined : object[last(path)];
}
result = result === undefined ? defaultValue : result;
}
return isFunction(result) ? result.call(object) : result;
}
/**
* Sets the property value of `path` on `object`. If a portion of `path`
* does not exist it is created.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to augment.
* @param {Array|string} path The path of the property to set.
* @param {*} value The value to set.
* @returns {Object} Returns `object`.
* @example
*
* var object = { 'a': [{ 'b': { 'c': 3 } }] };
*
* _.set(object, 'a[0].b.c', 4);
* console.log(object.a[0].b.c);
* // => 4
*
* _.set(object, 'x[0].y.z', 5);
* console.log(object.x[0].y.z);
* // => 5
*/
function set(object, path, value) {
if (object == null) {
return object;
}
var pathKey = (path + '');
path = (object[pathKey] != null || isKey(path, object)) ? [pathKey] : toPath(path);
var index = -1,
length = path.length,
lastIndex = length - 1,
nested = object;
while (nested != null && ++index < length) {
var key = path[index];
if (isObject(nested)) {
if (index == lastIndex) {
nested[key] = value;
} else if (nested[key] == null) {
nested[key] = isIndex(path[index + 1]) ? [] : {};
}
}
nested = nested[key];
}
return object;
}
/**
* An alternative to `_.reduce`; this method transforms `object` to a new
* `accumulator` object which is the result of running each of its own enumerable
* properties through `iteratee`, with each invocation potentially mutating
* the `accumulator` object. The `iteratee` is bound to `thisArg` and invoked
* with four arguments: (accumulator, value, key, object). Iteratee functions
* may exit iteration early by explicitly returning `false`.
*
* @static
* @memberOf _
* @category Object
* @param {Array|Object} object The object to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {*} [accumulator] The custom accumulator value.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {*} Returns the accumulated value.
* @example
*
* _.transform([2, 3, 4], function(result, n) {
* result.push(n *= n);
* return n % 2 == 0;
* });
* // => [4, 9]
*
* _.transform({ 'a': 1, 'b': 2 }, function(result, n, key) {
* result[key] = n * 3;
* });
* // => { 'a': 3, 'b': 6 }
*/
function transform(object, iteratee, accumulator, thisArg) {
var isArr = isArray(object) || isTypedArray(object);
iteratee = getCallback(iteratee, thisArg, 4);
if (accumulator == null) {
if (isArr || isObject(object)) {
var Ctor = object.constructor;
if (isArr) {
accumulator = isArray(object) ? new Ctor : [];
} else {
accumulator = baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined);
}
} else {
accumulator = {};
}
}
(isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
return iteratee(accumulator, value, index, object);
});
return accumulator;
}
/**
* Creates an array of the own enumerable property values of `object`.
*
* **Note:** Non-object values are coerced to objects.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property values.
* @example
*
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* _.values(new Foo);
* // => [1, 2] (iteration order is not guaranteed)
*
* _.values('hi');
* // => ['h', 'i']
*/
function values(object) {
return baseValues(object, keys(object));
}
/**
* Creates an array of the own and inherited enumerable property values
* of `object`.
*
* **Note:** Non-object values are coerced to objects.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property values.
* @example
*
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* _.valuesIn(new Foo);
* // => [1, 2, 3] (iteration order is not guaranteed)
*/
function valuesIn(object) {
return baseValues(object, keysIn(object));
}
/*------------------------------------------------------------------------*/
/**
* Checks if `n` is between `start` and up to but not including, `end`. If
* `end` is not specified it is set to `start` with `start` then set to `0`.
*
* @static
* @memberOf _
* @category Number
* @param {number} n The number to check.
* @param {number} [start=0] The start of the range.
* @param {number} end The end of the range.
* @returns {boolean} Returns `true` if `n` is in the range, else `false`.
* @example
*
* _.inRange(3, 2, 4);
* // => true
*
* _.inRange(4, 8);
* // => true
*
* _.inRange(4, 2);
* // => false
*
* _.inRange(2, 2);
* // => false
*
* _.inRange(1.2, 2);
* // => true
*
* _.inRange(5.2, 4);
* // => false
*/
function inRange(value, start, end) {
start = +start || 0;
if (end === undefined) {
end = start;
start = 0;
} else {
end = +end || 0;
}
return value >= nativeMin(start, end) && value < nativeMax(start, end);
}
/**
* Produces a random number between `min` and `max` (inclusive). If only one
* argument is provided a number between `0` and the given number is returned.
* If `floating` is `true`, or either `min` or `max` are floats, a floating-point
* number is returned instead of an integer.
*
* @static
* @memberOf _
* @category Number
* @param {number} [min=0] The minimum possible value.
* @param {number} [max=1] The maximum possible value.
* @param {boolean} [floating] Specify returning a floating-point number.
* @returns {number} Returns the random number.
* @example
*
* _.random(0, 5);
* // => an integer between 0 and 5
*
* _.random(5);
* // => also an integer between 0 and 5
*
* _.random(5, true);
* // => a floating-point number between 0 and 5
*
* _.random(1.2, 5.2);
* // => a floating-point number between 1.2 and 5.2
*/
function random(min, max, floating) {
if (floating && isIterateeCall(min, max, floating)) {
max = floating = undefined;
}
var noMin = min == null,
noMax = max == null;
if (floating == null) {
if (noMax && typeof min == 'boolean') {
floating = min;
min = 1;
}
else if (typeof max == 'boolean') {
floating = max;
noMax = true;
}
}
if (noMin && noMax) {
max = 1;
noMax = false;
}
min = +min || 0;
if (noMax) {
max = min;
min = 0;
} else {
max = +max || 0;
}
if (floating || min % 1 || max % 1) {
var rand = nativeRandom();
return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand + '').length - 1)))), max);
}
return baseRandom(min, max);
}
/*------------------------------------------------------------------------*/
/**
* Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the camel cased string.
* @example
*
* _.camelCase('Foo Bar');
* // => 'fooBar'
*
* _.camelCase('--foo-bar');
* // => 'fooBar'
*
* _.camelCase('__foo_bar__');
* // => 'fooBar'
*/
var camelCase = createCompounder(function(result, word, index) {
word = word.toLowerCase();
return result + (index ? (word.charAt(0).toUpperCase() + word.slice(1)) : word);
});
/**
* Capitalizes the first character of `string`.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to capitalize.
* @returns {string} Returns the capitalized string.
* @example
*
* _.capitalize('fred');
* // => 'Fred'
*/
function capitalize(string) {
string = baseToString(string);
return string && (string.charAt(0).toUpperCase() + string.slice(1));
}
/**
* Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
* to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to deburr.
* @returns {string} Returns the deburred string.
* @example
*
* _.deburr('déjà vu');
* // => 'deja vu'
*/
function deburr(string) {
string = baseToString(string);
return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
}
/**
* Checks if `string` ends with the given target string.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to search.
* @param {string} [target] The string to search for.
* @param {number} [position=string.length] The position to search from.
* @returns {boolean} Returns `true` if `string` ends with `target`, else `false`.
* @example
*
* _.endsWith('abc', 'c');
* // => true
*
* _.endsWith('abc', 'b');
* // => false
*
* _.endsWith('abc', 'b', 2);
* // => true
*/
function endsWith(string, target, position) {
string = baseToString(string);
target = (target + '');
var length = string.length;
position = position === undefined
? length
: nativeMin(position < 0 ? 0 : (+position || 0), length);
position -= target.length;
return position >= 0 && string.indexOf(target, position) == position;
}
/**
* Converts the characters "&", "<", ">", '"', "'", and "\`", in `string` to
* their corresponding HTML entities.
*
* **Note:** No other characters are escaped. To escape additional characters
* use a third-party library like [_he_](https://mths.be/he).
*
* Though the ">" character is escaped for symmetry, characters like
* ">" and "/" don't need escaping in HTML and have no special meaning
* unless they're part of a tag or unquoted attribute value.
* See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
* (under "semi-related fun fact") for more details.
*
* Backticks are escaped because in Internet Explorer < 9, they can break out
* of attribute values or HTML comments. See [#59](https://html5sec.org/#59),
* [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
* [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
* for more details.
*
* When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
* to reduce XSS vectors.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to escape.
* @returns {string} Returns the escaped string.
* @example
*
* _.escape('fred, barney, & pebbles');
* // => 'fred, barney, & pebbles'
*/
function escape(string) {
// Reset `lastIndex` because in IE < 9 `String#replace` does not.
string = baseToString(string);
return (string && reHasUnescapedHtml.test(string))
? string.replace(reUnescapedHtml, escapeHtmlChar)
: string;
}
/**
* Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?",
* "*", "+", "(", ")", "[", "]", "{" and "}" in `string`.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to escape.
* @returns {string} Returns the escaped string.
* @example
*
* _.escapeRegExp('[lodash](https://lodash.com/)');
* // => '\[lodash\]\(https:\/\/lodash\.com\/\)'
*/
function escapeRegExp(string) {
string = baseToString(string);
return (string && reHasRegExpChars.test(string))
? string.replace(reRegExpChars, escapeRegExpChar)
: (string || '(?:)');
}
/**
* Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the kebab cased string.
* @example
*
* _.kebabCase('Foo Bar');
* // => 'foo-bar'
*
* _.kebabCase('fooBar');
* // => 'foo-bar'
*
* _.kebabCase('__foo_bar__');
* // => 'foo-bar'
*/
var kebabCase = createCompounder(function(result, word, index) {
return result + (index ? '-' : '') + word.toLowerCase();
});
/**
* Pads `string` on the left and right sides if it's shorter than `length`.
* Padding characters are truncated if they can't be evenly divided by `length`.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to pad.
* @param {number} [length=0] The padding length.
* @param {string} [chars=' '] The string used as padding.
* @returns {string} Returns the padded string.
* @example
*
* _.pad('abc', 8);
* // => ' abc '
*
* _.pad('abc', 8, '_-');
* // => '_-abc_-_'
*
* _.pad('abc', 3);
* // => 'abc'
*/
function pad(string, length, chars) {
string = baseToString(string);
length = +length;
var strLength = string.length;
if (strLength >= length || !nativeIsFinite(length)) {
return string;
}
var mid = (length - strLength) / 2,
leftLength = nativeFloor(mid),
rightLength = nativeCeil(mid);
chars = createPadding('', rightLength, chars);
return chars.slice(0, leftLength) + string + chars;
}
/**
* Pads `string` on the left side if it's shorter than `length`. Padding
* characters are truncated if they exceed `length`.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to pad.
* @param {number} [length=0] The padding length.
* @param {string} [chars=' '] The string used as padding.
* @returns {string} Returns the padded string.
* @example
*
* _.padLeft('abc', 6);
* // => ' abc'
*
* _.padLeft('abc', 6, '_-');
* // => '_-_abc'
*
* _.padLeft('abc', 3);
* // => 'abc'
*/
var padLeft = createPadDir();
/**
* Pads `string` on the right side if it's shorter than `length`. Padding
* characters are truncated if they exceed `length`.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to pad.
* @param {number} [length=0] The padding length.
* @param {string} [chars=' '] The string used as padding.
* @returns {string} Returns the padded string.
* @example
*
* _.padRight('abc', 6);
* // => 'abc '
*
* _.padRight('abc', 6, '_-');
* // => 'abc_-_'
*
* _.padRight('abc', 3);
* // => 'abc'
*/
var padRight = createPadDir(true);
/**
* Converts `string` to an integer of the specified radix. If `radix` is
* `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
* in which case a `radix` of `16` is used.
*
* **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#E)
* of `parseInt`.
*
* @static
* @memberOf _
* @category String
* @param {string} string The string to convert.
* @param {number} [radix] The radix to interpret `value` by.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {number} Returns the converted integer.
* @example
*
* _.parseInt('08');
* // => 8
*
* _.map(['6', '08', '10'], _.parseInt);
* // => [6, 8, 10]
*/
function parseInt(string, radix, guard) {
// Firefox < 21 and Opera < 15 follow ES3 for `parseInt`.
// Chrome fails to trim leading <BOM> whitespace characters.
// See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
if (guard ? isIterateeCall(string, radix, guard) : radix == null) {
radix = 0;
} else if (radix) {
radix = +radix;
}
string = trim(string);
return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
}
/**
* Repeats the given string `n` times.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to repeat.
* @param {number} [n=0] The number of times to repeat the string.
* @returns {string} Returns the repeated string.
* @example
*
* _.repeat('*', 3);
* // => '***'
*
* _.repeat('abc', 2);
* // => 'abcabc'
*
* _.repeat('abc', 0);
* // => ''
*/
function repeat(string, n) {
var result = '';
string = baseToString(string);
n = +n;
if (n < 1 || !string || !nativeIsFinite(n)) {
return result;
}
// Leverage the exponentiation by squaring algorithm for a faster repeat.
// See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
do {
if (n % 2) {
result += string;
}
n = nativeFloor(n / 2);
string += string;
} while (n);
return result;
}
/**
* Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case).
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the snake cased string.
* @example
*
* _.snakeCase('Foo Bar');
* // => 'foo_bar'
*
* _.snakeCase('fooBar');
* // => 'foo_bar'
*
* _.snakeCase('--foo-bar');
* // => 'foo_bar'
*/
var snakeCase = createCompounder(function(result, word, index) {
return result + (index ? '_' : '') + word.toLowerCase();
});
/**
* Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the start cased string.
* @example
*
* _.startCase('--foo-bar');
* // => 'Foo Bar'
*
* _.startCase('fooBar');
* // => 'Foo Bar'
*
* _.startCase('__foo_bar__');
* // => 'Foo Bar'
*/
var startCase = createCompounder(function(result, word, index) {
return result + (index ? ' ' : '') + (word.charAt(0).toUpperCase() + word.slice(1));
});
/**
* Checks if `string` starts with the given target string.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to search.
* @param {string} [target] The string to search for.
* @param {number} [position=0] The position to search from.
* @returns {boolean} Returns `true` if `string` starts with `target`, else `false`.
* @example
*
* _.startsWith('abc', 'a');
* // => true
*
* _.startsWith('abc', 'b');
* // => false
*
* _.startsWith('abc', 'b', 1);
* // => true
*/
function startsWith(string, target, position) {
string = baseToString(string);
position = position == null
? 0
: nativeMin(position < 0 ? 0 : (+position || 0), string.length);
return string.lastIndexOf(target, position) == position;
}
/**
* Creates a compiled template function that can interpolate data properties
* in "interpolate" delimiters, HTML-escape interpolated data properties in
* "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
* properties may be accessed as free variables in the template. If a setting
* object is provided it takes precedence over `_.templateSettings` values.
*
* **Note:** In the development build `_.template` utilizes
* [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
* for easier debugging.
*
* For more information on precompiling templates see
* [lodash's custom builds documentation](https://lodash.com/custom-builds).
*
* For more information on Chrome extension sandboxes see
* [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The template string.
* @param {Object} [options] The options object.
* @param {RegExp} [options.escape] The HTML "escape" delimiter.
* @param {RegExp} [options.evaluate] The "evaluate" delimiter.
* @param {Object} [options.imports] An object to import into the template as free variables.
* @param {RegExp} [options.interpolate] The "interpolate" delimiter.
* @param {string} [options.sourceURL] The sourceURL of the template's compiled source.
* @param {string} [options.variable] The data object variable name.
* @param- {Object} [otherOptions] Enables the legacy `options` param signature.
* @returns {Function} Returns the compiled template function.
* @example
*
* // using the "interpolate" delimiter to create a compiled template
* var compiled = _.template('hello <%= user %>!');
* compiled({ 'user': 'fred' });
* // => 'hello fred!'
*
* // using the HTML "escape" delimiter to escape data property values
* var compiled = _.template('<b><%- value %></b>');
* compiled({ 'value': '<script>' });
* // => '<b><script></b>'
*
* // using the "evaluate" delimiter to execute JavaScript and generate HTML
* var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
* compiled({ 'users': ['fred', 'barney'] });
* // => '<li>fred</li><li>barney</li>'
*
* // using the internal `print` function in "evaluate" delimiters
* var compiled = _.template('<% print("hello " + user); %>!');
* compiled({ 'user': 'barney' });
* // => 'hello barney!'
*
* // using the ES delimiter as an alternative to the default "interpolate" delimiter
* var compiled = _.template('hello ${ user }!');
* compiled({ 'user': 'pebbles' });
* // => 'hello pebbles!'
*
* // using custom template delimiters
* _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
* var compiled = _.template('hello {{ user }}!');
* compiled({ 'user': 'mustache' });
* // => 'hello mustache!'
*
* // using backslashes to treat delimiters as plain text
* var compiled = _.template('<%= "\\<%- value %\\>" %>');
* compiled({ 'value': 'ignored' });
* // => '<%- value %>'
*
* // using the `imports` option to import `jQuery` as `jq`
* var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
* var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
* compiled({ 'users': ['fred', 'barney'] });
* // => '<li>fred</li><li>barney</li>'
*
* // using the `sourceURL` option to specify a custom sourceURL for the template
* var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
* compiled(data);
* // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
*
* // using the `variable` option to ensure a with-statement isn't used in the compiled template
* var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
* compiled.source;
* // => function(data) {
* // var __t, __p = '';
* // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
* // return __p;
* // }
*
* // using the `source` property to inline compiled templates for meaningful
* // line numbers in error messages and a stack trace
* fs.writeFileSync(path.join(cwd, 'jst.js'), '\
* var JST = {\
* "main": ' + _.template(mainText).source + '\
* };\
* ');
*/
function template(string, options, otherOptions) {
// Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/)
// and Laura Doktorova's doT.js (https://github.com/olado/doT).
var settings = lodash.templateSettings;
if (otherOptions && isIterateeCall(string, options, otherOptions)) {
options = otherOptions = undefined;
}
string = baseToString(string);
options = assignWith(baseAssign({}, otherOptions || options), settings, assignOwnDefaults);
var imports = assignWith(baseAssign({}, options.imports), settings.imports, assignOwnDefaults),
importsKeys = keys(imports),
importsValues = baseValues(imports, importsKeys);
var isEscaping,
isEvaluating,
index = 0,
interpolate = options.interpolate || reNoMatch,
source = "__p += '";
// Compile the regexp to match each delimiter.
var reDelimiters = RegExp(
(options.escape || reNoMatch).source + '|' +
interpolate.source + '|' +
(interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
(options.evaluate || reNoMatch).source + '|$'
, 'g');
// Use a sourceURL for easier debugging.
var sourceURL = '//# sourceURL=' +
('sourceURL' in options
? options.sourceURL
: ('lodash.templateSources[' + (++templateCounter) + ']')
) + '\n';
string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
interpolateValue || (interpolateValue = esTemplateValue);
// Escape characters that can't be included in string literals.
source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
// Replace delimiters with snippets.
if (escapeValue) {
isEscaping = true;
source += "' +\n__e(" + escapeValue + ") +\n'";
}
if (evaluateValue) {
isEvaluating = true;
source += "';\n" + evaluateValue + ";\n__p += '";
}
if (interpolateValue) {
source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
}
index = offset + match.length;
// The JS engine embedded in Adobe products requires returning the `match`
// string in order to produce the correct `offset` value.
return match;
});
source += "';\n";
// If `variable` is not specified wrap a with-statement around the generated
// code to add the data object to the top of the scope chain.
var variable = options.variable;
if (!variable) {
source = 'with (obj) {\n' + source + '\n}\n';
}
// Cleanup code by stripping empty strings.
source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
.replace(reEmptyStringMiddle, '$1')
.replace(reEmptyStringTrailing, '$1;');
// Frame code as the function body.
source = 'function(' + (variable || 'obj') + ') {\n' +
(variable
? ''
: 'obj || (obj = {});\n'
) +
"var __t, __p = ''" +
(isEscaping
? ', __e = _.escape'
: ''
) +
(isEvaluating
? ', __j = Array.prototype.join;\n' +
"function print() { __p += __j.call(arguments, '') }\n"
: ';\n'
) +
source +
'return __p\n}';
var result = attempt(function() {
return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues);
});
// Provide the compiled function's source by its `toString` method or
// the `source` property as a convenience for inlining compiled templates.
result.source = source;
if (isError(result)) {
throw result;
}
return result;
}
/**
* Removes leading and trailing whitespace or specified characters from `string`.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to trim.
* @param {string} [chars=whitespace] The characters to trim.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {string} Returns the trimmed string.
* @example
*
* _.trim(' abc ');
* // => 'abc'
*
* _.trim('-_-abc-_-', '_-');
* // => 'abc'
*
* _.map([' foo ', ' bar '], _.trim);
* // => ['foo', 'bar']
*/
function trim(string, chars, guard) {
var value = string;
string = baseToString(string);
if (!string) {
return string;
}
if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1);
}
chars = (chars + '');
return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1);
}
/**
* Removes leading whitespace or specified characters from `string`.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to trim.
* @param {string} [chars=whitespace] The characters to trim.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {string} Returns the trimmed string.
* @example
*
* _.trimLeft(' abc ');
* // => 'abc '
*
* _.trimLeft('-_-abc-_-', '_-');
* // => 'abc-_-'
*/
function trimLeft(string, chars, guard) {
var value = string;
string = baseToString(string);
if (!string) {
return string;
}
if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
return string.slice(trimmedLeftIndex(string));
}
return string.slice(charsLeftIndex(string, (chars + '')));
}
/**
* Removes trailing whitespace or specified characters from `string`.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to trim.
* @param {string} [chars=whitespace] The characters to trim.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {string} Returns the trimmed string.
* @example
*
* _.trimRight(' abc ');
* // => ' abc'
*
* _.trimRight('-_-abc-_-', '_-');
* // => '-_-abc'
*/
function trimRight(string, chars, guard) {
var value = string;
string = baseToString(string);
if (!string) {
return string;
}
if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
return string.slice(0, trimmedRightIndex(string) + 1);
}
return string.slice(0, charsRightIndex(string, (chars + '')) + 1);
}
/**
* Truncates `string` if it's longer than the given maximum string length.
* The last characters of the truncated string are replaced with the omission
* string which defaults to "...".
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to truncate.
* @param {Object|number} [options] The options object or maximum string length.
* @param {number} [options.length=30] The maximum string length.
* @param {string} [options.omission='...'] The string to indicate text is omitted.
* @param {RegExp|string} [options.separator] The separator pattern to truncate to.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {string} Returns the truncated string.
* @example
*
* _.trunc('hi-diddly-ho there, neighborino');
* // => 'hi-diddly-ho there, neighbo...'
*
* _.trunc('hi-diddly-ho there, neighborino', 24);
* // => 'hi-diddly-ho there, n...'
*
* _.trunc('hi-diddly-ho there, neighborino', {
* 'length': 24,
* 'separator': ' '
* });
* // => 'hi-diddly-ho there,...'
*
* _.trunc('hi-diddly-ho there, neighborino', {
* 'length': 24,
* 'separator': /,? +/
* });
* // => 'hi-diddly-ho there...'
*
* _.trunc('hi-diddly-ho there, neighborino', {
* 'omission': ' [...]'
* });
* // => 'hi-diddly-ho there, neig [...]'
*/
function trunc(string, options, guard) {
if (guard && isIterateeCall(string, options, guard)) {
options = undefined;
}
var length = DEFAULT_TRUNC_LENGTH,
omission = DEFAULT_TRUNC_OMISSION;
if (options != null) {
if (isObject(options)) {
var separator = 'separator' in options ? options.separator : separator;
length = 'length' in options ? (+options.length || 0) : length;
omission = 'omission' in options ? baseToString(options.omission) : omission;
} else {
length = +options || 0;
}
}
string = baseToString(string);
if (length >= string.length) {
return string;
}
var end = length - omission.length;
if (end < 1) {
return omission;
}
var result = string.slice(0, end);
if (separator == null) {
return result + omission;
}
if (isRegExp(separator)) {
if (string.slice(end).search(separator)) {
var match,
newEnd,
substring = string.slice(0, end);
if (!separator.global) {
separator = RegExp(separator.source, (reFlags.exec(separator) || '') + 'g');
}
separator.lastIndex = 0;
while ((match = separator.exec(substring))) {
newEnd = match.index;
}
result = result.slice(0, newEnd == null ? end : newEnd);
}
} else if (string.indexOf(separator, end) != end) {
var index = result.lastIndexOf(separator);
if (index > -1) {
result = result.slice(0, index);
}
}
return result + omission;
}
/**
* The inverse of `_.escape`; this method converts the HTML entities
* `&`, `<`, `>`, `"`, `'`, and ``` in `string` to their
* corresponding characters.
*
* **Note:** No other HTML entities are unescaped. To unescape additional HTML
* entities use a third-party library like [_he_](https://mths.be/he).
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to unescape.
* @returns {string} Returns the unescaped string.
* @example
*
* _.unescape('fred, barney, & pebbles');
* // => 'fred, barney, & pebbles'
*/
function unescape(string) {
string = baseToString(string);
return (string && reHasEscapedHtml.test(string))
? string.replace(reEscapedHtml, unescapeHtmlChar)
: string;
}
/**
* Splits `string` into an array of its words.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to inspect.
* @param {RegExp|string} [pattern] The pattern to match words.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {Array} Returns the words of `string`.
* @example
*
* _.words('fred, barney, & pebbles');
* // => ['fred', 'barney', 'pebbles']
*
* _.words('fred, barney, & pebbles', /[^, ]+/g);
* // => ['fred', 'barney', '&', 'pebbles']
*/
function words(string, pattern, guard) {
if (guard && isIterateeCall(string, pattern, guard)) {
pattern = undefined;
}
string = baseToString(string);
return string.match(pattern || reWords) || [];
}
/*------------------------------------------------------------------------*/
/**
* Attempts to invoke `func`, returning either the result or the caught error
* object. Any additional arguments are provided to `func` when it is invoked.
*
* @static
* @memberOf _
* @category Utility
* @param {Function} func The function to attempt.
* @returns {*} Returns the `func` result or error object.
* @example
*
* // avoid throwing errors for invalid selectors
* var elements = _.attempt(function(selector) {
* return document.querySelectorAll(selector);
* }, '>_>');
*
* if (_.isError(elements)) {
* elements = [];
* }
*/
var attempt = restParam(function(func, args) {
try {
return func.apply(undefined, args);
} catch(e) {
return isError(e) ? e : new Error(e);
}
});
/**
* Creates a function that invokes `func` with the `this` binding of `thisArg`
* and arguments of the created function. If `func` is a property name the
* created callback returns the property value for a given element. If `func`
* is an object the created callback returns `true` for elements that contain
* the equivalent object properties, otherwise it returns `false`.
*
* @static
* @memberOf _
* @alias iteratee
* @category Utility
* @param {*} [func=_.identity] The value to convert to a callback.
* @param {*} [thisArg] The `this` binding of `func`.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {Function} Returns the callback.
* @example
*
* var users = [
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 40 }
* ];
*
* // wrap to create custom callback shorthands
* _.callback = _.wrap(_.callback, function(callback, func, thisArg) {
* var match = /^(.+?)__([gl]t)(.+)$/.exec(func);
* if (!match) {
* return callback(func, thisArg);
* }
* return function(object) {
* return match[2] == 'gt'
* ? object[match[1]] > match[3]
* : object[match[1]] < match[3];
* };
* });
*
* _.filter(users, 'age__gt36');
* // => [{ 'user': 'fred', 'age': 40 }]
*/
function callback(func, thisArg, guard) {
if (guard && isIterateeCall(func, thisArg, guard)) {
thisArg = undefined;
}
return isObjectLike(func)
? matches(func)
: baseCallback(func, thisArg);
}
/**
* Creates a function that returns `value`.
*
* @static
* @memberOf _
* @category Utility
* @param {*} value The value to return from the new function.
* @returns {Function} Returns the new function.
* @example
*
* var object = { 'user': 'fred' };
* var getter = _.constant(object);
*
* getter() === object;
* // => true
*/
function constant(value) {
return function() {
return value;
};
}
/**
* This method returns the first argument provided to it.
*
* @static
* @memberOf _
* @category Utility
* @param {*} value Any value.
* @returns {*} Returns `value`.
* @example
*
* var object = { 'user': 'fred' };
*
* _.identity(object) === object;
* // => true
*/
function identity(value) {
return value;
}
/**
* Creates a function that performs a deep comparison between a given object
* and `source`, returning `true` if the given object has equivalent property
* values, else `false`.
*
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
* numbers, `Object` objects, regexes, and strings. Objects are compared by
* their own, not inherited, enumerable properties. For comparing a single
* own or inherited property value see `_.matchesProperty`.
*
* @static
* @memberOf _
* @category Utility
* @param {Object} source The object of property values to match.
* @returns {Function} Returns the new function.
* @example
*
* var users = [
* { 'user': 'barney', 'age': 36, 'active': true },
* { 'user': 'fred', 'age': 40, 'active': false }
* ];
*
* _.filter(users, _.matches({ 'age': 40, 'active': false }));
* // => [{ 'user': 'fred', 'age': 40, 'active': false }]
*/
function matches(source) {
return baseMatches(baseClone(source, true));
}
/**
* Creates a function that compares the property value of `path` on a given
* object to `value`.
*
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
* numbers, `Object` objects, regexes, and strings. Objects are compared by
* their own, not inherited, enumerable properties.
*
* @static
* @memberOf _
* @category Utility
* @param {Array|string} path The path of the property to get.
* @param {*} srcValue The value to match.
* @returns {Function} Returns the new function.
* @example
*
* var users = [
* { 'user': 'barney' },
* { 'user': 'fred' }
* ];
*
* _.find(users, _.matchesProperty('user', 'fred'));
* // => { 'user': 'fred' }
*/
function matchesProperty(path, srcValue) {
return baseMatchesProperty(path, baseClone(srcValue, true));
}
/**
* Creates a function that invokes the method at `path` on a given object.
* Any additional arguments are provided to the invoked method.
*
* @static
* @memberOf _
* @category Utility
* @param {Array|string} path The path of the method to invoke.
* @param {...*} [args] The arguments to invoke the method with.
* @returns {Function} Returns the new function.
* @example
*
* var objects = [
* { 'a': { 'b': { 'c': _.constant(2) } } },
* { 'a': { 'b': { 'c': _.constant(1) } } }
* ];
*
* _.map(objects, _.method('a.b.c'));
* // => [2, 1]
*
* _.invoke(_.sortBy(objects, _.method(['a', 'b', 'c'])), 'a.b.c');
* // => [1, 2]
*/
var method = restParam(function(path, args) {
return function(object) {
return invokePath(object, path, args);
};
});
/**
* The opposite of `_.method`; this method creates a function that invokes
* the method at a given path on `object`. Any additional arguments are
* provided to the invoked method.
*
* @static
* @memberOf _
* @category Utility
* @param {Object} object The object to query.
* @param {...*} [args] The arguments to invoke the method with.
* @returns {Function} Returns the new function.
* @example
*
* var array = _.times(3, _.constant),
* object = { 'a': array, 'b': array, 'c': array };
*
* _.map(['a[2]', 'c[0]'], _.methodOf(object));
* // => [2, 0]
*
* _.map([['a', '2'], ['c', '0']], _.methodOf(object));
* // => [2, 0]
*/
var methodOf = restParam(function(object, args) {
return function(path) {
return invokePath(object, path, args);
};
});
/**
* Adds all own enumerable function properties of a source object to the
* destination object. If `object` is a function then methods are added to
* its prototype as well.
*
* **Note:** Use `_.runInContext` to create a pristine `lodash` function to
* avoid conflicts caused by modifying the original.
*
* @static
* @memberOf _
* @category Utility
* @param {Function|Object} [object=lodash] The destination object.
* @param {Object} source The object of functions to add.
* @param {Object} [options] The options object.
* @param {boolean} [options.chain=true] Specify whether the functions added
* are chainable.
* @returns {Function|Object} Returns `object`.
* @example
*
* function vowels(string) {
* return _.filter(string, function(v) {
* return /[aeiou]/i.test(v);
* });
* }
*
* _.mixin({ 'vowels': vowels });
* _.vowels('fred');
* // => ['e']
*
* _('fred').vowels().value();
* // => ['e']
*
* _.mixin({ 'vowels': vowels }, { 'chain': false });
* _('fred').vowels();
* // => ['e']
*/
function mixin(object, source, options) {
if (options == null) {
var isObj = isObject(source),
props = isObj ? keys(source) : undefined,
methodNames = (props && props.length) ? baseFunctions(source, props) : undefined;
if (!(methodNames ? methodNames.length : isObj)) {
methodNames = false;
options = source;
source = object;
object = this;
}
}
if (!methodNames) {
methodNames = baseFunctions(source, keys(source));
}
var chain = true,
index = -1,
isFunc = isFunction(object),
length = methodNames.length;
if (options === false) {
chain = false;
} else if (isObject(options) && 'chain' in options) {
chain = options.chain;
}
while (++index < length) {
var methodName = methodNames[index],
func = source[methodName];
object[methodName] = func;
if (isFunc) {
object.prototype[methodName] = (function(func) {
return function() {
var chainAll = this.__chain__;
if (chain || chainAll) {
var result = object(this.__wrapped__),
actions = result.__actions__ = arrayCopy(this.__actions__);
actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
result.__chain__ = chainAll;
return result;
}
return func.apply(object, arrayPush([this.value()], arguments));
};
}(func));
}
}
return object;
}
/**
* Reverts the `_` variable to its previous value and returns a reference to
* the `lodash` function.
*
* @static
* @memberOf _
* @category Utility
* @returns {Function} Returns the `lodash` function.
* @example
*
* var lodash = _.noConflict();
*/
function noConflict() {
root._ = oldDash;
return this;
}
/**
* A no-operation function that returns `undefined` regardless of the
* arguments it receives.
*
* @static
* @memberOf _
* @category Utility
* @example
*
* var object = { 'user': 'fred' };
*
* _.noop(object) === undefined;
* // => true
*/
function noop() {
// No operation performed.
}
/**
* Creates a function that returns the property value at `path` on a
* given object.
*
* @static
* @memberOf _
* @category Utility
* @param {Array|string} path The path of the property to get.
* @returns {Function} Returns the new function.
* @example
*
* var objects = [
* { 'a': { 'b': { 'c': 2 } } },
* { 'a': { 'b': { 'c': 1 } } }
* ];
*
* _.map(objects, _.property('a.b.c'));
* // => [2, 1]
*
* _.pluck(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
* // => [1, 2]
*/
function property(path) {
return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
}
/**
* The opposite of `_.property`; this method creates a function that returns
* the property value at a given path on `object`.
*
* @static
* @memberOf _
* @category Utility
* @param {Object} object The object to query.
* @returns {Function} Returns the new function.
* @example
*
* var array = [0, 1, 2],
* object = { 'a': array, 'b': array, 'c': array };
*
* _.map(['a[2]', 'c[0]'], _.propertyOf(object));
* // => [2, 0]
*
* _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
* // => [2, 0]
*/
function propertyOf(object) {
return function(path) {
return baseGet(object, toPath(path), path + '');
};
}
/**
* Creates an array of numbers (positive and/or negative) progressing from
* `start` up to, but not including, `end`. If `end` is not specified it is
* set to `start` with `start` then set to `0`. If `end` is less than `start`
* a zero-length range is created unless a negative `step` is specified.
*
* @static
* @memberOf _
* @category Utility
* @param {number} [start=0] The start of the range.
* @param {number} end The end of the range.
* @param {number} [step=1] The value to increment or decrement by.
* @returns {Array} Returns the new array of numbers.
* @example
*
* _.range(4);
* // => [0, 1, 2, 3]
*
* _.range(1, 5);
* // => [1, 2, 3, 4]
*
* _.range(0, 20, 5);
* // => [0, 5, 10, 15]
*
* _.range(0, -4, -1);
* // => [0, -1, -2, -3]
*
* _.range(1, 4, 0);
* // => [1, 1, 1]
*
* _.range(0);
* // => []
*/
function range(start, end, step) {
if (step && isIterateeCall(start, end, step)) {
end = step = undefined;
}
start = +start || 0;
step = step == null ? 1 : (+step || 0);
if (end == null) {
end = start;
start = 0;
} else {
end = +end || 0;
}
// Use `Array(length)` so engines like Chakra and V8 avoid slower modes.
// See https://youtu.be/XAqIpGU8ZZk#t=17m25s for more details.
var index = -1,
length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
result = Array(length);
while (++index < length) {
result[index] = start;
start += step;
}
return result;
}
/**
* Invokes the iteratee function `n` times, returning an array of the results
* of each invocation. The `iteratee` is bound to `thisArg` and invoked with
* one argument; (index).
*
* @static
* @memberOf _
* @category Utility
* @param {number} n The number of times to invoke `iteratee`.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the array of results.
* @example
*
* var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));
* // => [3, 6, 4]
*
* _.times(3, function(n) {
* mage.castSpell(n);
* });
* // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2`
*
* _.times(3, function(n) {
* this.cast(n);
* }, mage);
* // => also invokes `mage.castSpell(n)` three times
*/
function times(n, iteratee, thisArg) {
n = nativeFloor(n);
// Exit early to avoid a JSC JIT bug in Safari 8
// where `Array(0)` is treated as `Array(1)`.
if (n < 1 || !nativeIsFinite(n)) {
return [];
}
var index = -1,
result = Array(nativeMin(n, MAX_ARRAY_LENGTH));
iteratee = bindCallback(iteratee, thisArg, 1);
while (++index < n) {
if (index < MAX_ARRAY_LENGTH) {
result[index] = iteratee(index);
} else {
iteratee(index);
}
}
return result;
}
/**
* Generates a unique ID. If `prefix` is provided the ID is appended to it.
*
* @static
* @memberOf _
* @category Utility
* @param {string} [prefix] The value to prefix the ID with.
* @returns {string} Returns the unique ID.
* @example
*
* _.uniqueId('contact_');
* // => 'contact_104'
*
* _.uniqueId();
* // => '105'
*/
function uniqueId(prefix) {
var id = ++idCounter;
return baseToString(prefix) + id;
}
/*------------------------------------------------------------------------*/
/**
* Adds two numbers.
*
* @static
* @memberOf _
* @category Math
* @param {number} augend The first number to add.
* @param {number} addend The second number to add.
* @returns {number} Returns the sum.
* @example
*
* _.add(6, 4);
* // => 10
*/
function add(augend, addend) {
return (+augend || 0) + (+addend || 0);
}
/**
* Calculates `n` rounded up to `precision`.
*
* @static
* @memberOf _
* @category Math
* @param {number} n The number to round up.
* @param {number} [precision=0] The precision to round up to.
* @returns {number} Returns the rounded up number.
* @example
*
* _.ceil(4.006);
* // => 5
*
* _.ceil(6.004, 2);
* // => 6.01
*
* _.ceil(6040, -2);
* // => 6100
*/
var ceil = createRound('ceil');
/**
* Calculates `n` rounded down to `precision`.
*
* @static
* @memberOf _
* @category Math
* @param {number} n The number to round down.
* @param {number} [precision=0] The precision to round down to.
* @returns {number} Returns the rounded down number.
* @example
*
* _.floor(4.006);
* // => 4
*
* _.floor(0.046, 2);
* // => 0.04
*
* _.floor(4060, -2);
* // => 4000
*/
var floor = createRound('floor');
/**
* Gets the maximum value of `collection`. If `collection` is empty or falsey
* `-Infinity` is returned. If an iteratee function is provided it is invoked
* for each value in `collection` to generate the criterion by which the value
* is ranked. The `iteratee` is bound to `thisArg` and invoked with three
* arguments: (value, index, collection).
*
* If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Math
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee] The function invoked per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {*} Returns the maximum value.
* @example
*
* _.max([4, 2, 8, 6]);
* // => 8
*
* _.max([]);
* // => -Infinity
*
* var users = [
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 40 }
* ];
*
* _.max(users, function(chr) {
* return chr.age;
* });
* // => { 'user': 'fred', 'age': 40 }
*
* // using the `_.property` callback shorthand
* _.max(users, 'age');
* // => { 'user': 'fred', 'age': 40 }
*/
var max = createExtremum(gt, NEGATIVE_INFINITY);
/**
* Gets the minimum value of `collection`. If `collection` is empty or falsey
* `Infinity` is returned. If an iteratee function is provided it is invoked
* for each value in `collection` to generate the criterion by which the value
* is ranked. The `iteratee` is bound to `thisArg` and invoked with three
* arguments: (value, index, collection).
*
* If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Math
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee] The function invoked per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {*} Returns the minimum value.
* @example
*
* _.min([4, 2, 8, 6]);
* // => 2
*
* _.min([]);
* // => Infinity
*
* var users = [
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 40 }
* ];
*
* _.min(users, function(chr) {
* return chr.age;
* });
* // => { 'user': 'barney', 'age': 36 }
*
* // using the `_.property` callback shorthand
* _.min(users, 'age');
* // => { 'user': 'barney', 'age': 36 }
*/
var min = createExtremum(lt, POSITIVE_INFINITY);
/**
* Calculates `n` rounded to `precision`.
*
* @static
* @memberOf _
* @category Math
* @param {number} n The number to round.
* @param {number} [precision=0] The precision to round to.
* @returns {number} Returns the rounded number.
* @example
*
* _.round(4.006);
* // => 4
*
* _.round(4.006, 2);
* // => 4.01
*
* _.round(4060, -2);
* // => 4100
*/
var round = createRound('round');
/**
* Gets the sum of the values in `collection`.
*
* @static
* @memberOf _
* @category Math
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee] The function invoked per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {number} Returns the sum.
* @example
*
* _.sum([4, 6]);
* // => 10
*
* _.sum({ 'a': 4, 'b': 6 });
* // => 10
*
* var objects = [
* { 'n': 4 },
* { 'n': 6 }
* ];
*
* _.sum(objects, function(object) {
* return object.n;
* });
* // => 10
*
* // using the `_.property` callback shorthand
* _.sum(objects, 'n');
* // => 10
*/
function sum(collection, iteratee, thisArg) {
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
iteratee = undefined;
}
iteratee = getCallback(iteratee, thisArg, 3);
return iteratee.length == 1
? arraySum(isArray(collection) ? collection : toIterable(collection), iteratee)
: baseSum(collection, iteratee);
}
/*------------------------------------------------------------------------*/
// Ensure wrappers are instances of `baseLodash`.
lodash.prototype = baseLodash.prototype;
LodashWrapper.prototype = baseCreate(baseLodash.prototype);
LodashWrapper.prototype.constructor = LodashWrapper;
LazyWrapper.prototype = baseCreate(baseLodash.prototype);
LazyWrapper.prototype.constructor = LazyWrapper;
// Add functions to the `Map` cache.
MapCache.prototype['delete'] = mapDelete;
MapCache.prototype.get = mapGet;
MapCache.prototype.has = mapHas;
MapCache.prototype.set = mapSet;
// Add functions to the `Set` cache.
SetCache.prototype.push = cachePush;
// Assign cache to `_.memoize`.
memoize.Cache = MapCache;
// Add functions that return wrapped values when chaining.
lodash.after = after;
lodash.ary = ary;
lodash.assign = assign;
lodash.at = at;
lodash.before = before;
lodash.bind = bind;
lodash.bindAll = bindAll;
lodash.bindKey = bindKey;
lodash.callback = callback;
lodash.chain = chain;
lodash.chunk = chunk;
lodash.compact = compact;
lodash.constant = constant;
lodash.countBy = countBy;
lodash.create = create;
lodash.curry = curry;
lodash.curryRight = curryRight;
lodash.debounce = debounce;
lodash.defaults = defaults;
lodash.defaultsDeep = defaultsDeep;
lodash.defer = defer;
lodash.delay = delay;
lodash.difference = difference;
lodash.drop = drop;
lodash.dropRight = dropRight;
lodash.dropRightWhile = dropRightWhile;
lodash.dropWhile = dropWhile;
lodash.fill = fill;
lodash.filter = filter;
lodash.flatten = flatten;
lodash.flattenDeep = flattenDeep;
lodash.flow = flow;
lodash.flowRight = flowRight;
lodash.forEach = forEach;
lodash.forEachRight = forEachRight;
lodash.forIn = forIn;
lodash.forInRight = forInRight;
lodash.forOwn = forOwn;
lodash.forOwnRight = forOwnRight;
lodash.functions = functions;
lodash.groupBy = groupBy;
lodash.indexBy = indexBy;
lodash.initial = initial;
lodash.intersection = intersection;
lodash.invert = invert;
lodash.invoke = invoke;
lodash.keys = keys;
lodash.keysIn = keysIn;
lodash.map = map;
lodash.mapKeys = mapKeys;
lodash.mapValues = mapValues;
lodash.matches = matches;
lodash.matchesProperty = matchesProperty;
lodash.memoize = memoize;
lodash.merge = merge;
lodash.method = method;
lodash.methodOf = methodOf;
lodash.mixin = mixin;
lodash.modArgs = modArgs;
lodash.negate = negate;
lodash.omit = omit;
lodash.once = once;
lodash.pairs = pairs;
lodash.partial = partial;
lodash.partialRight = partialRight;
lodash.partition = partition;
lodash.pick = pick;
lodash.pluck = pluck;
lodash.property = property;
lodash.propertyOf = propertyOf;
lodash.pull = pull;
lodash.pullAt = pullAt;
lodash.range = range;
lodash.rearg = rearg;
lodash.reject = reject;
lodash.remove = remove;
lodash.rest = rest;
lodash.restParam = restParam;
lodash.set = set;
lodash.shuffle = shuffle;
lodash.slice = slice;
lodash.sortBy = sortBy;
lodash.sortByAll = sortByAll;
lodash.sortByOrder = sortByOrder;
lodash.spread = spread;
lodash.take = take;
lodash.takeRight = takeRight;
lodash.takeRightWhile = takeRightWhile;
lodash.takeWhile = takeWhile;
lodash.tap = tap;
lodash.throttle = throttle;
lodash.thru = thru;
lodash.times = times;
lodash.toArray = toArray;
lodash.toPlainObject = toPlainObject;
lodash.transform = transform;
lodash.union = union;
lodash.uniq = uniq;
lodash.unzip = unzip;
lodash.unzipWith = unzipWith;
lodash.values = values;
lodash.valuesIn = valuesIn;
lodash.where = where;
lodash.without = without;
lodash.wrap = wrap;
lodash.xor = xor;
lodash.zip = zip;
lodash.zipObject = zipObject;
lodash.zipWith = zipWith;
// Add aliases.
lodash.backflow = flowRight;
lodash.collect = map;
lodash.compose = flowRight;
lodash.each = forEach;
lodash.eachRight = forEachRight;
lodash.extend = assign;
lodash.iteratee = callback;
lodash.methods = functions;
lodash.object = zipObject;
lodash.select = filter;
lodash.tail = rest;
lodash.unique = uniq;
// Add functions to `lodash.prototype`.
mixin(lodash, lodash);
/*------------------------------------------------------------------------*/
// Add functions that return unwrapped values when chaining.
lodash.add = add;
lodash.attempt = attempt;
lodash.camelCase = camelCase;
lodash.capitalize = capitalize;
lodash.ceil = ceil;
lodash.clone = clone;
lodash.cloneDeep = cloneDeep;
lodash.deburr = deburr;
lodash.endsWith = endsWith;
lodash.escape = escape;
lodash.escapeRegExp = escapeRegExp;
lodash.every = every;
lodash.find = find;
lodash.findIndex = findIndex;
lodash.findKey = findKey;
lodash.findLast = findLast;
lodash.findLastIndex = findLastIndex;
lodash.findLastKey = findLastKey;
lodash.findWhere = findWhere;
lodash.first = first;
lodash.floor = floor;
lodash.get = get;
lodash.gt = gt;
lodash.gte = gte;
lodash.has = has;
lodash.identity = identity;
lodash.includes = includes;
lodash.indexOf = indexOf;
lodash.inRange = inRange;
lodash.isArguments = isArguments;
lodash.isArray = isArray;
lodash.isBoolean = isBoolean;
lodash.isDate = isDate;
lodash.isElement = isElement;
lodash.isEmpty = isEmpty;
lodash.isEqual = isEqual;
lodash.isError = isError;
lodash.isFinite = isFinite;
lodash.isFunction = isFunction;
lodash.isMatch = isMatch;
lodash.isNaN = isNaN;
lodash.isNative = isNative;
lodash.isNull = isNull;
lodash.isNumber = isNumber;
lodash.isObject = isObject;
lodash.isPlainObject = isPlainObject;
lodash.isRegExp = isRegExp;
lodash.isString = isString;
lodash.isTypedArray = isTypedArray;
lodash.isUndefined = isUndefined;
lodash.kebabCase = kebabCase;
lodash.last = last;
lodash.lastIndexOf = lastIndexOf;
lodash.lt = lt;
lodash.lte = lte;
lodash.max = max;
lodash.min = min;
lodash.noConflict = noConflict;
lodash.noop = noop;
lodash.now = now;
lodash.pad = pad;
lodash.padLeft = padLeft;
lodash.padRight = padRight;
lodash.parseInt = parseInt;
lodash.random = random;
lodash.reduce = reduce;
lodash.reduceRight = reduceRight;
lodash.repeat = repeat;
lodash.result = result;
lodash.round = round;
lodash.runInContext = runInContext;
lodash.size = size;
lodash.snakeCase = snakeCase;
lodash.some = some;
lodash.sortedIndex = sortedIndex;
lodash.sortedLastIndex = sortedLastIndex;
lodash.startCase = startCase;
lodash.startsWith = startsWith;
lodash.sum = sum;
lodash.template = template;
lodash.trim = trim;
lodash.trimLeft = trimLeft;
lodash.trimRight = trimRight;
lodash.trunc = trunc;
lodash.unescape = unescape;
lodash.uniqueId = uniqueId;
lodash.words = words;
// Add aliases.
lodash.all = every;
lodash.any = some;
lodash.contains = includes;
lodash.eq = isEqual;
lodash.detect = find;
lodash.foldl = reduce;
lodash.foldr = reduceRight;
lodash.head = first;
lodash.include = includes;
lodash.inject = reduce;
mixin(lodash, (function() {
var source = {};
baseForOwn(lodash, function(func, methodName) {
if (!lodash.prototype[methodName]) {
source[methodName] = func;
}
});
return source;
}()), false);
/*------------------------------------------------------------------------*/
// Add functions capable of returning wrapped and unwrapped values when chaining.
lodash.sample = sample;
lodash.prototype.sample = function(n) {
if (!this.__chain__ && n == null) {
return sample(this.value());
}
return this.thru(function(value) {
return sample(value, n);
});
};
/*------------------------------------------------------------------------*/
/**
* The semantic version number.
*
* @static
* @memberOf _
* @type string
*/
lodash.VERSION = VERSION;
// Assign default placeholders.
arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
lodash[methodName].placeholder = lodash;
});
// Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
arrayEach(['drop', 'take'], function(methodName, index) {
LazyWrapper.prototype[methodName] = function(n) {
var filtered = this.__filtered__;
if (filtered && !index) {
return new LazyWrapper(this);
}
n = n == null ? 1 : nativeMax(nativeFloor(n) || 0, 0);
var result = this.clone();
if (filtered) {
result.__takeCount__ = nativeMin(result.__takeCount__, n);
} else {
result.__views__.push({ 'size': n, 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') });
}
return result;
};
LazyWrapper.prototype[methodName + 'Right'] = function(n) {
return this.reverse()[methodName](n).reverse();
};
});
// Add `LazyWrapper` methods that accept an `iteratee` value.
arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
var type = index + 1,
isFilter = type != LAZY_MAP_FLAG;
LazyWrapper.prototype[methodName] = function(iteratee, thisArg) {
var result = this.clone();
result.__iteratees__.push({ 'iteratee': getCallback(iteratee, thisArg, 1), 'type': type });
result.__filtered__ = result.__filtered__ || isFilter;
return result;
};
});
// Add `LazyWrapper` methods for `_.first` and `_.last`.
arrayEach(['first', 'last'], function(methodName, index) {
var takeName = 'take' + (index ? 'Right' : '');
LazyWrapper.prototype[methodName] = function() {
return this[takeName](1).value()[0];
};
});
// Add `LazyWrapper` methods for `_.initial` and `_.rest`.
arrayEach(['initial', 'rest'], function(methodName, index) {
var dropName = 'drop' + (index ? '' : 'Right');
LazyWrapper.prototype[methodName] = function() {
return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
};
});
// Add `LazyWrapper` methods for `_.pluck` and `_.where`.
arrayEach(['pluck', 'where'], function(methodName, index) {
var operationName = index ? 'filter' : 'map',
createCallback = index ? baseMatches : property;
LazyWrapper.prototype[methodName] = function(value) {
return this[operationName](createCallback(value));
};
});
LazyWrapper.prototype.compact = function() {
return this.filter(identity);
};
LazyWrapper.prototype.reject = function(predicate, thisArg) {
predicate = getCallback(predicate, thisArg, 1);
return this.filter(function(value) {
return !predicate(value);
});
};
LazyWrapper.prototype.slice = function(start, end) {
start = start == null ? 0 : (+start || 0);
var result = this;
if (result.__filtered__ && (start > 0 || end < 0)) {
return new LazyWrapper(result);
}
if (start < 0) {
result = result.takeRight(-start);
} else if (start) {
result = result.drop(start);
}
if (end !== undefined) {
end = (+end || 0);
result = end < 0 ? result.dropRight(-end) : result.take(end - start);
}
return result;
};
LazyWrapper.prototype.takeRightWhile = function(predicate, thisArg) {
return this.reverse().takeWhile(predicate, thisArg).reverse();
};
LazyWrapper.prototype.toArray = function() {
return this.take(POSITIVE_INFINITY);
};
// Add `LazyWrapper` methods to `lodash.prototype`.
baseForOwn(LazyWrapper.prototype, function(func, methodName) {
var checkIteratee = /^(?:filter|map|reject)|While$/.test(methodName),
retUnwrapped = /^(?:first|last)$/.test(methodName),
lodashFunc = lodash[retUnwrapped ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName];
if (!lodashFunc) {
return;
}
lodash.prototype[methodName] = function() {
var args = retUnwrapped ? [1] : arguments,
chainAll = this.__chain__,
value = this.__wrapped__,
isHybrid = !!this.__actions__.length,
isLazy = value instanceof LazyWrapper,
iteratee = args[0],
useLazy = isLazy || isArray(value);
if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
// Avoid lazy use if the iteratee has a "length" value other than `1`.
isLazy = useLazy = false;
}
var interceptor = function(value) {
return (retUnwrapped && chainAll)
? lodashFunc(value, 1)[0]
: lodashFunc.apply(undefined, arrayPush([value], args));
};
var action = { 'func': thru, 'args': [interceptor], 'thisArg': undefined },
onlyLazy = isLazy && !isHybrid;
if (retUnwrapped && !chainAll) {
if (onlyLazy) {
value = value.clone();
value.__actions__.push(action);
return func.call(value);
}
return lodashFunc.call(undefined, this.value())[0];
}
if (!retUnwrapped && useLazy) {
value = onlyLazy ? value : new LazyWrapper(this);
var result = func.apply(value, args);
result.__actions__.push(action);
return new LodashWrapper(result, chainAll);
}
return this.thru(interceptor);
};
});
// Add `Array` and `String` methods to `lodash.prototype`.
arrayEach(['join', 'pop', 'push', 'replace', 'shift', 'sort', 'splice', 'split', 'unshift'], function(methodName) {
var func = (/^(?:replace|split)$/.test(methodName) ? stringProto : arrayProto)[methodName],
chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
retUnwrapped = /^(?:join|pop|replace|shift)$/.test(methodName);
lodash.prototype[methodName] = function() {
var args = arguments;
if (retUnwrapped && !this.__chain__) {
return func.apply(this.value(), args);
}
return this[chainName](function(value) {
return func.apply(value, args);
});
};
});
// Map minified function names to their real names.
baseForOwn(LazyWrapper.prototype, function(func, methodName) {
var lodashFunc = lodash[methodName];
if (lodashFunc) {
var key = lodashFunc.name,
names = realNames[key] || (realNames[key] = []);
names.push({ 'name': methodName, 'func': lodashFunc });
}
});
realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{ 'name': 'wrapper', 'func': undefined }];
// Add functions to the lazy wrapper.
LazyWrapper.prototype.clone = lazyClone;
LazyWrapper.prototype.reverse = lazyReverse;
LazyWrapper.prototype.value = lazyValue;
// Add chaining functions to the `lodash` wrapper.
lodash.prototype.chain = wrapperChain;
lodash.prototype.commit = wrapperCommit;
lodash.prototype.concat = wrapperConcat;
lodash.prototype.plant = wrapperPlant;
lodash.prototype.reverse = wrapperReverse;
lodash.prototype.toString = wrapperToString;
lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
// Add function aliases to the `lodash` wrapper.
lodash.prototype.collect = lodash.prototype.map;
lodash.prototype.head = lodash.prototype.first;
lodash.prototype.select = lodash.prototype.filter;
lodash.prototype.tail = lodash.prototype.rest;
return lodash;
}
/*--------------------------------------------------------------------------*/
// Export lodash.
var _ = runInContext();
// Some AMD build optimizers like r.js check for condition patterns like the following:
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
// Expose lodash to the global object when an AMD loader is present to avoid
// errors in cases where lodash is loaded by a script tag and not intended
// as an AMD module. See http://requirejs.org/docs/errors.html#mismatch for
// more details.
root._ = _;
// Define as an anonymous module so, through path mapping, it can be
// referenced as the "underscore" module.
define(function() {
return _;
});
}
// Check for `exports` after `define` in case a build optimizer adds an `exports` object.
else if (freeExports && freeModule) {
// Export for Node.js or RingoJS.
if (moduleExports) {
(freeModule.exports = _)._ = _;
}
// Export for Rhino with CommonJS support.
else {
freeExports._ = _;
}
}
else {
// Export for a browser or Rhino.
root._ = _;
}
}.call(this));
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],21:[function(require,module,exports){
module.exports = require('./lib/retry');
},{"./lib/retry":22}],22:[function(require,module,exports){
var RetryOperation = require('./retry_operation');
exports.operation = function(options) {
var retryForever = false;
if (options && options.forever === true) retryForever = true;
var timeouts = exports.timeouts(options);
return new RetryOperation(timeouts, retryForever);
};
exports.timeouts = function(options) {
if (options instanceof Array) {
return [].concat(options);
}
var opts = {
retries: 10,
factor: 2,
minTimeout: 1 * 1000,
maxTimeout: Infinity,
randomize: false
};
for (var key in options) {
opts[key] = options[key];
}
if (opts.minTimeout > opts.maxTimeout) {
throw new Error('minTimeout is greater than maxTimeout');
}
var timeouts = [];
for (var i = 0; i < opts.retries; i++) {
timeouts.push(this.createTimeout(i, opts));
}
// sort the array numerically ascending
timeouts.sort(function(a,b) {
return a - b;
});
return timeouts;
};
exports.createTimeout = function(attempt, opts) {
var random = (opts.randomize)
? (Math.random() + 1)
: 1;
var timeout = Math.round(random * opts.minTimeout * Math.pow(opts.factor, attempt));
timeout = Math.min(timeout, opts.maxTimeout);
return timeout;
};
exports.wrap = function(obj, options, methods) {
if (options instanceof Array) {
methods = options;
options = null;
}
if (!methods) {
methods = [];
for (var key in obj) {
if (typeof obj[key] === 'function') {
methods.push(key);
}
}
}
for (var i = 0; i < methods.length; i++) {
var method = methods[i];
var original = obj[method];
obj[method] = function retryWrapper() {
var op = exports.operation(options);
var args = Array.prototype.slice.call(arguments);
var callback = args.pop();
args.push(function(err) {
if (op.retry(err)) {
return;
}
if (err) {
arguments[0] = op.mainError();
}
callback.apply(this, arguments);
});
op.attempt(function() {
original.apply(obj, args);
});
};
obj[method].options = options;
}
};
},{"./retry_operation":23}],23:[function(require,module,exports){
function RetryOperation(timeouts, retryForever) {
this._timeouts = timeouts;
this._fn = null;
this._errors = [];
this._attempts = 1;
this._operationTimeout = null;
this._operationTimeoutCb = null;
this._timeout = null;
if (!!retryForever) {
this._cachedTimeouts = this._timeouts.slice(0);
}
}
module.exports = RetryOperation;
RetryOperation.prototype.retry = function(err) {
if (this._timeout) {
clearTimeout(this._timeout);
}
if (!err) {
return false;
}
this._errors.push(err);
var timeout = this._timeouts.shift();
if (timeout === undefined) {
if (this._cachedTimeouts) {
// retry forever, only keep last error
this._errors.splice(this._errors.length - 1, this._errors.length);
this._timeouts = this._cachedTimeouts.slice(0);
timeout = this._timeouts.shift();
} else {
return false;
}
}
var self = this;
setTimeout(function() {
self._attempts++;
if (self._operationTimeoutCb) {
self._timeout = setTimeout(function() {
self._operationTimeoutCb(self._attempts);
}, self._operationTimeout);
}
self._fn(self._attempts);
}, timeout);
return true;
};
RetryOperation.prototype.attempt = function(fn, timeoutOps) {
this._fn = fn;
if (timeoutOps) {
if (timeoutOps.timeout) {
this._operationTimeout = timeoutOps.timeout;
}
if (timeoutOps.cb) {
this._operationTimeoutCb = timeoutOps.cb;
}
}
var self = this;
if (this._operationTimeoutCb) {
this._timeout = setTimeout(function() {
self._operationTimeoutCb();
}, self._operationTimeout);
}
this._fn(this._attempts);
};
RetryOperation.prototype.try = function(fn) {
console.log('Using RetryOperation.try() is deprecated');
this.attempt(fn);
};
RetryOperation.prototype.start = function(fn) {
console.log('Using RetryOperation.start() is deprecated');
this.attempt(fn);
};
RetryOperation.prototype.start = RetryOperation.prototype.try;
RetryOperation.prototype.errors = function() {
return this._errors;
};
RetryOperation.prototype.attempts = function() {
return this._attempts;
};
RetryOperation.prototype.mainError = function() {
if (this._errors.length === 0) {
return null;
}
var counts = {};
var mainError = null;
var mainErrorCount = 0;
for (var i = 0; i < this._errors.length; i++) {
var error = this._errors[i];
var message = error.message;
var count = (counts[message] || 0) + 1;
counts[message] = count;
if (count >= mainErrorCount) {
mainError = error;
mainErrorCount = count;
}
}
return mainError;
};
},{}],24:[function(require,module,exports){
function normalize (str) {
return str
.replace(/[\/]+/g, '/')
.replace(/\/\?/g, '?')
.replace(/\/\#/g, '#')
.replace(/\:\//g, '://');
}
module.exports = function () {
var joined = [].slice.call(arguments, 0).join('/');
return normalize(joined);
};
},{}],25:[function(require,module,exports){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
function EventEmitter() {
this._events = this._events || {};
this._maxListeners = this._maxListeners || undefined;
}
module.exports = EventEmitter;
// Backwards-compat with node 0.10.x
EventEmitter.EventEmitter = EventEmitter;
EventEmitter.prototype._events = undefined;
EventEmitter.prototype._maxListeners = undefined;
// By default EventEmitters will print a warning if more than 10 listeners are
// added to it. This is a useful default which helps finding memory leaks.
EventEmitter.defaultMaxListeners = 10;
// Obviously not all Emitters should be limited to 10. This function allows
// that to be increased. Set to zero for unlimited.
EventEmitter.prototype.setMaxListeners = function(n) {
if (!isNumber(n) || n < 0 || isNaN(n))
throw TypeError('n must be a positive number');
this._maxListeners = n;
return this;
};
EventEmitter.prototype.emit = function(type) {
var er, handler, len, args, i, listeners;
if (!this._events)
this._events = {};
// If there is no 'error' event listener then throw.
if (type === 'error') {
if (!this._events.error ||
(isObject(this._events.error) && !this._events.error.length)) {
er = arguments[1];
if (er instanceof Error) {
throw er; // Unhandled 'error' event
}
throw TypeError('Uncaught, unspecified "error" event.');
}
}
handler = this._events[type];
if (isUndefined(handler))
return false;
if (isFunction(handler)) {
switch (arguments.length) {
// fast cases
case 1:
handler.call(this);
break;
case 2:
handler.call(this, arguments[1]);
break;
case 3:
handler.call(this, arguments[1], arguments[2]);
break;
// slower
default:
args = Array.prototype.slice.call(arguments, 1);
handler.apply(this, args);
}
} else if (isObject(handler)) {
args = Array.prototype.slice.call(arguments, 1);
listeners = handler.slice();
len = listeners.length;
for (i = 0; i < len; i++)
listeners[i].apply(this, args);
}
return true;
};
EventEmitter.prototype.addListener = function(type, listener) {
var m;
if (!isFunction(listener))
throw TypeError('listener must be a function');
if (!this._events)
this._events = {};
// To avoid recursion in the case that type === "newListener"! Before
// adding it to the listeners, first emit "newListener".
if (this._events.newListener)
this.emit('newListener', type,
isFunction(listener.listener) ?
listener.listener : listener);
if (!this._events[type])
// Optimize the case of one listener. Don't need the extra array object.
this._events[type] = listener;
else if (isObject(this._events[type]))
// If we've already got an array, just append.
this._events[type].push(listener);
else
// Adding the second element, need to change to array.
this._events[type] = [this._events[type], listener];
// Check for listener leak
if (isObject(this._events[type]) && !this._events[type].warned) {
if (!isUndefined(this._maxListeners)) {
m = this._maxListeners;
} else {
m = EventEmitter.defaultMaxListeners;
}
if (m && m > 0 && this._events[type].length > m) {
this._events[type].warned = true;
console.error('(node) warning: possible EventEmitter memory ' +
'leak detected. %d listeners added. ' +
'Use emitter.setMaxListeners() to increase limit.',
this._events[type].length);
if (typeof console.trace === 'function') {
// not supported in IE 10
console.trace();
}
}
}
return this;
};
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.once = function(type, listener) {
if (!isFunction(listener))
throw TypeError('listener must be a function');
var fired = false;
function g() {
this.removeListener(type, g);
if (!fired) {
fired = true;
listener.apply(this, arguments);
}
}
g.listener = listener;
this.on(type, g);
return this;
};
// emits a 'removeListener' event iff the listener was removed
EventEmitter.prototype.removeListener = function(type, listener) {
var list, position, length, i;
if (!isFunction(listener))
throw TypeError('listener must be a function');
if (!this._events || !this._events[type])
return this;
list = this._events[type];
length = list.length;
position = -1;
if (list === listener ||
(isFunction(list.listener) && list.listener === listener)) {
delete this._events[type];
if (this._events.removeListener)
this.emit('removeListener', type, listener);
} else if (isObject(list)) {
for (i = length; i-- > 0;) {
if (list[i] === listener ||
(list[i].listener && list[i].listener === listener)) {
position = i;
break;
}
}
if (position < 0)
return this;
if (list.length === 1) {
list.length = 0;
delete this._events[type];
} else {
list.splice(position, 1);
}
if (this._events.removeListener)
this.emit('removeListener', type, listener);
}
return this;
};
EventEmitter.prototype.removeAllListeners = function(type) {
var key, listeners;
if (!this._events)
return this;
// not listening for removeListener, no need to emit
if (!this._events.removeListener) {
if (arguments.length === 0)
this._events = {};
else if (this._events[type])
delete this._events[type];
return this;
}
// emit removeListener for all listeners on all events
if (arguments.length === 0) {
for (key in this._events) {
if (key === 'removeListener') continue;
this.removeAllListeners(key);
}
this.removeAllListeners('removeListener');
this._events = {};
return this;
}
listeners = this._events[type];
if (isFunction(listeners)) {
this.removeListener(type, listeners);
} else if (listeners) {
// LIFO order
while (listeners.length)
this.removeListener(type, listeners[listeners.length - 1]);
}
delete this._events[type];
return this;
};
EventEmitter.prototype.listeners = function(type) {
var ret;
if (!this._events || !this._events[type])
ret = [];
else if (isFunction(this._events[type]))
ret = [this._events[type]];
else
ret = this._events[type].slice();
return ret;
};
EventEmitter.prototype.listenerCount = function(type) {
if (this._events) {
var evlistener = this._events[type];
if (isFunction(evlistener))
return 1;
else if (evlistener)
return evlistener.length;
}
return 0;
};
EventEmitter.listenerCount = function(emitter, type) {
return emitter.listenerCount(type);
};
function isFunction(arg) {
return typeof arg === 'function';
}
function isNumber(arg) {
return typeof arg === 'number';
}
function isObject(arg) {
return typeof arg === 'object' && arg !== null;
}
function isUndefined(arg) {
return arg === void 0;
}
},{}],26:[function(require,module,exports){
// shim for using process in browser
var process = module.exports = {};
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = setTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
clearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
setTimeout(drainQueue, 0);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
},{}]},{},[]);
|
document.write('<p id="value">0</p>');
function SliderInput(element, min, max, callback) {
this.element = typeof element !== 'undefined' ? element : document;
this.min = min;
this.max = max;
this.maxWidth = element.width || element.offsetWidth || element.clientWidth || window.innerWidth;
this.callback = callback;
this.value = min;
}
SliderInput.prototype.listen = function() {
this.element.addEventListener('touchstart', this.startTouch.bind(this));
this.element.addEventListener('touchmove', this.determineValue.bind(this));
this.element.addEventListener('keydown', this.setValue.bind(this));
};
SliderInput.prototype.startTouch = function(event) {
event.preventDefault();
this.xStart = event.touches[0].clientX;
};
SliderInput.prototype.determineValue = function(event) {
event.preventDefault();
if( this.xStart === null) {
return;
}
var xEnd = event.touches[0].clientX;
var value = Math.max(0, Math.min(Math.round(((xEnd * (this.max - this.min)) / (this.maxWidth)) + this.min), this.max));
this.value = value;
if(typeof this.callback === 'function') {
this.callback(value);
}
};
SliderInput.prototype.setValue = function(event) {
var keyCode = event.keyCode;
//For number input - tries to append digit if within range
if(keyCode >= 48 && keyCode <= 57 || keyCode >= 96 && keyCode <= 105) {
var zeroCode = keyCode <= 57 ? 48 : 96;
var number = keyCode - zeroCode;
var value = this.value.toString();
value += number.toString();
this.value = value > this.max ? Math.min(number, this.max) : parseInt(value);
//Backspace input - let's do it mathematically
} else if(keyCode === 8) {
this.value = Math.floor(this.value / 10);
//Left and right arrow keys - treat it like a number line
} else {
switch(event.keyCode) {
//Left
case 37 :
case 65 :
case 72 :
if(this.value > this.min) {
this.value -= 1;
}
break;
//Right
case 39 :
case 68 :
case 76 :
if(this.value < this.max) {
this.value += 1;
}
break;
}
}
this.callback(this.value);
};
var input = new SliderInput(document, 0, 20, function(value) {
document.getElementById('value').innerText = value;
});
input.listen();
|
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Ajax.org Code Editor (ACE).
*
* The Initial Developer of the Original Code is
* Ajax.org B.V.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Fabian Jakobs <fabian AT ajax DOT org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
var os = (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase();
var ua = navigator.userAgent;
var av = navigator.appVersion;
/** Is the user using a browser that identifies itself as Windows */
exports.isWin = (os == "win");
/** Is the user using a browser that identifies itself as Mac OS */
exports.isMac = (os == "mac");
/** Is the user using a browser that identifies itself as Linux */
exports.isLinux = (os == "linux");
exports.isIE = ! + "\v1";
/** Is this Firefox or related? */
exports.isGecko = exports.isMozilla = window.controllers && window.navigator.product === "Gecko";
/** oldGecko == rev < 2.0 **/
exports.isOldGecko = exports.isGecko && /rv\:1/.test(navigator.userAgent);
/** Is this Opera */
exports.isOpera = window.opera && Object.prototype.toString.call(window.opera) == "[object Opera]";
/** Is the user using a browser that identifies itself as WebKit */
exports.isWebKit = parseFloat(ua.split("WebKit/")[1]) || undefined;
exports.isChrome = parseFloat(ua.split(" Chrome/")[1]) || undefined;
exports.isAIR = ua.indexOf("AdobeAIR") >= 0;
exports.isIPad = ua.indexOf("iPad") >= 0;
/**
* I hate doing this, but we need some way to determine if the user is on a Mac
* The reason is that users have different expectations of their key combinations.
*
* Take copy as an example, Mac people expect to use CMD or APPLE + C
* Windows folks expect to use CTRL + C
*/
exports.OS = {
LINUX: 'LINUX',
MAC: 'MAC',
WINDOWS: 'WINDOWS'
};
/**
* Return an exports.OS constant
*/
exports.getOS = function() {
if (exports.isMac) {
return exports.OS['MAC'];
} else if (exports.isLinux) {
return exports.OS['LINUX'];
} else {
return exports.OS['WINDOWS'];
}
};
});
|
var mongoose = require('mongoose');
var ListSchema = require('../schemas/list');
var List = mongoose.model('List',ListSchema);
module.exports = List; |
(function() {
'use strict';
b3e.nodes.Vector2GetRightVector = b3e.node.create('Vector2GetRightVector',
b3e.MODULATOR, {
group: 'vector2',
title: 'Get Right Vector',
image: 'modulators/Vector2',
});
})();
|
/*
* ModelFactory module
* @lastmodifiedBy ChengFuLin(chengfulin0806@gmail.com)
* @lastmodifiedDate 2015-08-06
*/
var Model = require('./model');
/**
* ModelFactory
* @constructor
*/
function ModelFactory() {
}
/* start-public-methods */
/**
* Factory method of Model
* @returns {Model}
*/
ModelFactory.prototype.create = function() {
"use strict";
return new Model();
};
/* end-public-methods */
var facotry = new ModelFactory();
module.exports = facotry; |
import { expect } from "chai";
import React from "react";
import {
locationOfOffer,
transform,
sortOffers,
insertOffer
} from "containers/ExchangeOffers/utils";
function t(offer) {
let data = {};
for (let key in offer) data[key] = parseFloat(offer[key] + "")
return data
}
describe("ExchangeOffers utils", () => {
it("transform", () => {
const offers = transform([{ price: 2, amount: 2, total: 4 }, { price: 1, amount: 1, total: 1 }]);
for (let offer of offers) {
expect(typeof(offer.price)).to.equal("object");
expect(typeof(offer.amount)).to.equal("object");
expect(typeof(offer.total)).to.equal("object");
}
});
it("sortOffers", () => {
let offers = transform([
{ price: 4, amount: 1 , total: 4},
{ price: 3, amount: 2 , total: 6},
{ price: 2, amount: 3 , total: 6},
{ price: 1, amount: 4 , total: 4}
]);
offers = sortOffers(offers);
expect(t(offers[0]).price).to.equal(1);
expect(t(offers[1]).price).to.equal(2);
expect(t(offers[2]).price).to.equal(3);
expect(t(offers[3]).price).to.equal(4);
});
it("locationOfOffer lower than all", () => {
let newOffers = transform([{ price: 1, amount: 1 , total: 1}]);
let offers = sortOffers(transform([{ price: 2, amount: 2 , total: 4}]));
let [index, isExist] = locationOfOffer(newOffers[0], offers);
expect(index).to.equal(0);
expect(isExist).to.equal(false);
});
it("locationOfOffer same price", () => {
let newOffers = transform([{ price: 1, amount: 2 , total: 2}]);
let offers = sortOffers(transform([
{ price: 1, amount: 2 , total: 2},
{ price: 2, amount: 2 , total: 4}
]));
let [index, isExist] = locationOfOffer(newOffers[0], offers);
expect(index).to.equal(0);
expect(isExist).to.equal(true);
});
it("locationOfOffer bigger than all", () => {
let newOffers = transform([{ price: 5, amount: 2 , total: 10}]);
let offers = sortOffers(transform([
{ price: 1, amount: 2 , total: 2},
{ price: 2, amount: 2 , total: 4},
{ price: 3, amount: 2 , total: 6}
]));
let [index, isExist] = locationOfOffer(newOffers[0], offers);
expect(index).to.equal(3);
expect(isExist).to.equal(false);
});
it("locationOfOffer in the middle", () => {
let newOffers = transform([{ price: 2, amount: 2 , total: 4}]);
let offers = sortOffers(transform([
{ price: 1, amount: 2 , total: 2},
{ price: 3, amount: 2 , total: 6}
]));
let [index, isExist] = locationOfOffer(newOffers[0], offers);
expect(index).to.equal(1);
expect(isExist).to.equal(false);
});
it("insertOffer update", () => {
let newOffers = transform([{ price: 1, amount: 1 , total: 1}]);
let offers = sortOffers(transform([
{ price: 1, amount: 2 , total: 2},
{ price: 2, amount: 2 , total: 4}
]));
offers = insertOffer(newOffers[0], offers);
expect(t(offers[0]).amount).to.equal(1);
});
it("insertOffer delete", () => {
let newOffers = transform([{ price: 1, amount: 0 , total: 0}]);
let offers = sortOffers(transform([
{ price: 1, amount: 1 , total: 1},
{ price: 2, amount: 2 , total: 4}
]));
offers = insertOffer(newOffers[0], offers);
expect(t(offers[0]).price).to.equal(2);
expect(t(offers[0]).amount).to.equal(2);
expect(offers.length).to.equal(1);
});
it("insertOffer insert", () => {
let newOffers = transform([{ price: 2, amount: 2 , total: 4}]);
let offers = sortOffers(transform([
{ price: 1, amount: 1 , total: 1},
{ price: 3, amount: 3 , total: 9}
]));
offers = insertOffer(newOffers[0], offers);
expect(t(offers[1]).price).to.equal(2);
expect(t(offers[1]).amount).to.equal(2);
expect(offers.length).to.equal(3);
});
});
|
// flow-typed signature: 04c5870b5fe5aee349b372d22630ffcc
// flow-typed version: 43bc56fd02/@storybook/react_v4.x.x/flow_>=v0.72.x
type NodeModule = typeof module;
declare module '@storybook/react' {
declare type Context = { kind: string, story: string };
declare type Renderable = React$Element<*>;
declare type RenderCallback = (
context: Context
) => Renderable | Array<Renderable>;
declare type RenderFunction = () => Renderable | Array<Renderable>;
declare type StoryDecorator = (
story: RenderFunction,
context: Context
) => Renderable | null;
declare type DecoratorParameters = {
[key: string]: any,
};
declare interface Story {
+kind: string;
add(
storyName: string,
callback: RenderCallback,
parameters?: DecoratorParameters
): Story;
addDecorator(decorator: StoryDecorator): Story;
addParameters(parameters: DecoratorParameters): Story;
}
declare interface StoryObject {
name: string;
render: RenderFunction;
}
declare interface StoryBucket {
kind: string;
filename: string;
stories: Array<StoryObject>;
}
declare function addDecorator(decorator: StoryDecorator): void;
declare function addParameters(parameters: DecoratorParameters): void;
declare function clearDecorators(): void;
declare function configure(fn: () => void, module: NodeModule): void;
declare function setAddon(addon: Object): void;
declare function storiesOf(name: string, module: NodeModule): Story;
declare function storiesOf<T>(name: string, module: NodeModule): Story & T;
declare function forceReRender(): void;
declare function getStorybook(): Array<StoryBucket>;
}
|
var read = require('read'),
path = require('path'),
util = require('util'),
fs = require('fs');
var version = require('./package.json').version;
var Commands = [
'all',
'cd',
'cp',
'current',
'help',
'ls',
'pwd',
'use',
'version',
];
var Services = ['baidu'];
var ConfigFileName = '.baohe.json';
var debug = function() { };
if (/\bbaohe\b/.test(process.env.NODE_DEBUG)) {
debug = function() {
console.error('[BAOHE] %s', util.format.apply(util, arguments));
};
}
function getConfigFile() {
var configDir = process.env.HOME || process.env.TMPDIR;
return path.join(configDir, ConfigFileName);
}
function Baohe() {}
Baohe.prototype.getCommand = function(name) {
var command = 'help';
if (Commands.indexOf(name) !== -1) {
command = name;
}
return require('./lib/' + command);
};
Baohe.prototype.getService = function(serviceName) {
return require('./lib/' + serviceName);
};
Baohe.prototype.getConfig = function(service) {
if (!this.config) {
var configFile = getConfigFile();
if (fs.existsSync(configFile)) {
this.config = require(configFile);
} else {
this.config = {};
}
}
var result = this.config;
if (service) {
if (!this.config[service]) {
this.config[service] = {};
}
result = this.config[service];
}
return result;
};
Baohe.prototype.processLogin = function(onLogin, onSuccess) {
function promptLoginInfo(callback) {
read({ prompt: 'user name:', silent: false },
function(err, user) {
read({ prompt: 'password:', silent: true },
function(err, password) {
process.nextTick(function() {
callback(user, password);
});
});
});
}
var self = this;
promptLoginInfo(function(user, password) {
onLogin(user, password, function(success) {
if (success) {
debug('Login sucessfully');
self._writeConfigFile();
process.nextTick(onSuccess);
} else {
process.nextTick(function() {
self.processLogin(onLogin, onSuccess);
});
}
});
});
};
Baohe.prototype.debug = debug;
Baohe.prototype._writeConfigFile = function() {
fs.writeFileSync(getConfigFile(),
JSON.stringify(this.config, null, 2));
};
exports = module.exports = new Baohe();
exports.Version = version;
exports.Commands = Commands;
exports.Services = Services;
|
var Vector2 = function()
{
this.x = 0;
this.y = 0;
}
Vector2.prototype.set = function(x,y)
{
this.x = x;
this.y = y;
}
//return a single value
Vector2.prototype.Magnitude = function()
{
return Math.sqrt(this.x * this.x + this.y * this.y);
}
//returns a Vector2
Vector2.prototype.Normalize = function()
{
var length = this.Magnitude();
if (length == 0)
return;
this.x /= length;
this.y /= length;
} |
c['1703']=[['1704',"ApplicantVideoVm Constructor","topic_000000000000059B.html",0],['1705',"Properties","topic_000000000000059A_props--.html",1]]; |
const storage = {};
storage.set = (key, object) => {
sessionStorage[key] = (typeof object) === 'string' ? object : JSON.stringify(object);
}
storage.get = (key) => {
if (!sessionStorage[key]) {
return null;
}
try {
const parsed = JSON.parse(sessionStorage[key]);
return parsed;
} catch(e) {
return sessionStorage[key];
}
}
storage.remove = (key) => {
if (sessionStorage[key]) {
sessionStorage.removeItem(key);
}
}
export default storage; |
/****************************************************************************
jquery-bootstrap-modal-backdrop.js,
(c) 2017, FCOO
https://github.com/fcoo/jquery-bootstrap
https://github.com/fcoo
Global methods to provide backdrop for modal windows and noty
****************************************************************************/
(function ($, window/*, document, undefined*/) {
"use strict";
$.bsZIndexModalBackdrop = 1040; // zindexModalBackdrop = 1040, //MUST be equal to $zindex-modal-backdrop in bootstrap/scss/_variables.scss
var zindexAllwaysOnTop = 9999,
modalBackdropLevels = 0,
$modalBackdrop = null;
/******************************************************
$.fn._setModalBackdropZIndex
Set the z-index of this to the current level
If a className is given => use it, else
If delta === true the z-index is set to zindexAllwaysOnTop (9999), else
increase current z-index by 10
******************************************************/
$.fn._setModalBackdropZIndex = function( delta, className ){
if (className)
this.addClass( className );
else
this.css('z-index', delta === true ? zindexAllwaysOnTop : $.bsZIndexModalBackdrop + modalBackdropLevels*10 + (delta?delta:0));
return this;
};
/******************************************************
$._addModalBackdropLevel
Move the backdrop up in z-index
******************************************************/
$._addModalBackdropLevel = function(){
modalBackdropLevels++;
if (!$modalBackdrop)
$modalBackdrop =
$('<div/>')
.append( $('<i/>')._bsAddHtml({icon:'fa-spinner fa-spin'}) )
.addClass('global-backdrop')
.appendTo( $('body') );
$modalBackdrop
._setModalBackdropZIndex( -1 )
.removeClass('hidden')
.addClass('show');
};
/******************************************************
$._removeModalBackdropLevel
Move the backdrop down in z-index
******************************************************/
$._removeModalBackdropLevel = function( noDelay ){
modalBackdropLevels--;
$modalBackdrop._setModalBackdropZIndex( -1 );
if (!modalBackdropLevels){
$modalBackdrop
.removeClass('show');
if (noDelay)
$modalBackdrop.addClass('hidden');
else
window.setTimeout( function(){ $modalBackdrop.addClass('hidden'); }, 2000 );
}
};
/******************************************************
$.workingOn / $.workingOff
Display/hide a bagdrop while some process is 'working'
******************************************************/
$.workingOn = function(){
$._addModalBackdropLevel();
window.setTimeout(function(){
$modalBackdrop.addClass('working');
}, 100);
};
$.workingOff = function(){
$._removeModalBackdropLevel(true);
window.setTimeout(function(){
$modalBackdrop.removeClass('working');
}, 100);
};
}(jQuery, this, document)); |
/*jshint multistr:true, quotmark:false */
var fireNative, originaljQuery, original$,
baseURL = "",
supportjQuery = this.jQuery,
// see RFC 2606
externalHost = "example.com";
this.hasPHP = true;
this.isLocal = window.location.protocol === "file:";
// Setup global variables before loading jQuery for testing .noConflict()
supportjQuery.noConflict( true );
originaljQuery = this.jQuery = undefined;
original$ = this.$ = "replaced";
/**
* Returns an array of elements with the given IDs
* @example q("main", "foo", "bar")
* @result [<div id="main">, <span id="foo">, <input id="bar">]
*/
this.q = function() {
var r = [],
i = 0;
for ( ; i < arguments.length; i++ ) {
r.push( document.getElementById( arguments[i] ) );
}
return r;
};
/**
* Asserts that a select matches the given IDs
* @param {String} a - Assertion name
* @param {String} b - Sizzle selector
* @param {String} c - Array of ids to construct what is expected
* @example t("Check for something", "//[a]", ["foo", "baar"]);
* @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baar'
*/
this.t = function( a, b, c ) {
var f = jQuery(b).get(),
s = "",
i = 0;
for ( ; i < f.length; i++ ) {
s += ( s && "," ) + '"' + f[ i ].id + '"';
}
deepEqual(f, q.apply( q, c ), a + " (" + b + ")");
};
this.createDashboardXML = function() {
var string = '<?xml version="1.0" encoding="UTF-8"?> \
<dashboard> \
<locations class="foo"> \
<location for="bar" checked="different"> \
<infowindowtab normal="ab" mixedCase="yes"> \
<tab title="Location"><![CDATA[blabla]]></tab> \
<tab title="Users"><![CDATA[blublu]]></tab> \
</infowindowtab> \
</location> \
</locations> \
</dashboard>';
return jQuery.parseXML(string);
};
this.createWithFriesXML = function() {
var string = '<?xml version="1.0" encoding="UTF-8"?> \
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" \
xmlns:xsd="http://www.w3.org/2001/XMLSchema" \
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> \
<soap:Body> \
<jsconf xmlns="http://{{ externalHost }}/ns1"> \
<response xmlns:ab="http://{{ externalHost }}/ns2"> \
<meta> \
<component id="seite1" class="component"> \
<properties xmlns:cd="http://{{ externalHost }}/ns3"> \
<property name="prop1"> \
<thing /> \
<value>1</value> \
</property> \
<property name="prop2"> \
<thing att="something" /> \
</property> \
<foo_bar>foo</foo_bar> \
</properties> \
</component> \
</meta> \
</response> \
</jsconf> \
</soap:Body> \
</soap:Envelope>';
return jQuery.parseXML( string.replace( /\{\{\s*externalHost\s*\}\}/g, externalHost ) );
};
this.createXMLFragment = function() {
var xml, frag;
if ( window.ActiveXObject ) {
xml = new ActiveXObject("msxml2.domdocument");
} else {
xml = document.implementation.createDocument( "", "", null );
}
if ( xml ) {
frag = xml.createElement("data");
}
return frag;
};
fireNative = document.createEvent ?
function( node, type ) {
var event = document.createEvent('HTMLEvents');
event.initEvent( type, true, true );
node.dispatchEvent( event );
} :
function( node, type ) {
var event = document.createEventObject();
node.fireEvent( 'on' + type, event );
};
/**
* Add random number to url to stop caching
*
* @example url("data/test.html")
* @result "data/test.html?10538358428943"
*
* @example url("data/test.php?foo=bar")
* @result "data/test.php?foo=bar&10538358345554"
*/
function url( value ) {
return baseURL + value + (/\?/.test( value ) ? "&" : "?") +
new Date().getTime() + "" + parseInt( Math.random() * 100000, 10 );
}
// Ajax testing helper
this.ajaxTest = function( title, expect, options ) {
var requestOptions;
if ( jQuery.isFunction( options ) ) {
options = options();
}
options = options || [];
requestOptions = options.requests || options.request || options;
if ( !jQuery.isArray( requestOptions ) ) {
requestOptions = [ requestOptions ];
}
asyncTest( title, expect, function() {
if ( options.setup ) {
options.setup();
}
var completed = false,
remaining = requestOptions.length,
complete = function() {
if ( !completed && --remaining === 0 ) {
completed = true;
delete ajaxTest.abort;
if ( options.teardown ) {
options.teardown();
}
start();
}
},
requests = jQuery.map( requestOptions, function( options ) {
var request = ( options.create || jQuery.ajax )( options ),
callIfDefined = function( deferType, optionType ) {
var handler = options[ deferType ] || !!options[ optionType ];
return function( _, status ) {
if ( !completed ) {
if ( !handler ) {
ok( false, "unexpected " + status );
} else if ( jQuery.isFunction( handler ) ) {
handler.apply( this, arguments );
}
}
};
};
if ( options.afterSend ) {
options.afterSend( request );
}
return request
.done( callIfDefined( "done", "success" ) )
.fail( callIfDefined( "fail", "error" ) )
.always( complete );
});
ajaxTest.abort = function( reason ) {
if ( !completed ) {
completed = true;
delete ajaxTest.abort;
ok( false, "aborted " + reason );
jQuery.each( requests, function( i, request ) {
request.abort();
});
}
};
});
};
this.testIframe = function( fileName, name, fn ) {
asyncTest(name, function() {
// load fixture in iframe
var iframe = loadFixture(),
win = iframe.contentWindow,
interval = setInterval(function() {
if ( win && win.jQuery && win.jQuery.isReady ) {
clearInterval( interval );
start();
// call actual tests passing the correct jQuery instance to use
fn.call( this, win.jQuery, win, win.document );
document.body.removeChild( iframe );
iframe = null;
}
}, 15 );
});
function loadFixture() {
var src = url( "./data/" + fileName + ".html" ),
iframe = jQuery( "<iframe />" ).appendTo( "body" )[ 0 ];
iframe.style.cssText = "width: 500px; height: 500px; position: absolute; top: -600px; left: -600px; visibility: hidden;";
iframe.contentWindow.location = src;
return iframe;
}
};
this.testIframeWithCallback = function( title, fileName, func ) {
test( title, function() {
var iframe;
// Expect one assertion, but allow overrides
expect( 1 );
stop();
window.iframeCallback = function() {
var self = this,
args = arguments;
setTimeout(function() {
window.iframeCallback = undefined;
iframe.remove();
func.apply( self, args );
func = function() {};
start();
}, 0 );
};
iframe = jQuery( "<div/>" ).css({ position: "absolute", width: "500px", left: "-600px" })
.append( jQuery( "<iframe/>" ).attr( "src", url( "./data/" + fileName ) ) )
.appendTo( "#qunit-fixture" );
});
};
window.iframeCallback = undefined; |
import { Directive, ElementRef, EventEmitter, HostListener, Input, Output, Renderer, ViewContainerRef } from '@angular/core';
import { NgControl } from '@angular/forms';
import { TypeaheadContainerComponent } from './typeahead-container.component';
import { TypeaheadUtils } from './typeahead-utils';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/from';
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/operator/toArray';
import { TypeaheadMatch } from './typeahead-match.class';
import { ComponentLoaderFactory } from '../component-loader';
export var TypeaheadDirective = (function () {
function TypeaheadDirective(control, viewContainerRef, element, renderer, cis) {
/** minimal no of characters that needs to be entered before typeahead kicks-in. When set to 0, typeahead shows on focus with full list of options (limited as normal by typeaheadOptionsLimit) */
this.typeaheadMinLength = void 0;
/** should be used only in case of typeahead attribute is array. If true - loading of options will be async, otherwise - sync. true make sense if options array is large. */
this.typeaheadAsync = void 0;
/** match latin symbols. If true the word súper would match super and vice versa. */
this.typeaheadLatinize = true;
/** break words with spaces. If true the text "exact phrase" here match would match with match exact phrase here but not with phrase here exact match (kind of "google style"). */
this.typeaheadSingleWords = true;
/** should be used only in case typeaheadSingleWords attribute is true. Sets the word delimiter to break words. Defaults to space. */
this.typeaheadWordDelimiters = ' ';
/** should be used only in case typeaheadSingleWords attribute is true. Sets the word delimiter to match exact phrase. Defaults to simple and double quotes. */
this.typeaheadPhraseDelimiters = '\'"';
/** fired when 'busy' state of this component was changed, fired on async mode only, returns boolean */
this.typeaheadLoading = new EventEmitter();
/** fired on every key event and returns true in case of matches are not detected */
this.typeaheadNoResults = new EventEmitter();
/** fired when option was selected, return object with data of this option */
this.typeaheadOnSelect = new EventEmitter();
/** fired when blur event occurres. returns the active item */
this.typeaheadOnBlur = new EventEmitter();
this.isTypeaheadOptionsListActive = false;
this.keyUpEventEmitter = new EventEmitter();
this.placement = 'bottom-left';
this.element = element;
this.ngControl = control;
this.viewContainerRef = viewContainerRef;
this.renderer = renderer;
this._typeahead = cis
.createLoader(element, viewContainerRef, renderer);
}
TypeaheadDirective.prototype.onChange = function (e) {
if (this._container) {
// esc
if (e.keyCode === 27) {
this.hide();
return;
}
// up
if (e.keyCode === 38) {
this._container.prevActiveMatch();
return;
}
// down
if (e.keyCode === 40) {
this._container.nextActiveMatch();
return;
}
// enter
if (e.keyCode === 13) {
this._container.selectActiveMatch();
return;
}
}
// For `<input>`s, use the `value` property. For others that don't have a
// `value` (such as `<span contenteditable="true">`, use `innerText`.
var value = e.target.value !== undefined
? e.target.value
: e.target.innerText;
if (value.trim().length >= this.typeaheadMinLength) {
this.typeaheadLoading.emit(true);
this.keyUpEventEmitter.emit(e.target.value);
}
else {
this.typeaheadLoading.emit(false);
this.typeaheadNoResults.emit(false);
this.hide();
}
};
TypeaheadDirective.prototype.onFocus = function () {
if (this.typeaheadMinLength === 0) {
this.typeaheadLoading.emit(true);
this.keyUpEventEmitter.emit('');
}
};
TypeaheadDirective.prototype.onBlur = function () {
if (this._container && !this._container.isFocused) {
this.typeaheadOnBlur.emit(this._container.active);
this.hide();
}
};
TypeaheadDirective.prototype.onKeydown = function (e) {
// no container - no problems
if (!this._container) {
return;
}
// if items is visible - prevent form submition
if (e.keyCode === 13) {
e.preventDefault();
return;
}
};
TypeaheadDirective.prototype.ngOnInit = function () {
this.typeaheadOptionsLimit = this.typeaheadOptionsLimit || 20;
this.typeaheadMinLength = this.typeaheadMinLength === void 0
? 1
: this.typeaheadMinLength;
this.typeaheadWaitMs = this.typeaheadWaitMs || 0;
// async should be false in case of array
if (this.typeaheadAsync === undefined && !(this.typeahead instanceof Observable)) {
this.typeaheadAsync = false;
}
if (this.typeahead instanceof Observable) {
this.typeaheadAsync = true;
}
if (this.typeaheadAsync) {
this.asyncActions();
}
else {
this.syncActions();
}
};
TypeaheadDirective.prototype.changeModel = function (match) {
var valueStr = match.value;
this.ngControl.viewToModelUpdate(valueStr);
this.ngControl.control.setValue(valueStr);
this.hide();
};
Object.defineProperty(TypeaheadDirective.prototype, "matches", {
get: function () {
return this._matches;
},
enumerable: true,
configurable: true
});
TypeaheadDirective.prototype.show = function () {
this._typeahead
.attach(TypeaheadContainerComponent)
.to(this.container)
.position({ attachment: 'bottom left' })
.show({
typeaheadRef: this,
placement: this.placement,
animation: false
});
this._container = this._typeahead.instance;
this._container.parent = this;
// This improves the speed as it won't have to be done for each list item
var normalizedQuery = (this.typeaheadLatinize
? TypeaheadUtils.latinize(this.ngControl.control.value)
: this.ngControl.control.value).toString()
.toLowerCase();
this._container.query = this.typeaheadSingleWords
? TypeaheadUtils.tokenize(normalizedQuery, this.typeaheadWordDelimiters, this.typeaheadPhraseDelimiters)
: normalizedQuery;
this._container.matches = this._matches;
this.element.nativeElement.focus();
};
TypeaheadDirective.prototype.hide = function () {
if (this._typeahead.isShown) {
this._typeahead.hide();
this._container = null;
}
};
TypeaheadDirective.prototype.ngOnDestroy = function () {
this._typeahead.dispose();
};
TypeaheadDirective.prototype.asyncActions = function () {
var _this = this;
this.keyUpEventEmitter
.debounceTime(this.typeaheadWaitMs)
.mergeMap(function () { return _this.typeahead; })
.subscribe(function (matches) {
_this.finalizeAsyncCall(matches);
}, function (err) {
console.error(err);
});
};
TypeaheadDirective.prototype.syncActions = function () {
var _this = this;
this.keyUpEventEmitter
.debounceTime(this.typeaheadWaitMs)
.mergeMap(function (value) {
var normalizedQuery = _this.normalizeQuery(value);
return Observable.from(_this.typeahead)
.filter(function (option) {
return option && _this.testMatch(_this.normalizeOption(option), normalizedQuery);
})
.toArray();
})
.subscribe(function (matches) {
_this.finalizeAsyncCall(matches);
}, function (err) {
console.error(err);
});
};
TypeaheadDirective.prototype.normalizeOption = function (option) {
var optionValue = TypeaheadUtils.getValueFromObject(option, this.typeaheadOptionField);
var normalizedOption = this.typeaheadLatinize
? TypeaheadUtils.latinize(optionValue)
: optionValue;
return normalizedOption.toLowerCase();
};
TypeaheadDirective.prototype.normalizeQuery = function (value) {
// If singleWords, break model here to not be doing extra work on each
// iteration
var normalizedQuery = (this.typeaheadLatinize ? TypeaheadUtils.latinize(value) : value)
.toString()
.toLowerCase();
normalizedQuery = this.typeaheadSingleWords
?
TypeaheadUtils.tokenize(normalizedQuery, this.typeaheadWordDelimiters, this.typeaheadPhraseDelimiters)
:
normalizedQuery;
return normalizedQuery;
};
TypeaheadDirective.prototype.testMatch = function (match, test) {
var spaceLength;
if (typeof test === 'object') {
spaceLength = test.length;
for (var i = 0; i < spaceLength; i += 1) {
if (test[i].length > 0 && match.indexOf(test[i]) < 0) {
return false;
}
}
return true;
}
else {
return match.indexOf(test) >= 0;
}
};
TypeaheadDirective.prototype.finalizeAsyncCall = function (matches) {
this.prepareMatches(matches);
this.typeaheadLoading.emit(false);
this.typeaheadNoResults.emit(!this.hasMatches());
if (!this.hasMatches()) {
this.hide();
return;
}
if (this._container) {
// This improves the speed as it won't have to be done for each list item
var normalizedQuery = (this.typeaheadLatinize
? TypeaheadUtils.latinize(this.ngControl.control.value)
: this.ngControl.control.value).toString()
.toLowerCase();
this._container.query = this.typeaheadSingleWords
? TypeaheadUtils.tokenize(normalizedQuery, this.typeaheadWordDelimiters, this.typeaheadPhraseDelimiters)
: normalizedQuery;
this._container.matches = this._matches;
}
else {
this.show();
}
};
TypeaheadDirective.prototype.prepareMatches = function (options) {
var _this = this;
var limited = options.slice(0, this.typeaheadOptionsLimit);
if (this.typeaheadGroupField) {
var matches_1 = [];
// extract all group names
var groups = limited
.map(function (option) { return TypeaheadUtils.getValueFromObject(option, _this.typeaheadGroupField); })
.filter(function (v, i, a) { return a.indexOf(v) === i; });
groups.forEach(function (group) {
// add group header to array of matches
matches_1.push(new TypeaheadMatch(group, group, true));
// add each item of group to array of matches
matches_1 = matches_1.concat(limited
.filter(function (option) { return TypeaheadUtils.getValueFromObject(option, _this.typeaheadGroupField) === group; })
.map(function (option) { return new TypeaheadMatch(option, TypeaheadUtils.getValueFromObject(option, _this.typeaheadOptionField)); }));
});
this._matches = matches_1;
}
else {
this._matches = limited.map(function (option) { return new TypeaheadMatch(option, TypeaheadUtils.getValueFromObject(option, _this.typeaheadOptionField)); });
}
};
TypeaheadDirective.prototype.hasMatches = function () {
return this._matches.length > 0;
};
TypeaheadDirective.decorators = [
{ type: Directive, args: [{ selector: '[typeahead]', exportAs: 'bs-typeahead' },] },
];
/** @nocollapse */
TypeaheadDirective.ctorParameters = function () { return [
{ type: NgControl, },
{ type: ViewContainerRef, },
{ type: ElementRef, },
{ type: Renderer, },
{ type: ComponentLoaderFactory, },
]; };
TypeaheadDirective.propDecorators = {
'typeahead': [{ type: Input },],
'typeaheadMinLength': [{ type: Input },],
'typeaheadWaitMs': [{ type: Input },],
'typeaheadOptionsLimit': [{ type: Input },],
'typeaheadOptionField': [{ type: Input },],
'typeaheadGroupField': [{ type: Input },],
'typeaheadAsync': [{ type: Input },],
'typeaheadLatinize': [{ type: Input },],
'typeaheadSingleWords': [{ type: Input },],
'typeaheadWordDelimiters': [{ type: Input },],
'typeaheadPhraseDelimiters': [{ type: Input },],
'typeaheadItemTemplate': [{ type: Input },],
'optionsListTemplate': [{ type: Input },],
'typeaheadLoading': [{ type: Output },],
'typeaheadNoResults': [{ type: Output },],
'typeaheadOnSelect': [{ type: Output },],
'typeaheadOnBlur': [{ type: Output },],
'container': [{ type: Input },],
'onChange': [{ type: HostListener, args: ['keyup', ['$event'],] },],
'onFocus': [{ type: HostListener, args: ['focus',] },],
'onBlur': [{ type: HostListener, args: ['blur',] },],
'onKeydown': [{ type: HostListener, args: ['keydown', ['$event'],] },],
};
return TypeaheadDirective;
}());
//# sourceMappingURL=typeahead.directive.js.map |
(function () {
'use strict';
angular.module('common').factory('logger', ['$log', logger]);
function logger($log) {
var service = {
getLogFn: getLogFn,
log: log,
logError: logError,
logSuccess: logSuccess,
logWarning: logWarning
};
return service;
function getLogFn(moduleId, fnName) {
fnName = fnName || 'log';
switch (fnName.toLowerCase()) { // convert aliases
case 'success':
fnName = 'logSuccess'; break;
case 'error':
fnName = 'logError'; break;
case 'warn':
fnName = 'logWarning'; break;
case 'warning':
fnName = 'logWarning'; break;
}
var logFn = service[fnName] || service.log;
return function (msg, data, showToast) {
logFn(msg, data, moduleId, (showToast === undefined) ? true : showToast);
};
}
function log(message, data, source, showToast) {
logIt(message, data, source, showToast, 'info');
}
function logWarning(message, data, source, showToast) {
logIt(message, data, source, showToast, 'warning');
}
function logSuccess(message, data, source, showToast) {
logIt(message, data, source, showToast, 'success');
}
function logError(message, data, source, showToast) {
logIt(message, data, source, showToast, 'error');
}
function logIt(message, data, source, showToast, toastType) {
var write = (toastType === 'error') ? $log.error : $log.log;
source = source ? '[' + source + '] ' : '';
write(source, message, data);
if (showToast) {
if (toastType === 'error') {
toastr.error(message);
} else if (toastType === 'warning') {
toastr.warning(message);
} else if (toastType === 'success') {
toastr.success(message);
} else {
toastr.info(message);
}
}
}
}
})(); |
'use strict';
var data = require('../data.js'),
util = require('./util.js');
exports.isTorsoUp = function (skillTree) {
if (skillTree === '胴系統倍加') return true;
if (skillTree === '胴系統倍化') return true;
return false;
};
exports.hasTorsoUp = function (skillComb) {
if (skillComb == null) return false;
if (skillComb['胴系統倍加']) return true;
if (skillComb['胴系統倍化']) return true;
return false;
};
/**
* skillTrees のみのスキルの組み合わせにまとめる。
*
* skillTrees のスキルがない場合(undefined のプロパティ)は 0 で初期化。
* skillComb に胴系統倍加がある場合は、skillTrees に関係なく含める。
*/
exports.compact = function (skillTrees, skillComb) {
if (!util.isArray(skillComb)) {
return compact(skillTrees, skillComb);
}
var skillCombs = skillComb,
ret = [];
for (var i = 0, len = skillCombs.length; i < len; ++i) {
var sc = skillCombs[i];
ret.push(this.compact(skillTrees, sc));
}
if (ret.length === 0) ret = [ this.compact(skillTrees) ];
return ret;
};
var compact = function (skillTrees, skillComb) {
var tree,
ret = {};
skillTrees = skillTrees || [];
skillComb = skillComb || {};
for (var i = 0, len = skillTrees.length; i < len; ++i) {
tree = skillTrees[i];
ret[tree] = skillComb[tree] || 0;
}
for (tree in skillComb) {
if (exports.isTorsoUp(tree)) {
ret[tree] = skillComb[tree];
break;
}
}
return ret;
};
/**
* スキルの組み合わせに skillTree のスキル系統が含まれていたら true 、
* そうでなければ false を返す。
*/
exports.contains = function (skillComb, skillTree) {
var trees = util.isArray(skillTree) ? skillTree : [ skillTree ];
for (var combTree in skillComb) {
for (var i = 0, len = trees.length; i < len; ++i) {
if (combTree === trees[i]) return true;
}
}
return false;
};
/**
* スキルの名前をキーに data のスキルデータを返す。
*/
exports.get = function (name) {
return data.skills[name] || null;
};
/**
* スキルの組み合わせが同じか調べる。
*
* 前提として combA と combB は全く同じプロパティを持っていること。
*/
exports.isEqual = function (combA, combB) {
for (var key in combA) {
if (combA[key] !== combB[key]) return false;
}
return true;
};
/**
* スキルの組み合わせのリストを結合する。
* (胴系統倍加のポイントは加算しない)
*
* e.g.
* join([ { '攻撃': 1, '防御': -1 }, { '斬れ味': 1, '匠': -1 } ]);
* => { '攻撃': 1, '防御': -1, '斬れ味': 1, '匠': -1 }
*/
exports.join = function (combs) {
combs = combs || [];
var ret = {};
for (var i = 0, len = combs.length; i < len; ++i) {
var comb = combs[i];
if (comb == null) continue;
for (var tree in comb) {
if (exports.isTorsoUp(tree)) {
ret[tree] = 1;
continue;
}
if (ret[tree] == null) ret[tree] = 0;
ret[tree] += comb[tree];
}
}
return ret;
};
/**
* スキルの組み合わせをマージする。
* (胴系統倍加のポイントは加算しない)
*
* e.g.
* merge({ '攻撃': 1, '防御': -1 }, { '斬れ味': 1, '匠': -1 });
* => { '攻撃': 1, '防御': -1, '斬れ味': 1, '匠': -1 }
*/
exports.merge = function (a, b) {
return this.join([ a, b ]);
};
/**
* スキルの組み合わせのスキルポイントを合計する。
* (胴系統倍加のポイントは合計しない)
*
* e.g.
* sum({ '攻撃': 1, '斬れ味': 1 })
* => 2
*/
exports.sum = function (skillComb) {
if (skillComb == null) return 0;
var sum = 0;
for (var tree in skillComb) {
if (exports.isTorsoUp(tree)) continue;
sum += skillComb[tree];
}
return sum;
};
/**
* スキル(の名前)から対応するスキル系統を返す。
*/
exports.trees = function (skillNames) {
var skillTrees = [];
for (var i = 0, len = skillNames.length; i < len; ++i) {
var name = skillNames[i],
skill = this.get(name);
if (skill == null) throw new Error(name + ' is not found');
skillTrees.push(skill.tree);
}
return skillTrees;
};
/**
* セット or リストとして渡されたスキルを一つにまとめて返す。
* (胴系統倍加も考慮)
*
* セットの場合のデータ構造
* { head: { skillComb: {}, ... }, ... }
*
* リストの場合のデータ構造
* [ { skillComb: {}, ... }, ... }
*
* リストの場合、最初の要素を胴として胴系統倍加を処理する。
*/
exports.unify = function (setOrList) {
return util.isArray(setOrList) ?
this._unifyList(setOrList) : this._unifySet(setOrList);
};
exports._unifySet = function (set) {
var bodySC = set.body ? (set.body.skillComb || {}) : {};
var combs = [];
for (var part in set) {
var skillComb = set[part] ? (set[part].skillComb || {}) : {};
if (exports.hasTorsoUp(skillComb)) skillComb = bodySC;
combs.push(skillComb);
}
return this.join(combs);
};
exports._unifyList = function (list) {
var bodySC = list[0] ? (list[0].skillComb || {}) : {};
var combs = [];
for (var i = 0, len = list.length; i < len; ++i) {
var skillComb = list[i] ? (list[i].skillComb || {}) : {};
if (exports.hasTorsoUp(skillComb)) skillComb = bodySC;
combs.push(skillComb);
}
return this.join(combs);
};
|
import AWS from 'aws-sdk/dist/aws-sdk-react-native';
import Storage from './Storage';
import StorageKeys from './StorageKeys.js';
import Util from'./MobileAnalyticsUtilities';
import { Constants } from 'expo';
/**
* @typedef AMA.Client.Options
* @property {string} appId - The Application ID from the Amazon Mobile Analytics Console
* @property {string} [apiVersion=2014-06-05] - The version of the Mobile Analytics API to submit to.
* @property {object} [provider=AWS.config.credentials] - Credentials to use for submitting events.
* **Never check in credentials to source
* control.
* @property {boolean} [autoSubmitEvents=true] - Automatically Submit Events, Default: true
* @property {number} [autoSubmitInterval=10000] - Interval to try to submit events in ms,
* Default: 10s
* @property {number} [batchSizeLimit=256000] - Batch Size in Bytes, Default: 256Kb
* @property {AMA.Client.SubmitCallback} [submitCallback=] - Callback function that is executed when events are
* successfully submitted
* @property {AMA.Client.Attributes} [globalAttributes=] - Attribute to be applied to every event, may be
* overwritten with a different value when recording events.
* @property {AMA.Client.Metrics} [globalMetrics=] - Metric to be applied to every event, may be overwritten
* with a different value when recording events.
* @property {string} [clientId=GUID()] - A unique identifier representing this installation instance
* of your app. This will be managed and persisted by the SDK
* by default.
* @property {string} [appTitle=] - The title of your app. For example, My App.
* @property {string} [appVersionName=] - The version of your app. For example, V2.0.
* @property {string} [appVersionCode=] - The version code for your app. For example, 3.
* @property {string} [appPackageName=] - The name of your package. For example, com.example.my_app.
* @property {string} [platform=] - The operating system of the device. For example, iPhoneOS.
* @property {string} [plaformVersion=] - The version of the operating system of the device.
* For example, 4.0.4.
* @property {string} [model=] - The model of the device. For example, Nexus.
* @property {string} [make=] - The manufacturer of the device. For example, Samsung.
* @property {string} [locale=] - The locale of the device. For example, en_US.
* @property {AMA.Client.Logger} [logger=] - Object of logger functions
* @property {AMA.Storage} [storage=] - Storage client to persist events, will create a new AMA.Storage if not provided
* @property {Object} [clientOptions=] - Low level client options to be passed to the AWS.MobileAnalytics low level SDK
*/
/**
* @typedef AMA.Client.Logger
* @description Uses Javascript Style log levels, one function for each level. Basic usage is to pass the console object
* which will output directly to browser developer console.
* @property {Function} [log=] - Logger for client log level messages
* @property {Function} [info=] - Logger for interaction level messages
* @property {Function} [warn=] - Logger for warn level messages
* @property {Function} [error=] - Logger for error level messages
*/
/**
* @typedef AMA.Client.Attributes
* @type {object}
* @description A collection of key-value pairs that give additional context to the event. The key-value pairs are
* specified by the developer.
*/
/**
* @typedef AMA.Client.Metrics
* @type {object}
* @description A collection of key-value pairs that gives additional measurable context to the event. The pairs
* specified by the developer.
*/
/**
* @callback AMA.Client.SubmitCallback
* @param {Error} err
* @param {Null} data
* @param {string} batchId
*/
/**
* @typedef AMA.Client.Event
* @type {object}
* @description A JSON object representing an event occurrence in your app and consists of the following:
* @property {string} eventType - A name signifying an event that occurred in your app. This is used for grouping and
* aggregating like events together for reporting purposes.
* @property {string} timestamp - The time the event occurred in ISO 8601 standard date time format.
* For example, 2014-06-30T19:07:47.885Z
* @property {AMA.Client.Attributes} [attributes=] - A collection of key-value pairs that give additional context to
* the event. The key-value pairs are specified by the developer.
* This collection can be empty or the attribute object can be omitted.
* @property {AMA.Client.Metrics} [metrics=] - A collection of key-value pairs that gives additional measurable context
* to the event. The pairs specified by the developer.
* @property {AMA.Session} session - Describes the session. Session information is required on ALL events.
*/
/**
* @name AMA.Client
* @namespace AMA.Client
* @constructor
* @param {AMA.Client.Options} options - A configuration map for the AMA.Client
* @returns A new instance of the Mobile Analytics Mid Level Client
*/
export default class MobileAnalyticsClient {
constructor(options, callback) {
this.options = options || {};
this.options.logger = this.options.logger || {};
this.logger = {
log : this.options.logger.log || Util.NOP,
info : this.options.logger.info || Util.NOP,
warn : this.options.logger.warn || Util.NOP,
error: this.options.logger.error || Util.NOP
};
this.logger.log = this.logger.log.bind(this.options.logger);
this.logger.info = this.logger.info.bind(this.options.logger);
this.logger.warn = this.logger.warn.bind(this.options.logger);
this.logger.error = this.logger.error.bind(this.options.logger);
this.logger.log('[Function:(AMA)Client Constructor]' +
(options ? '\noptions:' + JSON.stringify(options) : ''));
this.initOptions(options);
this.storage = this.options.storage || new Storage(options.appId);
this.storage.reload(()=>{
this.initStorage(callback);
});
}
initStorage(callback) {
this.storage.setLogger(this.logger);
this.storage.set(
StorageKeys.GLOBAL_ATTRIBUTES,
Util.mergeObjects(this.options.globalAttributes,
this.storage.get(StorageKeys.GLOBAL_ATTRIBUTES) || {})
);
this.storage.set(
StorageKeys.GLOBAL_METRICS,
Util.mergeObjects(this.options.globalMetrics,
this.storage.get(StorageKeys.GLOBAL_METRICS) || {})
);
this.storage.set(StorageKeys.CLIENT_ID, Constants.deviceId);
this.StorageKeys = {
'EVENTS' : 'AWSMobileAnalyticsEventStorage',
'BATCHES' : 'AWSMobileAnalyticsBatchStorage',
'BATCH_INDEX': 'AWSMobileAnalyticsBatchIndexStorage'
};
this.outputs = {};
this.outputs.MobileAnalytics = new AWS.MobileAnalytics(this.options.clientOptions);
this.outputs.timeoutReference = null;
this.outputs.batchesInFlight = {};
this.outputs.events = this.storage.get(this.StorageKeys.EVENTS) || [];
this.outputs.batches = this.storage.get(this.StorageKeys.BATCHES) || {};
this.outputs.batchIndex = this.storage.get(this.StorageKeys.BATCH_INDEX) || [];
if (this.options.autoSubmitEvents) {
this.submitEvents();
}
callback();
}
initOptions(options) {
if (options.appId === undefined) {
this.logger.error('AMA.Client must be initialized with an appId');
return null; //No need to run rest of init since appId is required
}
if (options.platform === undefined) {
this.logger.error('AMA.Client must be initialized with a platform');
}
this.options.apiVersion = this.options.apiVersion || '2014-06-05';
this.options.provider = this.options.provider || AWS.config.credentials;
this.options.autoSubmitEvents = options.autoSubmitEvents !== false;
this.options.autoSubmitInterval = this.options.autoSubmitInterval || 10000;
this.options.batchSizeLimit = this.options.batchSizeLimit || 256000;
this.options.submitCallback = this.options.submitCallback || Util.NOP;
this.options.globalAttributes = this.options.globalAttributes || {};
this.options.globalMetrics = this.options.globalMetrics || {};
this.options.clientOptions = this.options.clientOptions || {};
this.options.clientOptions.provider = this.options.clientOptions.provider || this.options.provider;
this.options.clientOptions.apiVersion = this.options.clientOptions.apiVersion || this.options.apiVersion;
this.options.clientOptions.correctClockSkew = this.options.clientOptions.correctClockSkew !== false;
this.options.clientOptions.retryDelayOptions = this.options.clientOptions.retryDelayOptions || {};
this.options.clientOptions.retryDelayOptions.base = this.options.clientOptions.retryDelayOptions.base || 3000;
this.options.clientContext = this.options.clientContext || {
'client' : {
'client_id' : Constants.deviceId,
'app_title' : this.options.appTitle,
'app_version_name': this.options.appVersionName,
'app_version_code': this.options.appVersionCode,
'app_package_name': this.options.appPackageName
},
'env' : {
'platform' : this.options.platform,
'platform_version': this.options.platformVersion,
'model' : this.options.model,
'make' : this.options.make,
'locale' : this.options.locale
},
'services': {
'mobile_analytics': {
'app_id' : this.options.appId,
'sdk_name' : 'aws-sdk-mobile-analytics-js',
'sdk_version': '0.9.2' + ':' + AWS.VERSION
}
},
'custom' : {}
};
}
validateEvent(event) {
let invalidMetrics = [];
function customNameErrorFilter(name) {
if (name.length === 0) {
return true;
}
return name.length > 50;
}
function customAttrValueErrorFilter(name) {
return event.attributes[name] && event.attributes[name].length > 200;
}
function validationError(errorMsg) {
this.logger.error(errorMsg);
return null;
}
invalidMetrics = Object.keys(event.metrics).filter(function (metricName) {
return typeof event.metrics[metricName] !== 'number';
});
if (event.version !== 'v2.0') {
return validationError('Event must have version v2.0');
}
if (typeof event.eventType !== 'string') {
return validationError('Event Type must be a string');
}
if (invalidMetrics.length > 0) {
return validationError('Event Metrics must be numeric (' + invalidMetrics[0] + ')');
}
if (Object.keys(event.metrics).length + Object.keys(event.attributes).length > 40) {
return validationError('Event Metric and Attribute Count cannot exceed 40');
}
if (Object.keys(event.attributes).filter(customNameErrorFilter).length) {
return validationError('Event Attribute names must be 1-50 characters');
}
if (Object.keys(event.metrics).filter(customNameErrorFilter).length) {
return validationError('Event Metric names must be 1-50 characters');
}
if (Object.keys(event.attributes).filter(customAttrValueErrorFilter).length) {
return validationError('Event Attribute values cannot be longer than 200 characters');
}
return event;
}
/**
* AMA.Client.createEvent
* @param {string} eventType - Custom Event Type to be displayed in Console
* @param {AMA.Session} session - Session Object (required for use within console)
* @param {string} session.id - Identifier for current session
* @param {string} session.startTimestamp - Timestamp that indicates the start of the session
* @param [attributes=] - Custom attributes
* @param [metrics=] - Custom metrics
* @returns {AMA.Event}
*/
createEvent(eventType, session, attributes, metrics) {
this.logger.log('[Function:(AMA.Client).createEvent]' +
(eventType ? '\neventType:' + eventType : '') +
(session ? '\nsession:' + session : '') +
(attributes ? '\nattributes:' + JSON.stringify(attributes) : '') +
(metrics ? '\nmetrics:' + JSON.stringify(metrics) : ''));
attributes = attributes || {};
metrics = metrics || {};
Util.mergeObjects(attributes, this.options.globalAttributes);
Util.mergeObjects(metrics, this.options.globalMetrics);
Object.keys(attributes).forEach(function (name) {
if (typeof attributes[name] !== 'string') {
try {
attributes[name] = JSON.stringify(attributes[name]);
} catch (e) {
this.logger.warn('Error parsing attribute ' + name);
}
}
});
let event = {
eventType : eventType,
timestamp : new Date().toISOString(),
session : {
id : session.id,
startTimestamp: session.startTimestamp
},
version : 'v2.0',
attributes: attributes,
metrics : metrics
};
if (session.stopTimestamp) {
event.session.stopTimestamp = session.stopTimestamp;
event.session.duration = new Date(event.stopTimestamp).getTime() - new Date(event.startTimestamp).getTime();
}
return this.validateEvent(event);
}
/**
* AMA.Client.pushEvent
* @param {AMA.Event} event - event to be pushed onto queue
* @returns {int} Index of event in outputs.events
*/
pushEvent(event) {
if (!event) {
return -1;
}
this.logger.log('[Function:(AMA.Client).pushEvent]' +
(event ? '\nevent:' + JSON.stringify(event) : ''));
//Push adds to the end of array and returns the size of the array
let eventIndex = this.outputs.events.push(event);
this.storage.set(this.StorageKeys.EVENTS, this.outputs.events);
return (eventIndex - 1);
}
/**
* Helper to record events, will automatically submit if the events exceed batchSizeLimit
* @param {string} eventType - Custom event type name
* @param {AMA.Session} session - Session object
* @param {AMA.Client.Attributes} [attributes=] - Custom attributes
* @param {AMA.Client.Metrics} [metrics=] - Custom metrics
* @returns {AMA.Event} The event that was recorded
*/
recordEvent(eventType, session, attributes, metrics) {
this.logger.log('[Function:(AMA.Client).recordEvent]' +
(eventType ? '\neventType:' + eventType : '') +
(session ? '\nsession:' + session : '') +
(attributes ? '\nattributes:' + JSON.stringify(attributes) : '') +
(metrics ? '\nmetrics:' + JSON.stringify(metrics) : ''));
let index, event = this.createEvent(eventType, session, attributes, metrics);
if (event) {
index = this.pushEvent(event);
if (Util.getRequestBodySize(this.outputs.events) >= this.options.batchSizeLimit) {
this.submitEvents();
}
return this.outputs.events[index];
}
return null;
}
/**
* recordMonetizationEvent
* @param session
* @param {Object} monetizationDetails - Details about Monetization Event
* @param {string} monetizationDetails.currency - ISO Currency of event
* @param {string} monetizationDetails.productId - Product Id of monetization event
* @param {number} monetizationDetails.quantity - Quantity of product in transaction
* @param {string|number} monetizationDetails.price - Price of product either ISO formatted string, or number
* with associated ISO Currency
* @param {AMA.Client.Attributes} [attributes=] - Custom attributes
* @param {AMA.Client.Metrics} [metrics=] - Custom metrics
* @returns {event} The event that was recorded
*/
recordMonetizationEvent(session, monetizationDetails, attributes, metrics) {
this.logger.log('[Function:(AMA.Client).recordMonetizationEvent]' +
(session ? '\nsession:' + session : '') +
(monetizationDetails ? '\nmonetizationDetails:' + JSON.stringify(monetizationDetails) : '') +
(attributes ? '\nattributes:' + JSON.stringify(attributes) : '') +
(metrics ? '\nmetrics:' + JSON.stringify(metrics) : ''));
attributes = attributes || {};
metrics = metrics || {};
attributes._currency = monetizationDetails.currency || attributes._currency;
attributes._product_id = monetizationDetails.productId || attributes._product_id;
metrics._quantity = monetizationDetails.quantity || metrics._quantity;
if (typeof monetizationDetails.price === 'number') {
metrics._item_price = monetizationDetails.price || metrics._item_price;
} else {
attributes._item_price_formatted = monetizationDetails.price || attributes._item_price_formatted;
}
return this.recordEvent('_monetization.purchase', session, attributes, metrics);
}
/**
* submitEvents
* @param {Object} [options=] - options for submitting events
* @param {Object} [options.clientContext=this.options.clientContext] - clientContext to submit with defaults
* to options.clientContext
* @param {SubmitCallback} [options.submitCallback=this.options.submitCallback] - Callback function that is executed
* when events are successfully
* submitted
* @returns {Array} Array of batch indices that were submitted
*/
submitEvents(options) {
options = options || {};
options.submitCallback = options.submitCallback || this.options.submitCallback;
this.logger.log('[Function:(AMA.Client).submitEvents]' +
(options ? '\noptions:' + JSON.stringify(options) : ''));
if (this.options.autoSubmitEvents) {
clearTimeout(this.outputs.timeoutReference);
this.outputs.timeoutReference = setTimeout(this.submitEvents.bind(this), this.options.autoSubmitInterval);
}
let warnMessage;
//Get distribution of retries across clients by introducing a weighted rand.
//Probability will increase over time to an upper limit of 60s
if (this.outputs.isThrottled && this.throttlingSuppressionFunction() < Math.random()) {
warnMessage = 'Prevented submission while throttled';
} else if (Object.keys(this.outputs.batchesInFlight).length > 0) {
warnMessage = 'Prevented submission while batches are in flight';
} else if (this.outputs.batches.length === 0 && this.outputs.events.length === 0) {
warnMessage = 'No batches or events to be submitted';
} else if (this.outputs.lastSubmitTimestamp && Util.timestamp() - this.outputs.lastSubmitTimestamp < 1000) {
warnMessage = 'Prevented multiple submissions in under a second';
}
if (warnMessage) {
this.logger.warn(warnMessage);
return [];
}
this.generateBatches();
this.outputs.lastSubmitTimestamp = Util.timestamp();
if (this.outputs.isThrottled) {
//Only submit the first batch if throttled
this.logger.warn('Is throttled submitting first batch');
options.batchId = this.outputs.batchIndex[0];
return [this.submitBatchById(options)];
}
return this.submitAllBatches(options);
}
throttlingSuppressionFunction(timestamp) {
timestamp = timestamp || Util.timestamp();
return Math.pow(timestamp - this.outputs.lastSubmitTimestamp, 2) / Math.pow(60000, 2);
}
generateBatches() {
while (this.outputs.events.length > 0) {
let lastIndex = this.outputs.events.length;
this.logger.log(this.outputs.events.length + ' events to be submitted');
while (lastIndex > 1 &&
Util.getRequestBodySize(this.outputs.events.slice(0, lastIndex)) > this.options.batchSizeLimit) {
this.logger.log('Finding Batch Size (' + this.options.batchSizeLimit + '): ' + lastIndex + '(' +
Util.getRequestBodySize(this.outputs.events.slice(0, lastIndex)) + ')');
lastIndex -= 1;
}
if (this.persistBatch(this.outputs.events.slice(0, lastIndex))) {
//Clear event queue
this.outputs.events.splice(0, lastIndex);
this.storage.set(this.StorageKeys.EVENTS, this.outputs.events);
}
}
}
persistBatch(eventBatch) {
this.logger.log(eventBatch.length + ' events in batch');
if (Util.getRequestBodySize(eventBatch) < 512000) {
let batchId = Util.GUID();
//Save batch so data is not lost.
this.outputs.batches[batchId] = eventBatch;
this.storage.set(this.StorageKeys.BATCHES, this.outputs.batches);
this.outputs.batchIndex.push(batchId);
this.storage.set(this.StorageKeys.BATCH_INDEX, this.outputs.batchIndex);
return true;
}
this.logger.error('Events too large');
return false;
}
submitAllBatches(options) {
options.submitCallback = options.submitCallback || this.options.submitCallback;
this.logger.log('[Function:(AMA.Client).submitAllBatches]' +
(options ? '\noptions:' + JSON.stringify(options) : ''));
let indices = [],
that = this;
this.outputs.batchIndex.forEach(function (batchIndex) {
options.batchId = batchIndex;
options.clientContext = options.clientContext || that.options.clientContext;
if (!that.outputs.batchesInFlight[batchIndex]) {
indices.push(that.submitBatchById(options));
}
});
return indices;
}
submitBatchById(options) {
if (typeof(options) !== 'object' || !options.batchId) {
this.logger.error('Invalid Options passed to submitBatchById');
return;
}
options.submitCallback = options.submitCallback || this.options.submitCallback;
this.logger.log('[Function:(AMA.Client).submitBatchById]' +
(options ? '\noptions:' + JSON.stringify(options) : ''));
let eventBatch = {
'events' : this.outputs.batches[options.batchId],
'clientContext': JSON.stringify(options.clientContext || this.options.clientContext)
};
this.outputs.batchesInFlight[options.batchId] = Util.timestamp();
this.outputs.MobileAnalytics.putEvents(eventBatch,
this.handlePutEventsResponse(options.batchId, options.submitCallback));
return options.batchId;
}
handlePutEventsResponse(batchId, callback) {
const NON_RETRYABLE_EXCEPTIONS = ['BadRequestException', 'SerializationException', 'ValidationException'];
let self = this;
return function (err, data) {
let clearBatch = true,
wasThrottled = self.outputs.isThrottled;
if (err) {
self.logger.error(err, data);
if (err.statusCode === undefined || err.statusCode === 400) {
if (NON_RETRYABLE_EXCEPTIONS.indexOf(err.code) < 0) {
clearBatch = false;
}
self.outputs.isThrottled = err.code === 'ThrottlingException';
if (self.outputs.isThrottled) {
self.logger.warn('Application is currently throttled');
}
}
} else {
self.logger.info('Events Submitted Successfully');
self.outputs.isThrottled = false;
}
if (clearBatch) {
self.clearBatchById(batchId);
}
delete self.outputs.batchesInFlight[batchId];
callback(err, data, batchId);
if (wasThrottled && !self.outputs.isThrottled) {
self.logger.warn('Was throttled flushing remaining batches', callback);
self.submitAllBatches({
submitCallback: callback
});
}
};
}
clearBatchById(batchId) {
this.logger.log('[Function:(AMA.Client).clearBatchById]' +
(batchId ? '\nbatchId:' + batchId : ''));
if (this.outputs.batchIndex.indexOf(batchId) !== -1) {
delete this.outputs.batches[batchId];
this.outputs.batchIndex.splice(this.outputs.batchIndex.indexOf(batchId), 1);
// Persist latest batches / events
this.storage.set(this.StorageKeys.BATCH_INDEX, this.outputs.batchIndex);
this.storage.set(this.StorageKeys.BATCHES, this.outputs.batches);
}
}
} |
/* @flow */
const { createAction } = require('redux-actions')
const { get_body } = require('app/http')
const { format } = require('app/transform_dated')
const { compose, concat, reduce, map, negate, lensPath, flip, over, prop,
view, set, append, identity, objOf, propOr, mergeAll, converge, unapply,
assoc, pick, cond, equals, T, sortBy } =
require('ramda')
const { plus, plus2 } = require('app/money_arith')
const { S } = require('sanctuary')
const RECEIVED = 'RECEIVED_REPORT_DATA'
const { PATH_UPDATE } = require('../../../shared/redux/modules/route.js')
import type { Action, Reducer } from 'redux'
import type { Payment } from './payment_defaults.js'
const initialState = {}
type State = {}
type Check = (x: any) => (p: Payment) => boolean
const reducer
: Reducer<State, Action>
= (state = {}, { type, payload }) => {
switch (type) {
case RECEIVED:
return payload
case PATH_UPDATE:
return initialState
default:
return state
}
}
export default reducer
const paying_in_url = concat('/api/payingin/')
const non_cheque_url = ({ type, before, after }) =>
`/api/noncheque/${type}?before=${before}&after=${after}`
const payments = lensPath(['payments'])
const memberL = lensPath(['member'])
const dateL = lensPath(['date'])
const name = lensPath(['surname'])
const balance = lensPath(['balance'])
const make_balances = (check) => (balances, charge) => {
const { amount, category, member, date, last_name } = charge
const curr = lensPath([member])
const curr_val = compose
( curr
, lensPath([check(charge) ? 'payments' : category])
)
const curr_bal = compose(curr, balance)
const update_balance = parity =>
over(curr_val, plus(amount), over(curr_bal, plus(parity(amount)), balances))
const credit = () => update_balance(identity)
const debit = () => update_balance(negate)
const add_member_details =
compose(set(name, last_name), set(dateL, date), set(memberL, member))
const reset_current = set(curr, {})
const add_payment = (payment) => over(payments, append(payment), balances)
const transfer_payment = compose(reset_current, add_payment)
const clear_if_zerod = cond(
[ [compose(equals(0), view(curr_bal)), reset_current], [T, identity] ]
)
return check(charge)
? transfer_payment(add_member_details(view(curr, credit())), balances)
: clear_if_zerod
( category === 'payment'
? credit()
: debit()
)
}
const make_payments = (check) =>
compose
( over(payments, map(format))
, pick(['payments'])
, reduce(make_balances(check), { payments: [] })
)
const make_total = type =>
compose(objOf(type), reduce(plus2, 0), map(propOr(0, type)))
const make_totals = converge
( unapply(mergeAll)
, map
( make_total
, [ 'subscription', 'donation', 'event', 'payment', 'payments', 'balance' ]
)
)
const add_totals =
S(flip(assoc('totals')), compose(make_totals, prop('payments')))
const sails_date_string = string => new Date(string).setHours(12)
const paying_in_check = ref => ({ reference, category }) =>
category === 'payment' && ref === reference
const non_cheque_check =
({ type: t, before, after }) => ({ type, category, date }) =>
category === 'payment' && t === type.toLowerCase()
&& sortBy(sails_date_string, [after, date, before])[1] === date
// link to issue on discussion around alternatives to breaking encapsulation
export const prepare
: (f: Check) => (a: any) => (ps: Payment[]) => {}
= check => payload =>
compose(add_totals, make_payments(check(payload)))
export const receive
: (f: (x: any) => string) => (g: Check) => Function
= make_url => check =>
createAction
( RECEIVED
, (payload) => compose
( map(prepare(check)(payload))
, get_body
, make_url
)(payload)
)
export const receive_paying_in = receive(paying_in_url)(paying_in_check)
export const receive_non_cheque = receive(non_cheque_url)(non_cheque_check)
|
const { flattenArrayToString } = require('../generator-utils');
function UULangCompiler() {
function compile(ast) {
if (ast.typeName !== 'Program')
throw new TypeError('Compilers.UULangCompiler.compile: First node must be of typeName `Program`');
return ast;
}
return {
compile
};
}
module.exports = {
UULangCompiler
};
|
var should = require('should');
var sinon = require('sinon');
var fs = require('fs');
var path = require('path');
var rimraf = require('rimraf');
var touch = require('touch');
var regen = require('../src/index');
describe('Integration', function() {
before(cleanup);
after(cleanup);
it('builds all destination files from scratch', function(done) {
rebuild('initial', function() {
checkContents('./tmp/one.rand', 'initial');
checkContents('./tmp/folder/two.rand', 'initial');
done();
});
});
it('does nothing if rebuilding straight away', function(done) {
rebuild('round two', function() {
checkContents('./tmp/one.rand', 'initial');
checkContents('./tmp/folder/two.rand', 'initial');
done();
});
});
it('rebuilds files if the source file has changed', function(done) {
var futureDate = new Date().getTime() + 1000;
touch.sync(path.join(__dirname, './data/one.txt'), {time: futureDate});
rebuild('round three', function() {
checkContents('./tmp/one.rand', 'round three');
checkContents('./tmp/folder/two.rand', 'initial');
done();
});
});
});
function cleanup(done) {
rimraf(path.join(__dirname, 'tmp'), done);
}
function rebuild(contents, done) {
regen({
cwd: path.join(__dirname, 'data'),
src: '**/*.txt',
dest: '../tmp/$path/$name.rand',
process: 'echo "' + contents +'" > $dest'
}, done);
}
function checkContents(file, contents) {
var read = fs.readFileSync(path.join(__dirname, file));
read.toString().should.include(contents);
}
|
(function () {
'use strict';
angular.module('blocks.auth')
.factory('loginRedirect', loginRedirect)
.config(configureLoginRedirect);
function loginRedirect($q, $injector) {
return {
responseError: responseError
};
function responseError(response) {
if (response.status === 401) {
var $state = $injector.get('$state');
$state.go('login');
}
return $q.reject(response);
}
}
function configureLoginRedirect($httpProvider) {
$httpProvider.interceptors.push('loginRedirect');
}
})();
|
/* jshint node: true */
/* jshint sub: true */
/* global window,document, $,alert,history */
"use strict";
if (typeof(window) === 'undefined')
{
console.log('pureworld in node/iojs');
global.window = global;
}
else
{
console.log('pureworld in browser');
}
// unit :: a -> IO a
var unit = function(x)
{
return function()
{
return x;
};
};
// bind :: IO a -> (a -> IO b) -> IO b
var bind = function(x, y)
{
return function()
{
return y(x())();
};
};
// seq :: IO a -> IO b -> IO b
var seq = function(x, y)
{
return function()
{
return x(), y();
};
};
var action = function(x)
{
return function(y)
{
return y ? action(seq(x, y)) : x();
};
};
var wrap = function(f)
{
return function(x)
{
return action(function()
{
return f(x);
});
};
};
var log = wrap(console.log);
var pureworld = {
unit: unit,
bind: bind,
seq: seq,
action: action,
wrap: wrap,
log: log
};
// -- runtime --
Object.defineProperties(window,
{
world:
{
set: function(w)
{
return w();
}
}
});
module.exports = pureworld; |
var express = require('express');
var router = express.Router();
var videos = require('../../models/videos');
router.get('/', function(req, res) {
res.render('APP/uploadVideos');
});
router.get('/app', function(req, res) {
res.render('APP/app');
});
router.get('/myUploads', function(req, res) {
res.render('APP/myUploads');
});
router.get('/playlistUpdate', function(req, res) {
res.render('APP/playlistUpdate');
});
router.get('/uploadVideos', function(req, res) {
res.render('APP/uploadVideos');
});
router.get('/search', function(req, res) {
res.render('APP/search');
});
router.get('/analyticsCodelab', function(req, res) {
res.render('APP/analyticsCodelab');
});
router.get('/oauth2callback', function(req, res) {
var resJson = {
status : 'OK',
message : 'Yapi'
};
res.send(resJson);
});
router.get('/oauth2logout', function(req, res) {
var resJson = {
status : 'OK',
message : 'Yapi'
};
res.send(resJson);
});
router.post('/controllerCheck', function(req, res) {
var resJson = {
status : 'OK',
message : 'Yapi'
};
res.send(resJson);
});
router.post('/modelCheck', function(req, res) {
videos.check(req.body, function(err, resModel) {
if (err) res.send(err);
else res.send(resModel);
});
});
module.exports = router; |
'use strict';
import React from 'react/addons';
import {Link} from 'react-router';
let Footer = React.createClass({
render() {
return (
<div id="envuelve_pie" style={this.props.style}>
<div className="footer">
<div className="container-fluid">
<div className="pull-right">
<Link to="/contacto">Contacto</Link>
</div>
</div>
</div>
</div>
);
}
});
module.exports = Footer;
|
"use strict";
/* global describe, it */
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}], no-void: 0 */
import { expect } from "chai";
import isFunction from "lodash/isFunction";
import actionFn from "../src/actionFn";
function fetchSuccess() {
return new Promise(function(resolve) {
resolve({ msg: "hello" });
});
}
function getState() {
return {
test: { loading: false, syncing: false, sync: false, data: {} }
};
}
const ERROR = new Error("Error");
function fetchFail() {
return new Promise(function(resolve, reject) {
reject(ERROR);
});
}
function transformer(data) {
return data;
}
const ACTIONS = {
actionFetch: "actionFetch",
actionSuccess: "actionSuccess",
actionFail: "actionFail",
actionReset: "actionReset",
actionCache: "actionCache"
};
describe("actionFn", function() {
it("check null params", function() {
const api = actionFn();
expect(isFunction(api)).to.be.true;
});
it("check sync method", function() {
let executeCounter = 0;
const api = actionFn("/test", "test", null, ACTIONS, {
transformer,
fetch: () => {
executeCounter += 1;
return fetchSuccess();
}
});
const async1 = new Promise(resolve => {
const initialState = getState();
initialState.test.sync = true;
api.sync(resolve)(
function() {},
() => initialState
);
expect(executeCounter).to.be.eql(0);
});
const expectedEvent = [
{
type: ACTIONS.actionFetch,
syncing: true,
request: { pathvars: undefined, params: {} }
},
{
type: ACTIONS.actionSuccess,
data: { msg: "hello" },
origData: { msg: "hello" },
syncing: false,
request: { pathvars: undefined, params: {} }
}
];
const async2 = new Promise(resolve => {
api.sync(resolve)(msg => {
expect(expectedEvent).to.have.length.above(0);
const exp = expectedEvent.shift();
expect(msg).to.eql(exp);
}, getState);
}).then(() => {
expect(executeCounter).to.be.eql(1);
expect(expectedEvent).to.have.length(0);
});
return Promise.all([async1, async2]);
});
it("check request method", function() {
let urlFetch;
let paramsFetch;
const api = actionFn("/test/:id", "test", null, ACTIONS, {
transformer,
fetch: (url, params) => {
urlFetch = url;
paramsFetch = params;
return fetchSuccess();
}
});
const async = api.request({ id: 2 }, { hello: "world" });
expect(async).to.be.an.instanceof(Promise);
return async.then(data => {
expect(data).to.eql({ msg: "hello" });
expect(urlFetch).to.eql("/test/2");
expect(paramsFetch).to.eql({ hello: "world" });
});
});
it("check normal usage", function() {
const api = actionFn("/test", "test", null, ACTIONS, {
transformer,
fetch: fetchSuccess
});
expect(api.reset()).to.eql({ type: ACTIONS.actionReset });
const expectedEvent = [
{
type: ACTIONS.actionFetch,
syncing: false,
request: { pathvars: undefined, params: {} }
},
{
type: ACTIONS.actionSuccess,
data: { msg: "hello" },
origData: { msg: "hello" },
syncing: false,
request: { pathvars: undefined, params: {} }
}
];
return new Promise(resolve => {
const action = api(resolve);
expect(isFunction(action)).to.be.true;
function dispatch(msg) {
expect(expectedEvent).to.have.length.above(0);
const exp = expectedEvent.shift();
expect(msg).to.eql(exp);
}
action(dispatch, getState);
}).then(() => {
expect(expectedEvent).to.have.length(0);
});
});
it("check reset helper with mutation", function() {
const api = actionFn("/test", "test", null, ACTIONS, {
transformer,
fetch: fetchSuccess
});
expect(api.reset()).to.eql({ type: ACTIONS.actionReset });
expect(api.reset("sync")).to.eql({
type: ACTIONS.actionReset,
mutation: "sync"
});
expect(api.reset("other")).to.eql({ type: ACTIONS.actionReset });
});
it("check fail fetch", function() {
const api = actionFn("/test", "test", null, ACTIONS, {
transformer,
fetch: fetchFail
});
const expectedEvent = [
{
type: ACTIONS.actionFetch,
syncing: false,
request: { pathvars: undefined, params: {} }
},
{
type: ACTIONS.actionFail,
error: ERROR,
syncing: false,
request: { pathvars: undefined, params: {} }
}
];
function dispatch(msg) {
expect(expectedEvent).to.have.length.above(0);
const exp = expectedEvent.shift();
expect(msg.type).to.eql(exp.type);
expect(msg.syncing).to.eql(exp.syncing);
expect(msg.request).to.eql(exp.request);
expect(msg.error).to.eql(exp.error);
}
return new Promise(resolve => {
api(resolve)(dispatch, getState);
}).then(
() => {
expect(expectedEvent).to.have.length(0);
},
err => expect(null).to.eql(err)
);
});
it("check options param", function() {
let callOptions = 0;
let checkOptions = null;
const api = actionFn(
"/test/:id",
"test",
function(url, params, _getState) {
expect(_getState).to.exist;
expect(getState === _getState).to.be.true;
callOptions += 1;
return { ...params, test: 1 };
},
ACTIONS,
{
transformer,
fetch(url, opts) {
checkOptions = opts;
return fetchSuccess();
}
}
);
function dispatch() {}
return new Promise(resolve => {
api("", { params: 1 }, resolve)(dispatch, getState);
expect(callOptions).to.eql(1);
expect(checkOptions).to.eql({ params: 1, test: 1 });
});
});
it("check server mode", function() {
function getServerState() {
return {
test: { loading: false, syncing: false, sync: true, data: {} }
};
}
const api = actionFn("/test/:id", "test", null, ACTIONS, {
transformer,
fetch: fetchSuccess,
holder: {
server: true
}
});
const expectedEvent = [
{
type: ACTIONS.actionFetch,
syncing: true,
request: { pathvars: undefined, params: {} }
},
{
type: ACTIONS.actionSuccess,
syncing: false,
data: { msg: "hello" },
origData: { msg: "hello" },
request: { pathvars: undefined, params: {} }
}
];
return new Promise(resolve => {
api.sync(resolve)(function(msg) {
expect(expectedEvent).to.have.length.above(0);
const exp = expectedEvent.shift();
expect(msg).to.eql(exp);
}, getServerState);
}).then(() => {
expect(expectedEvent).to.have.length(0);
});
});
it("check broadcast option", function() {
const BROADCAST_ACTION = "BROADCAST_ACTION";
const expectedEvent = [
{
type: ACTIONS.actionFetch,
syncing: false,
request: { pathvars: undefined, params: {} }
},
{
type: ACTIONS.actionSuccess,
data: { msg: "hello" },
origData: { msg: "hello" },
syncing: false,
request: { pathvars: undefined, params: {} }
},
{
type: BROADCAST_ACTION,
data: { msg: "hello" },
origData: { msg: "hello" },
request: { pathvars: undefined, params: {} }
}
];
const meta = {
transformer,
fetch: fetchSuccess,
broadcast: [BROADCAST_ACTION]
};
const api = actionFn("/test/:id", "test", null, ACTIONS, meta);
return new Promise(resolve => {
api(resolve)(function(msg) {
expect(expectedEvent).to.have.length.above(0);
const exp = expectedEvent.shift();
expect(msg).to.eql(exp);
}, getState);
}).then(() => {
expect(expectedEvent).to.have.length(0);
});
});
it("check validation with request method", function() {
let expData;
let counter = 0;
const meta = {
transformer,
fetch: fetchSuccess,
validation(data, cb) {
counter += 1;
expData = data;
cb();
}
};
const api = actionFn("/test/:id", "test", null, ACTIONS, meta);
return api.request({ id: 1 }).then(data => {
expect(data).to.eql({ msg: "hello" });
expect(counter).to.eql(1);
expect(expData).to.eql({ msg: "hello" });
});
});
it("check success validation", function() {
let expData;
let counter = 0;
const meta = {
transformer,
fetch: fetchSuccess,
validation(data, cb) {
counter += 1;
expData = data;
cb();
}
};
const expectedEvent = [
{
type: ACTIONS.actionFetch,
syncing: false,
request: { pathvars: undefined, params: {} }
},
{
type: ACTIONS.actionSuccess,
data: { msg: "hello" },
origData: { msg: "hello" },
syncing: false,
request: { pathvars: undefined, params: {} }
}
];
const api = actionFn("/test/:id", "test", null, ACTIONS, meta);
return new Promise(resolve => {
api(resolve)(function(msg) {
expect(expectedEvent).to.have.length.above(0);
const exp = expectedEvent.shift();
expect(msg).to.eql(exp);
}, getState);
}).then(() => {
expect(expectedEvent).to.have.length(0);
expect(counter).to.eql(1);
expect(expData).to.eql({ msg: "hello" });
});
});
it("check unsuccess validation", function() {
let expData;
let counter = 0;
const meta = {
transformer,
fetch: fetchSuccess,
validation(data, cb) {
counter += 1;
expData = data;
cb("invalid");
}
};
const expectedEvent = [
{
type: ACTIONS.actionFetch,
syncing: false,
request: { pathvars: undefined, params: {} }
},
{
type: ACTIONS.actionFail,
error: "invalid",
syncing: false,
request: { pathvars: undefined, params: {} }
}
];
const api = actionFn("/test/:id", "test", null, ACTIONS, meta);
return new Promise(resolve => {
api(resolve)(function(msg) {
expect(expectedEvent).to.have.length.above(0);
const exp = expectedEvent.shift();
expect(msg.type).to.eql(exp.type);
expect(msg.syncing).to.eql(exp.syncing);
expect(msg.request).to.eql(exp.request);
expect(msg.error).to.eql(exp.error);
}, getState);
}).then(
() => {
expect(expectedEvent).to.have.length(0);
expect(counter).to.eql(1);
expect(expData).to.eql({ msg: "hello" });
},
err => expect(null).to.eql(err)
);
});
it("check postfetch option", function() {
let expectedOpts;
const meta = {
transformer,
fetch: fetchSuccess,
postfetch: [
function(opts) {
expectedOpts = opts;
opts.dispatch({ type: "One", data: opts.data });
},
function(opts) {
opts.dispatch({ type: "Two", data: opts.data });
}
],
actions: { hello: "a" }
};
const api = actionFn("/test/:id", "test", null, ACTIONS, meta);
const expectedEvent = [
{
type: ACTIONS.actionFetch,
syncing: false,
request: { pathvars: undefined, params: {} }
},
{
type: ACTIONS.actionSuccess,
data: { msg: "hello" },
origData: { msg: "hello" },
syncing: false,
request: { pathvars: undefined, params: {} }
},
{
type: "One",
data: { msg: "hello" }
},
{
type: "Two",
data: { msg: "hello" }
}
];
function dispatch(msg) {
expect(expectedEvent).to.have.length.above(0);
const exp = expectedEvent.shift();
expect(msg).to.eql(exp);
}
return new Promise(resolve => {
api(resolve)(dispatch, getState);
}).then(() => {
expect(expectedOpts).to.exist;
expect(expectedOpts).to.include.keys(
"data",
"getState",
"dispatch",
"actions",
"request"
);
expect(expectedOpts.getState).to.eql(getState);
expect(expectedOpts.dispatch).to.eql(dispatch);
expect(expectedOpts.actions).to.eql({ hello: "a" });
expect(expectedOpts.request).to.eql({ params: {}, pathvars: void 0 });
});
});
it("check prefetch option", function() {
const checkPrefetch = [];
const meta = {
transformer,
fetch: fetchSuccess,
prefetch: [
function(opts, cb) {
checkPrefetch.push(["one", opts]);
cb();
},
function(opts, cb) {
checkPrefetch.push(["two", opts]);
cb();
}
]
};
const requestOptions = { pathvars: undefined, params: {} };
const api = actionFn("/test/:id", "test", null, ACTIONS, meta);
const expectedEvent = [
{
type: ACTIONS.actionFetch,
syncing: false,
request: requestOptions
},
{
type: ACTIONS.actionSuccess,
data: { msg: "hello" },
origData: { msg: "hello" },
syncing: false,
request: requestOptions
}
];
function dispatch(msg) {
expect(expectedEvent).to.have.length.above(0);
const exp = expectedEvent.shift();
expect(msg).to.eql(exp);
}
const expOpts = {
dispatch,
getState,
request: requestOptions,
actions: undefined,
prefetch: meta.prefetch
};
return new Promise(resolve => {
api(resolve)(dispatch, getState);
}).then(
() => {
expect(expectedEvent).to.have.length(0);
expect(checkPrefetch).to.eql([
["one", expOpts],
["two", expOpts]
]);
},
err => expect(null).to.eql(err)
);
});
it("check incorrect helpers name", function() {
expect(() =>
actionFn("/test/:id", "test", null, ACTIONS, {
helpers: {
reset() {}
}
})
).to.throw(
Error,
'Helper name: "reset" for endpoint "test" has been already reserved'
);
expect(() =>
actionFn("/test/:id", "test", null, ACTIONS, {
helpers: {
sync() {}
}
})
).to.throw(
Error,
'Helper name: "sync" for endpoint "test" has been already reserved'
);
});
it("check that helpers returns Promise", function() {
const api = actionFn("/test/:id", "test", null, ACTIONS, {
transformer,
fetch: fetchSuccess,
helpers: {
test: () => cb => cb(null, [{ id: 1 }, { async: true }])
}
});
const result = api.test()(() => {}, getState);
expect(result).to.be.an.instanceof(Promise);
});
it("check helpers with async functionality", function() {
const meta = {
transformer,
fetch(url, opts) {
return new Promise(resolve => resolve({ url, opts }));
},
helpers: {
asyncSuccess: () => cb => cb(null, [{ id: 1 }, { async: true }]),
asyncFail: () => cb => cb("Error")
}
};
const api = actionFn("/test/:id", "test", null, ACTIONS, meta);
const expectedEvent1 = [
{
type: ACTIONS.actionFetch,
syncing: false,
request: { pathvars: { id: 1 }, params: { async: true } }
},
{
type: ACTIONS.actionSuccess,
syncing: false,
data: { url: "/test/1", opts: { async: true } },
origData: { url: "/test/1", opts: { async: true } },
request: { pathvars: { id: 1 }, params: { async: true } }
}
];
const wait1 = new Promise(resolve => {
api.asyncSuccess(resolve)(function(msg) {
expect(expectedEvent1).to.have.length.above(0);
const exp = expectedEvent1.shift();
expect(msg).to.eql(exp);
}, getState);
});
let errorMsg;
const wait2 = new Promise(resolve => {
api.asyncFail(function(err) {
errorMsg = err;
resolve();
})(function() {}, getState);
});
return Promise.all([wait1, wait2]).then(() => {
expect(expectedEvent1).to.have.length(0);
expect(errorMsg).to.eql("Error");
});
});
it("check crud option", function() {
const meta = {
transformer,
crud: true,
fetch(url, opts) {
return new Promise(resolve => resolve({ url, opts }));
}
};
const api = actionFn("/test/:id", "test", null, ACTIONS, meta);
const expectedEvent = [
{
type: ACTIONS.actionFetch,
syncing: false,
request: {
pathvars: { id: 1 },
params: { method: "GET" }
}
},
{
type: ACTIONS.actionFetch,
syncing: false,
request: {
pathvars: { id: 2 },
params: { body: "Hello", method: "POST" }
}
},
{
type: ACTIONS.actionFetch,
syncing: false,
request: {
pathvars: { id: 3 },
params: { body: "World", method: "PUT" }
}
},
{
type: ACTIONS.actionFetch,
syncing: false,
request: {
pathvars: { id: 4 },
params: { method: "DELETE" }
}
},
{
type: ACTIONS.actionFetch,
syncing: false,
request: {
pathvars: { id: 5 },
params: { body: "World", method: "PATCH" }
}
},
{
type: ACTIONS.actionSuccess,
syncing: false,
data: { url: "/test/1", opts: { method: "GET" } },
origData: { url: "/test/1", opts: { method: "GET" } },
request: {
pathvars: { id: 1 },
params: { method: "GET" }
}
},
{
type: ACTIONS.actionSuccess,
syncing: false,
data: {
url: "/test/2",
opts: { body: "Hello", method: "POST" }
},
origData: {
url: "/test/2",
opts: { body: "Hello", method: "POST" }
},
request: {
pathvars: { id: 2 },
params: { body: "Hello", method: "POST" }
}
},
{
type: ACTIONS.actionSuccess,
syncing: false,
data: {
url: "/test/3",
opts: { body: "World", method: "PUT" }
},
origData: {
url: "/test/3",
opts: { body: "World", method: "PUT" }
},
request: {
pathvars: { id: 3 },
params: { body: "World", method: "PUT" }
}
},
{
type: ACTIONS.actionSuccess,
syncing: false,
data: {
url: "/test/4",
opts: { method: "DELETE" }
},
origData: {
url: "/test/4",
opts: { method: "DELETE" }
},
request: {
pathvars: { id: 4 },
params: { method: "DELETE" }
}
},
{
type: ACTIONS.actionSuccess,
syncing: false,
data: {
url: "/test/5",
opts: { body: "World", method: "PATCH" }
},
origData: {
url: "/test/5",
opts: { body: "World", method: "PATCH" }
},
request: {
pathvars: { id: 5 },
params: { body: "World", method: "PATCH" }
}
}
];
const getQuery = new Promise(resolve => {
api.get({ id: 1 }, resolve)(function(msg) {
expect(expectedEvent).to.have.length.above(0);
const exp = expectedEvent.shift();
expect(msg).to.eql(exp);
}, getState);
});
const postQuery = new Promise(resolve => {
api.post(
{ id: 2 },
{ body: "Hello" },
resolve
)(function(msg) {
expect(expectedEvent).to.have.length.above(0);
const exp = expectedEvent.shift();
expect(msg).to.eql(exp);
}, getState);
});
const putQuery = new Promise(resolve => {
api.put(
{ id: 3 },
{ body: "World" },
resolve
)(function(msg) {
expect(expectedEvent).to.have.length.above(0);
const exp = expectedEvent.shift();
expect(msg).to.eql(exp);
}, getState);
});
const deleteQuery = new Promise(resolve => {
api.delete({ id: 4 }, resolve)(function(msg) {
expect(expectedEvent).to.have.length.above(0);
const exp = expectedEvent.shift();
expect(msg).to.eql(exp);
}, getState);
});
const patchQuery = new Promise(resolve => {
api.patch(
{ id: 5 },
{ body: "World" },
resolve
)(function(msg) {
expect(expectedEvent).to.have.length.above(0);
const exp = expectedEvent.shift();
expect(msg).to.eql(exp);
}, getState);
});
return Promise.all([
getQuery,
postQuery,
putQuery,
deleteQuery,
patchQuery
]).then(() => expect(expectedEvent).to.have.length(0));
});
it("check crud option with overwrite", function() {
const meta = {
transformer,
crud: true,
fetch(url, opts) {
return new Promise(resolve => resolve({ url, opts }));
},
helpers: {
get() {
return [{ id: "overwrite" }];
}
}
};
const api = actionFn("/test/:id", "test", null, ACTIONS, meta);
const expectedEvent = [
{
type: ACTIONS.actionFetch,
syncing: false,
request: { pathvars: { id: "overwrite" }, params: undefined }
},
{
type: ACTIONS.actionSuccess,
syncing: false,
data: { url: "/test/overwrite", opts: null },
origData: { url: "/test/overwrite", opts: null },
request: { pathvars: { id: "overwrite" }, params: undefined }
}
];
return new Promise(resolve => {
api.get({ id: 1 }, resolve)(function(msg) {
expect(expectedEvent).to.have.length.above(0);
const exp = expectedEvent.shift();
expect(msg).to.eql(exp);
}, getState);
}).then(() => expect(expectedEvent).to.have.length(0));
});
it("check crud option with overwrite 2", function() {
const meta = {
transformer,
crud: true,
fetch(url, opts) {
return new Promise(resolve => resolve({ url, opts }));
},
helpers: {
get(param) {
return [{ id: param.id }, null];
}
}
};
const api = actionFn("/test/", "test", null, ACTIONS, meta);
const expectedEvent = [
{
type: ACTIONS.actionFetch,
syncing: false,
request: {
pathvars: { id: 1 },
params: null
}
},
{
type: ACTIONS.actionSuccess,
syncing: false,
data: { url: "/test/?id=1", opts: null },
origData: { url: "/test/?id=1", opts: null },
request: { pathvars: { id: 1 }, params: null }
}
];
return new Promise(resolve => {
api.get({ id: 1 }, resolve)(function(msg) {
expect(expectedEvent).to.have.length.above(0);
const exp = expectedEvent.shift();
expect(msg).to.eql(exp);
}, getState);
}).then(() => expect(expectedEvent).to.have.length(0));
});
it("check merge params", function() {
let params;
const meta = {
transformer,
fetch: (urlparams, _params) => {
params = _params;
return fetchSuccess();
}
};
const opts = { headers: { One: 1 } };
const api = actionFn("/test", "test", opts, ACTIONS, meta);
return api.request(null, { headers: { Two: 2 } }).then(() => {
expect(params).to.eql({
headers: {
One: 1,
Two: 2
}
});
});
});
it("check urlOptions", function() {
let urlFetch;
const api = actionFn("/test", "test", null, ACTIONS, {
transformer,
fetch: url => {
urlFetch = url;
return fetchSuccess();
},
urlOptions: {
delimiter: ",",
arrayFormat: "repeat"
}
});
const async = api.request({ id: [1, 2] });
expect(async).to.be.an.instanceof(Promise);
return async.then(() => {
expect(urlFetch).to.eql("/test?id=1,id=2");
});
});
it("check responseHandler success", function() {
const resp = [];
const api = actionFn("/test", "test", null, ACTIONS, {
transformer,
fetch() {
return fetchSuccess();
},
holder: {
responseHandler(err, data) {
resp.push({ err, data });
}
}
});
return api.request().then(() => {
expect(resp).to.eql([{ err: null, data: { msg: "hello" } }]);
});
});
it("check responseHandler error", function() {
const resp = [];
const api = actionFn("/test", "test", null, ACTIONS, {
transformer,
fetch() {
return fetchFail();
},
holder: {
responseHandler(err, data) {
resp.push({ err, data });
}
}
});
return api.request().then(null, () => {
expect(resp).to.have.length(1);
expect(resp[0].data).to.not.exist;
expect(resp[0].err).to.be.an.instanceof(Error);
});
});
it("chained callbacks all resolve", function() {
const meta = {
transformer,
crud: true,
fetch(url, opts) {
return new Promise(resolve => resolve({ url, opts }));
}
};
const api = actionFn("/test/:id", "test", null, ACTIONS, meta);
let callCount = 0;
function spy(resolve) {
callCount += 1;
resolve();
}
function none() {}
function chainedAction(resolve) {
api.get({ id: 1 }, () => spy(resolve))(none, getState);
}
return new Promise(resolve =>
api.get({ id: 1 }, () => chainedAction(resolve))(none, getState)
).then(() => expect(callCount).to.have.length.equal(1));
});
});
|
process.env.NODE_ENV = 'test'
// The following allows you to require files independent of
// the location of your test file.
// Example:
// var User = require(__server + '/models/user.js')
//
global.__server = __dirname + '/../server'
global.__app = __dirname + '/../app'
global.__actions = __dirname + '/../actions'
var chai = require('chai')
// Option 1: Make the `expect` function available in every test file
global.expect = chai.expect
// Option 2: Make everything should-able
// global.should = chai.should()
// Helper Functions
//
// This is the object you can attach any helper functions used across
// several test files.
global.TestHelper = {}
// Mock apps for API testing
var express = require('express')
TestHelper.createApp = function (loader) {
var app = express()
app.use(require('body-parser').json())
app.testReady = function () {
// Log all errors
app.use(function (err, req, res, next) {
console.error("==Error==")
console.error(" " + err.stack)
next(err)
})
}
return app
}
/* Mocha 'helpers' to support coroutine tests */
var Bluebird = require('bluebird');
global.before_ = function (f) { before ( Bluebird.coroutine(f) ) }
global.beforeEach_ = function (f) { beforeEach ( Bluebird.coroutine(f) ) }
global.it_ = function (description, f) { it ( description, Bluebird.coroutine(f) ) }
global.xit_ = function (description, f) { xit ( description, f ) }
global.it_.only = function (description, f) { it.only( description, Bluebird.coroutine(f) ) } |
var path = require('path')
var jsreport = require('jsreport-core')
var wkhtmltopdf = require('../')
var debug = require('jsreport-debug')
require('should')
describe('wkhtmltopdf', function () {
var reporter
beforeEach(function () {
reporter = jsreport()
reporter.use(wkhtmltopdf())
reporter.use(debug())
return reporter.init()
})
it('should not fail when rendering', function () {
var request = {
template: { content: 'Heyx', recipe: 'wkhtmltopdf', engine: 'none' }
}
return reporter.render(request).then(function (response) {
response.content.toString().should.containEql('%PDF')
})
})
it('should block local file access', function (done) {
var localFile = path.join(__dirname, 'test.png')
var request = {
template: { content: '<img src="' + localFile + '"/>', recipe: 'wkhtmltopdf', engine: 'none' }
}
reporter.render(request).then(function (response) {
done('Should have failed')
}).catch(function () {
done()
})
})
it('should propagate output to logs', function () {
var request = {
template: { content: 'Heyx<script>console.log("aaa")</script>', recipe: 'wkhtmltopdf', engine: 'none' }
}
return reporter.render(request).then(function (response) {
response.meta.logs.map(l => l.message).should.matchAny(/aaa/)
})
})
})
describe('wkhtmltopdf with local', function () {
var reporter
beforeEach(function () {
reporter = jsreport()
reporter.use(wkhtmltopdf({
allowLocalFilesAccess: true
}))
return reporter.init()
})
it('should block local file access', function () {
var localFile = path.join(__dirname, 'test.png')
var request = {
template: { content: '<img src="' + localFile + '"/>', recipe: 'wkhtmltopdf', engine: 'none' }
}
return reporter.render(request).then(function (response) {
response.content.toString().should.containEql('%PDF')
})
})
})
describe('wkhtmltopdf with proxy', function () {
var reporter
beforeEach(function () {
reporter = jsreport()
reporter.use(debug())
reporter.use(wkhtmltopdf({
proxy: 'foo'
}))
return reporter.init()
})
it('should propagate proxy config', function () {
var request = {
template: { content: 'foo', recipe: 'wkhtmltopdf', engine: 'none' }
}
return reporter.render(request).then(function (response) {
response.meta.logs.map(l => l.message).should.matchAny(/--proxy foo/)
})
})
})
describe('wkhtmltopdf with execOpptions.maxBuffer = 1', function () {
var reporter
beforeEach(function () {
reporter = jsreport()
reporter.use(debug())
reporter.use(wkhtmltopdf({
execOptions: {
maxBuffer: 1
}
}))
return reporter.init()
})
it('should fail because of max buffer acceeded', function (done) {
var request = {
template: { content: 'foo', recipe: 'wkhtmltopdf', engine: 'none' }
}
reporter.render(request).then(function (response) {
done(new Error('Should have fail'))
}).catch(function () {
done()
})
})
})
describe('wkhtmltopdf with execOpptions.maxBuffer = 1000 * 100', function () {
var reporter
beforeEach(function () {
reporter = jsreport()
reporter.use(debug())
reporter.use(wkhtmltopdf({
execOptions: {
maxBuffer: 1000 * 100
}
}))
return reporter.init()
})
it('should work', function () {
var request = {
template: { content: 'foo', recipe: 'wkhtmltopdf', engine: 'none' }
}
return reporter.render(request)
})
})
|
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DataObject = exports.Defaults = exports.Types = undefined;
var _types = require('./types');
var _types2 = _interopRequireDefault(_types);
var _defaults = require('./defaults');
var _defaults2 = _interopRequireDefault(_defaults);
var _dataObject = require('./dataObject');
var _dataObject2 = _interopRequireDefault(_dataObject);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.Types = _types2.default;
exports.Defaults = _defaults2.default;
exports.DataObject = _dataObject2.default; |
'use strict';
const Generator = require('yeoman-generator');
const path = require('path');
const chalk = require('chalk');
const yosay = require('yosay');
const rename = require("gulp-rename");
const _ = require("lodash");
module.exports = class extends Generator
{
constructor(args, opts) {
super(args, opts);
this.argument('name', { type: String, required: false });
this.option('dir', {
desc: "The directory where the code will be",
type: String,
required: false
});
this.option('skip-prompt', {
desc: "Don't ask anything, use the default",
type: Boolean,
required: false,
default: false
});
this.props = {};
}
getVersion() {
return require('../package.json').version;
}
getProjectRoot() {
let root = '';
let ndx = 0;
while (!this.fs.exists(this.destinationPath(`${root}package.json`)) && (++ndx) < 20)
root = '../' + root;
if (ndx === 20)
root = '';
return root;
}
initializing() {
this.props['dir'] = this.options.dir || '';
this.props['name'] = this.options.name;
this.props['kebabName'] = _.kebabCase(this.options.name);
this.props['titleName'] = _.upperFirst(_.camelCase(this.options.name));
}
configuring() {
}
writing() {
// Templated filename
this.registerTransformStream(rename((path) => {
path.basename = path.basename.replace(/(#name#)/g, this.props.kebabName);
path.dirname = path.dirname.replace(/(#name#)/g, this.props.kebabName);
}));
}
copyTemplates() {
// Copy all files
this.fs.copy(
this.templatePath(),
this.destinationPath(this.props.dir),
{
globOptions: {
dot: true
}
}
);
// Overwrite with templated files (json, js, html, css, scss)
this.fs.copyTpl(
this.templatePath('**/*.{json,js,ts,html,css,scss}'),
this.destinationPath(this.props.dir),
this.props
);
}
insertBeforeNeedle(file, needle, str) {
let content = this.fs.read(file);
needle = `/* ${needle} `;
let ndx = content.indexOf(needle);
if (ndx >= 0) {
// Find spaces before
let spaces = "";
for (let i = ndx-1; i > 0; i--) {
if (content.charAt(i) === ' ')
spaces += " ";
else
break;
}
content = content.replace(needle, `${str}\r\n${spaces}${needle}`);
this.fs.write(file, content);
}
}
};
|
/*
* Copyright (c) André Bargull
* Alle Rechte vorbehalten / All Rights Reserved. Use is subject to license terms.
*
* <https://github.com/anba/es6draft>
*/
const {
assertThrows, assertSyntaxError, assertInstanceOf, fail
} = Assert;
System.load("lib/promises.jsm");
const {
reportFailure
} = System.get("lib/promises.jsm");
var home = {};
// 14.1 FunctionDeclaration
assertSyntaxError(`
function fdecl() {
(() => {
if (false) { super.add_super_binding; }
eval("super.property_from_eval");
})();
}
fdecl.toMethod(home)();
`);
// 14.1 FunctionExpression
assertSyntaxError(`
var fexpr = function() {
(() => {
if (false) { super.add_super_binding; }
eval("super.property_from_eval");
})();
};
fexpr.toMethod(home)();
`);
// 14.3 Method Definitions [Method]
var obj = {
m() {
(() => {
if (false) { super.add_super_binding; }
eval("super.property_from_eval");
})();
}
};
obj.m();
var obj = class {
m() {
(() => {
if (false) { super.add_super_binding; }
eval("super.property_from_eval");
})();
}
};
obj.prototype.m();
var obj = class {
static m() {
(() => {
if (false) { super.add_super_binding; }
eval("super.property_from_eval");
})();
}
};
obj.m();
// 14.3 Method Definitions [ConstructorMethod]
var obj = class {
constructor() {
(() => {
if (false) { super.add_super_binding; }
eval("super.property_from_eval");
})();
}
};
new obj();
var obj = class extends class {} {
constructor() {
super();
(() => {
if (false) { super.add_super_binding; }
eval("super.property_from_eval");
})();
}
};
new obj();
// 14.3 Method Definitions [Getter]
var obj = {
get x() {
(() => {
if (false) { super.add_super_binding; }
eval("super.property_from_eval");
})();
}
};
Object.getOwnPropertyDescriptor(obj, "x").get();
var obj = class {
get x() {
(() => {
if (false) { super.add_super_binding; }
eval("super.property_from_eval");
})();
}
};
Object.getOwnPropertyDescriptor(obj.prototype, "x").get();
var obj = class {
static get x() {
(() => {
if (false) { super.add_super_binding; }
eval("super.property_from_eval");
})();
}
};
Object.getOwnPropertyDescriptor(obj, "x").get();
// 14.3 Method Definitions [Setter]
var obj = {
set x(_) {
(() => {
if (false) { super.add_super_binding; }
eval("super.property_from_eval");
})();
}
};
Object.getOwnPropertyDescriptor(obj, "x").set();
var obj = class {
set x(_) {
(() => {
if (false) { super.add_super_binding; }
eval("super.property_from_eval");
})();
}
};
Object.getOwnPropertyDescriptor(obj.prototype, "x").set();
var obj = class {
static set x(_) {
(() => {
if (false) { super.add_super_binding; }
eval("super.property_from_eval");
})();
}
};
Object.getOwnPropertyDescriptor(obj, "x").set();
// 14.4 GeneratorDeclaration
assertSyntaxError(`
function* gdecl() {
(() => {
if (false) { super.add_super_binding; }
eval("super.property_from_eval");
})();
}
gdecl.toMethod(home)().next();
`);
// 14.4 GeneratorExpression
assertSyntaxError(`
var gexpr = function*() {
(() => {
if (false) { super.add_super_binding; }
eval("super.property_from_eval");
})();
};
gexpr.toMethod(home)().next();
`);
// 14.4 GeneratorMethod
var obj = {
*m() {
(() => {
if (false) { super.add_super_binding; }
eval("super.property_from_eval");
})();
}
};
obj.m().next();
var obj = class {
*m() {
(() => {
if (false) { super.add_super_binding; }
eval("super.property_from_eval");
})();
}
};
obj.prototype.m().next();
var obj = class {
static *m() {
(() => {
if (false) { super.add_super_binding; }
eval("super.property_from_eval");
})();
}
};
obj.m().next();
// 15.1 Scripts
assertThrows(SyntaxError, () => evalScript(`
(() => {
eval("super.property_from_eval");
})();
`));
// 15.2 Modules
System
.define("parse-super-property-arrow-eval", `
(() => {
eval("super.property_from_eval");
})();
`)
.then(() => fail `no SyntaxError`, e => assertInstanceOf(SyntaxError, e))
.catch(reportFailure);
|
(function ($, Backbone) {
'use strict';
var Page = Backbone.View.extend({
tagName: 'section',
events: {
'click .slideInRight': function () {
stackView.push(new Page(), 'slideInRight', 'fadeOut');
},
'click .slideOutRight': function () {
stackView.pop('slideOutRight', 'fadeIn');
},
'click .slideInBottom': function () {
stackView.push(new Page(), 'slideInBottom');
},
'click .slideOutBottom': function () {
stackView.pop('slideOutBottom', 'fadeIn');
},
'click .fadeIn': function () {
stackView.push(new Page(), 'fadeIn');
},
'click .fadeOut': function () {
stackView.pop('fadeOut');
},
'click .pop': function () {
stackView.pop();
},
'click .slideInRightReplace': function () {
stackView.replace(new Page(), 'slideInRight', 'slideOutLeft');
},
'click .slideInLeftReplace': function () {
stackView.replace(new Page(), 'slideInLeft', 'slideOutRight');
}
},
render: function () {
this.$el.html('<button class="slideInRight">Slide In Right</button>' +
'<button class="slideOutRight">Slide Out Right</button><br>' +
'<button class="slideInBottom">Slide In Bottom</button>' +
'<button class="slideOutBottom">Slide Out Bottom</button><br>' +
'<button class="fadeIn">Fade In</button>' +
'<button class="fadeOut">Fade Out</button><br>' +
'<button class="pop">Pop</button><br>');
return this;
}
});
$(function () {
window.stackView = new Backbone.StackView({el: '#stack'});
window.stackView.push(new Page(), false);
});
}(this.jQuery, this.Backbone));
|
/*! angular-phonecat 2016-01-30 */
"use strict";var phonecatApp=angular.module("phonecatApp",["ngRoute","phonecatControllers","phonecatFilters","angular.backtop"]);phonecatApp.config(["$routeProvider",function(a){a.when("/index",{templateUrl:"partials/video-list.html",controller:"PhoneListCtrl"}).when("/detail/:detailId",{templateUrl:"partials/video-detail.html",controller:"PhoneDetailCtrl"}).otherwise({redirectTo:"/index"})}]),window.screen.width<768&&(alert("检测到移动设备,进入官网下载App"),window.location="http://www.wandoujia.com/eyepetizer"); |
/**
* ActionFieldLayouts are used with OO.ui.FieldsetLayout. The layout consists of a field-widget,
* a button, and an optional label and/or help text. The field-widget (e.g., a
* {@link OO.ui.TextInputWidget TextInputWidget}), is required and is specified before any optional
* configuration settings.
*
* Labels can be aligned in one of four ways:
*
* - **left**: The label is placed before the field-widget and aligned with the left margin.
* A left-alignment is used for forms with many fields.
* - **right**: The label is placed before the field-widget and aligned to the right margin.
* A right-alignment is used for long but familiar forms which users tab through,
* verifying the current field with a quick glance at the label.
* - **top**: The label is placed above the field-widget. A top-alignment is used for brief forms
* that users fill out from top to bottom.
* - **inline**: The label is placed after the field-widget and aligned to the left.
* An inline-alignment is best used with checkboxes or radio buttons.
*
* Help text is accessed via a help icon that appears in the upper right corner of the rendered
* field layout when help text is specified.
*
* @example
* // Example of an ActionFieldLayout
* var actionFieldLayout = new OO.ui.ActionFieldLayout(
* new OO.ui.TextInputWidget( {
* placeholder: 'Field widget'
* } ),
* new OO.ui.ButtonWidget( {
* label: 'Button'
* } ),
* {
* label: 'An ActionFieldLayout. This label is aligned top',
* align: 'top',
* help: 'This is help text'
* }
* );
*
* $( document.body ).append( actionFieldLayout.$element );
*
* @class
* @extends OO.ui.FieldLayout
*
* @constructor
* @param {OO.ui.Widget} fieldWidget Field widget
* @param {OO.ui.ButtonWidget} buttonWidget Button widget
* @param {Object} config
*/
OO.ui.ActionFieldLayout = function OoUiActionFieldLayout( fieldWidget, buttonWidget, config ) {
// Allow passing positional parameters inside the config object
if ( OO.isPlainObject( fieldWidget ) && config === undefined ) {
config = fieldWidget;
fieldWidget = config.fieldWidget;
buttonWidget = config.buttonWidget;
}
// Parent constructor
OO.ui.ActionFieldLayout.super.call( this, fieldWidget, config );
// Properties
this.buttonWidget = buttonWidget;
this.$button = $( '<span>' );
this.$input = this.isFieldInline() ? $( '<span>' ) : $( '<div>' );
// Initialization
this.$element.addClass( 'oo-ui-actionFieldLayout' );
this.$button
.addClass( 'oo-ui-actionFieldLayout-button' )
.append( this.buttonWidget.$element );
this.$input
.addClass( 'oo-ui-actionFieldLayout-input' )
.append( this.fieldWidget.$element );
this.$field.append( this.$input, this.$button );
};
/* Setup */
OO.inheritClass( OO.ui.ActionFieldLayout, OO.ui.FieldLayout );
|
/**
*
* @returns {string}
* @private
*/
jDoc.Engine.prototype._getHalfTabAsSpaces = function () {
return "\u2000\u2000";
}; |
/*
* spa.shell.preface.js
* Preface module for Shell
*/
/*jslint browser : true, continue : true,
devel : true, indent : 2, maxerr : 50,
newcap : true, nomen : true, plusplus : true,
regexp : true, sloppy : true, vars : false,
white : true
*/
/*global $, spa */
spa.shell.preface = (function () {
var
configMap = {
preface_html : String()
+ '<div class="spa-preface-img">'
+ '<img src="images/index/preface.png">'
+ '</div>'
},
stateMap = { $preface : null },
initModule;
initModule = function ($preface) {
stateMap.$preface = $preface;
$preface.html(configMap.preface_html);
};
return { initModule : initModule };
}());
|
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports) {
module.exports = {
data: window.$data,
methods: {
save: function() {
this.$http.post('admin/system/settings/config', { name: 'system/user', config: this.config }, function() {
this.$notify('Settings saved.');
}).error(function(data) {
this.$notify(data, 'danger');
});
}
}
};
$(function () {
new Vue(module.exports).$mount('#settings');
});
/***/ }
/******/ ]); |
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const sinon = require('sinon');
const sinonChai = require('sinon-chai');
const log4Js = require('log4js');
const config = require('./config');
const uwpws = require('../../src/index');
const logger = log4Js.getLogger();
logger.level = config.logLevel || 'info';
logger.info('Starting test run');
chai.use(sinonChai);
chai.use(chaiAsPromised);
global.expect = chai.expect;
global.config = config;
global.uwpws = uwpws;
beforeEach(function setup() {
this.sandbox = sinon.createSandbox();
this.stub = this.sandbox.stub.bind(this.sandbox);
this.spy = this.sandbox.spy.bind(this.sandbox);
});
afterEach(function teardown() {
this.stub = undefined;
this.spy = undefined;
this.sandbox.restore();
});
|
import React from "react";
import PropTypes from "prop-types";
import Helmet from "react-helmet";
import { useStaticQuery, graphql } from "gatsby";
function SEO({ description, lang, meta, title, image }) {
const { site } = useStaticQuery(
graphql`
query {
site {
siteMetadata {
title
tagline
siteURL
author
}
}
}
`
);
const metaDescription = description || site.siteMetadata.tagline;
return (
<Helmet
htmlAttributes={{
lang,
}}
title={title}
titleTemplate={`${site.siteMetadata.title} | %s`}
meta={[
{
name: `description`,
content: metaDescription,
},
{
name: `image`,
content: `${site.siteMetadata.siteURL}${image}`,
},
{
property: `og:title`,
content: title,
},
{
property: `og:description`,
content: metaDescription,
},
{
property: `og:type`,
content: `website`,
},
{
property: `og:image`,
content: `${site.siteMetadata.siteURL}${image}`,
},
{
name: `twitter:card`,
content: `summary`,
},
{
name: `twitter:creator`,
content: site.siteMetadata.author,
},
{
name: `twitter:title`,
content: title,
},
{
name: `twitter:description`,
content: metaDescription,
},
{
name: `twitter:image`,
content: `${site.siteMetadata.siteURL}${image}`,
},
].concat(meta)}
/>
);
}
SEO.defaultProps = {
lang: `en`,
meta: [],
description: ``,
};
SEO.propTypes = {
description: PropTypes.string,
lang: PropTypes.string,
meta: PropTypes.arrayOf(PropTypes.object),
title: PropTypes.string.isRequired,
};
export default SEO;
|
const { userDal } = require('./dal');
/**
* 通过查询组成员包含userId的组,来查出用户加入的组
* @param {*} ctx
*/
const getUserGroupList = async ctx => {
const userId = +ctx.params.userId;
const groups = await userDal.getUserGroupList(userId);
ctx.body = groups;
};
/**
* 通过两次查询,获取用户的好友列表
* @param {*} ctx
*/
const getUserFriendList = async ctx => {
const userId = +ctx.params.userId;
const friendList = await userDal.getUserFriendList(userId);
ctx.body = friendList;
};
/**
* 获取用户的会话列表
* @param {*} ctx
*/
const getUserSessionList = async ctx => {
const userId = +ctx.params.userId;
const sessionList = await userDal.getUserSessionList(userId);
ctx.body = sessionList;
};
const getMainUIData = async ctx => {
const userId = ctx.state.user.userId;
const sessions = await userDal.getUserSessionList(userId);
const userIdStr = userId.toString();
// Nosql的苦果,需要关联查询好友的昵称
const friendIdList = sessions.filter(x => x.groupId.startsWith('user_')).map(x => {
const friendId = x.groupId.split('_').find(x => x !== 'user' && x !== userIdStr);
return +friendId;
});
const friendList = await userDal.findUserList(
{ userId: { $in: friendIdList } },
{ userId: true, userName: true, nickName: true, avatarUrl: true }
);
const friendMap = new global.Map();
friendList.forEach(x => {
friendMap.set(x.userId.toString(), x);
});
sessions.forEach(item => {
if (item.groupId.startsWith('user_')) {
const friendId = item.groupId.split('_').find(x => x !== 'user' && x !== userIdStr);
const friend = friendMap.get(friendId);
item.groupName = friend.nickName;
item.avatarUrl = friend.avatarUrl;
}
});
const resBody = {
friends: await userDal.getUserFriendList(userId),
groups: await userDal.getUserGroupList(userId),
sessions
};
ctx.body = resBody;
};
const _createSession = async (userId, groupId) => {
const findUser = await userDal.findUser({ userId }, { sessions: true });
// sessions中找不到groupID
if (findUser) {
const newSessions = findUser.sessions || [];
if (newSessions.filter(x => x.groupId === groupId).length === 0) {
newSessions.push({ groupId });
}
// 写入DB
await userDal.updateUserSession(userId, newSessions);
}
};
module.exports = {
getUserGroupList,
getUserFriendList,
getUserSessionList,
getMainUIData,
_createSession
};
|
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
var h = require('./hello');
var w = require('./world');
function output() {
var result = h.call() + ', ' + w.call() + '!';
console.log(result);
return result;
}
module.exports = output();
},{"./hello":2,"./world":3}],2:[function(require,module,exports){
'use strict';
var str = 'Hello'
module.exports = function hello(){
return str;
}
},{}],3:[function(require,module,exports){
'use strict';
var str = 'World'
module.exports = function world(){
return str;
}
},{}]},{},[1]) |
/*
@author Ilya Shubentsov
MIT License
Copyright (c) 2017 Ilya Shubentsov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
"use strict";
/**
* Format a 10 digit phone number like this:
* 111.111.1111
* @param value - the phone number to format
* @param intentName - the intent name, ignored here since this is a built in transform function.
* @param slotName - the slot name, ignored here since this is a built in transform function.
* @param slotType - slot type, verified to be TRANSCEND.US_PHONE_NUMBER. If not - returns the passed in value.
* @returns {*} - either formatted value, unchanged value (if not US_PHONE_NUMBER slot type) or undefined if the input is
* undefined or null
*/
module.exports = function(value, intentName, slotName, slotType){
if(slotType !== "TRANSCEND.US_PHONE_NUMBER"){
return value;
}
if(typeof value !== "undefined" && value !== null){
let returnValue = "";
returnValue += value.substring(0,3);
returnValue += ".";
returnValue += value.substring(3, 6);
returnValue += ".";
returnValue += value.substring(6);
return returnValue;
}
//return;
};
|
$(document).ready(function() {
$('[data-form="monthly-materials-report-form"]').submit(function() {
var dateInput = $('[data-input="date"]').val();
setDialogLoader();
openDialog();
setDialogHtmlContent('Monthly Materials Report', '<iframe class="pdf-frame" src="requests/generate_monthly_materials_report.php?date=' + dateInput + '"></iframe>');
return false;
});
$('[data-form="monthly-transactions-report-form"]').submit(function() {
var dateInput = $('[data-input="date"]').val();
setDialogLoader();
openDialog();
setDialogHtmlContent('Monthly Transactions Report', '<iframe class="pdf-frame" src="requests/generate_monthly_transactions_report.php?date=' + dateInput + '"></iframe>');
return false;
});
$('[data-form="students-report-form"]').submit(function() {
setDialogLoader();
openDialog();
setDialogHtmlContent('Students Report', '<iframe class="pdf-frame" src="requests/generate_students_report.php"></iframe>');
return false;
});
$('[data-form="barcode-report-form"]').submit(function() {
setDialogLoader();
openDialog();
setDialogHtmlContent('Barcode Report', '<iframe class="pdf-frame" src="requests/generate_barcode_report.php"></iframe>');
return false;
});
}); |
// All symbols with the `Logical_Order_Exception` property as per Unicode v4.0.1:
[
'\u0E40',
'\u0E41',
'\u0E42',
'\u0E43',
'\u0E44',
'\u0EC0',
'\u0EC1',
'\u0EC2',
'\u0EC3',
'\u0EC4'
]; |
"use strict";
module.exports = function(grunt) {
var settings = grunt.config.get("settings"),
shell = require("shelljs")
grunt.registerTask("gitPushCommit", "Commit the ftpush json", function(){
var command = grunt.template.process('git add <%=logFilePath%><%=logFilename%>.log && git commit -m "<%=environment%> push (from grunt)"', {data: {
logFilePath: settings.deploy.logFilePath,
logFilename: grunt.config.get("logFilename"),
environment: grunt.config.get("environment"),
}});
shell.exec(command);
});
};
|
const express = require('express')
const bodyParser = require('body-parser')
const compression = require('compression')
const path = require('path')
const emojiFavicon = require('emoji-favicon')
const uuid = require('uuid')
const morgan = require('morgan')
const _ = require('lodash')
const AuthenticationClient = require('auth0').AuthenticationClient
const Uploader = require('./uploader')
const Promise = require('bluebird')
const multiparty = Promise.promisifyAll(require('multiparty'), {multiArgs: true})
const fs = Promise.promisifyAll(require('fs'))
const models = require('./models')
const utils = require('./utils')
const app = express()
app.use(bodyParser.json())
app.use(compression())
app.use(emojiFavicon('sparkles'))
if (process.env.NODE_ENV !== 'test') {
app.use(morgan(':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] :response-time ms'))
}
app.use(express.static(path.resolve(__dirname, '..', 'client', 'build')))
app.post('/api/login', utils.jwtCheck, async (req, res) => {
try {
const auth0 = new AuthenticationClient({
domain: 'twobucks.auth0.com'
})
const authToken = utils.getJWTToken(req)
const userInfoRaw = await auth0.users.getInfo(authToken)
const userInfo = JSON.parse(userInfoRaw)
const where = utils.whereQueryFromUserInfo(userInfo)
const accessToken = uuid.v4()
const [ user ] = await models.User.findOrCreate({
where,
defaults: { auth_token: authToken, access_token: accessToken }
})
await user.update({ auth_token: authToken })
res.json(_.pick(user, 'auth_token'))
} catch (e) {
console.log(e)
}
})
app.get('/api/tokens', utils.jwtCheck, utils.findUserByAuthToken, async (req, res) => {
if (!req.user) {
res.status(401).json({
error: 'user not found'
})
return
}
res.json(_.pick(req.user, 's3_details', 'access_token'))
})
app.post('/api/test', utils.jwtCheck, utils.findUserByAuthToken, async (req, res) => {
try {
req.user.update({
s3_details: {
bucket_name: req.body.bucket_name,
aws_secret_key: req.body.aws_secret_key,
aws_access_key: req.body.aws_access_key
}
})
const bucketName = req.body.bucket_name
const awsSecretKey = req.body.aws_secret_key
const awsAccessKey = req.body.aws_access_key
const id = uuid.v4()
const filePath = path.join(__dirname, '..', 'test', 'cat.jpg')
const uploader = new Uploader({
accessKey: awsAccessKey,
secretKey: awsSecretKey,
bucketName
})
await uploader.upload({
path: filePath,
key: id
})
await uploader.delete({
key: id
})
res.json({ })
} catch (e) {
// TODO: better error handling
res.status(422).json({
error: e.message
})
}
})
app.get('/api/images', utils.jwtCheck, utils.findUserByAuthToken, async (req, res) => {
try {
const images = await req.user.getImages()
const imagesJson = images.map(function (image) {
return {
url: image.url
}
})
const imageCount = await models.Image.count({
where: {
'user_id': req.user.id
}
})
res.json({
images: imagesJson,
count: imageCount
})
} catch (e) {
res.status(422).json({
error: e.message
})
}
})
app.post('/api/images', async (req, res) => {
try {
const form = new multiparty.Form()
const [formParams, files] = await form.parseAsync(req)
if (!formParams.access_token) {
res.status(422).json({
error: 'access token is required'
})
return
}
const accessToken = formParams.access_token[0]
const user = await utils.findUserByAccessToken(accessToken, res)
if (!user) {
return
}
const path = files.file[0].path
if (_.isEmpty(user.s3_details)) {
res.status(422).json({
error: 'S3 configuration is not set up yet'
})
return
}
const uploader = new Uploader({
accessKey: user.s3_details.aws_access_key,
secretKey: user.s3_details.aws_secret_key,
bucketName: user.s3_details.bucket_name
})
const url = await uploader.upload({
path,
key: uuid.v4()
})
await fs.unlinkAsync(path)
const image = await models.Image.create({
url
})
await user.addImage(image)
res.json({
url
})
} catch (e) {
console.error(e)
res.status(422).json({
error: e.message
})
}
})
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, '..', 'client', 'build', 'index.html'))
})
app.set('x-powered-by', false)
app.use(function (err, req, res, next) {
if (err.name === 'UnauthorizedError') {
res.status(401).json({
error: 'invalid token'
})
}
})
app.use(function (req, res, next) {
res.status(404)
if (req.accepts('json')) {
res.send({ error: 'not found' })
return
}
res.type('txt').send('not found')
})
module.exports = app
|
import Ember from 'ember';
export default Ember.Controller.extend({
winningResult: function() {
if(this.get("isComplete")) {
var tally = Ember.Object.create();
var selections = this.get("selections");
Object.keys(selections).forEach(function(qid) {
var answer = selections[qid];
Object.keys(answer).forEach(function(resultId) {
tally.incrementProperty(resultId, answer[resultId]);
});
});
var winningResultId = Object.keys(tally).reduce(function(a, b){ return tally[a] > tally[b] ? a : b; });
var result = this.get(`model.results.${winningResultId}`);
console.log(result);
return result;
} else {
return null;
}
}.property("selections", "isComplete"),
isComplete: function() {
return Object.keys(this.get("selections")).length === this.get("model.questions").length;
}.property("selections"),
url: function() {
return window.location;
}.property(),
tweet: function() {
var tweetText = "I got '" + this.get("winningResult.name") + "' on the '" + this.get("model.title") + "' quiz by @thewordset";
return encodeURI(tweetText);
}.property("winningResult"),
actions: {
selectedAnswer: function(answer) {
answer = answer.split("-");
var qid = answer[0];
var aid = answer[1];
this.set("selections." + qid,
this.get(`model.questions.${qid}.answers.${aid}.result_values`));
this.notifyPropertyChange("selections");
}
}
});
|
/* exported MockSIMSlot */
'use strict';
var MockSIMSlot = function(conn, index) {
this._smsc = '0123456789';
this.conn = conn;
this.index = index;
this.absent = false;
this.locked = false;
this.simCard = {
cardState: null
};
this.update = function() {};
this.isAbsent = function() { return this.absent; };
this.isLocked = function() { return this.locked; };
this.getSmsc = function() { return this._smsc; };
// Inject method
['sendStkResponse', 'sendStkMenuSelection',
'sendStkTimerExpiration', 'sendStkEventDownload'].forEach(function(name) {
this[name] = function() {};
}, this);
// Inject dom request
['getCardLock', 'unlockCardLock', 'setCardLock',
'getCardLockRetryCount', 'readContacts',
'updateContact', 'iccOpenChannel', 'iccExchangeAPDU',
'iccCloseChannel'].forEach(function(name) {
this[name] = function() {
return {};
};
}, this);
};
|
import { h } from 'omi';
import createSvgIcon from './utils/createSvgIcon';
export default createSvgIcon(h("path", {
d: "M22 18v-2H8V4h2L7 1 4 4h2v2H2v2h4v8c0 1.1.9 2 2 2h8v2h-2l3 3 3-3h-2v-2h4zM10 8h6v6h2V8c0-1.1-.9-2-2-2h-6v2z"
}), 'TransformOutlined'); |
const subNotes = require('./sub-notes')
const argv = require('./argv')
const json = require('./json')
// console.log(`Yor age is ${subNotes.age}`)
/**
* При обычном присваивании переменная передается по ссылке
* Демонстрация внизу:
*/
var _notes = subNotes.notes
console.log('_notes: ',_notes)
subNotes.addNote({
id: 1,
title: 'Note 1',
flag: false
})
console.log('_notes after addNote: ',_notes)
// _notes = null
// console.log( 'subNotes.notes after addNote local _notes = null: ', subNotes.notes) // [ { id: 1, title: 'Note 1', flag: false } ]
subNotes.notes = null
console.log('subNotes.notes: ', subNotes.notes) // null
console.log('_notes: ', _notes) // [ { id: 1, title: 'Note 1', flag: false } ]
/**
* Но при использовании паттерна "модуль" все инкапсулировано в combiner:
*/
// К массиву notes доступа нет
// console.log(subNotes.combiner.notes) // undefined
console.log(subNotes.combiner.getNotes())
console.log(subNotes.combiner.addNote({
id: 1,
title: 'Note 1',
flag: false
}))
var __Notes = subNotes.combiner.getNotes()
console.log(__Notes) // [ { id: 1, title: 'Note 1', flag: false } ]
subNotes.combiner.addNote({
id: 2,
title: 'Note 2',
flag: false
})
console.log(__Notes) // [ { id: 1, title: 'Note 1', flag: false },{ id: 2, title: 'Note 2', flag: false } ]
__Notes = null
console.log( subNotes.combiner.getNotes() ) // [ { id: 1, title: 'Note 1', flag: false },{ id: 2, title: 'Note 2', flag: false } ]
console.log( __Notes ) // null
/**
* Вывод последнего аргумента, переданного в консоли
* node node-samples/notes arg_1 arg_2 --key "some string" --another_key="asd"
* // arg_2
*/
// console.log( argv.getLastArg() )
/**
* Вывод аргумента по имени
* node node-samples/notes arg_1 arg_2 --key "some string" --another_key="asd"
* // some string
*/
// console.log( argv.getAtrByName('title') )
// Построить объект note из аргументов консоли
var getNote = function () {
var note = {}
try {
note.title = argv.getAtrByName('title')
note.description = argv.getAtrByName('desc')
} catch (err){
}
return note
}
/**
* Код управления заметками
* Заметки создаются из командной строки
* node node-samples/notes addNote --title=TITLE --desc="new description"
* node node-samples/notes dropNote --title=TITLE --desc="new description"
*
* node node-samples/notes -h
*/
// todo доработать, чтобы брать команду и ключи из consoleArgs
const consoleArgs = argv.getHelp()
// console.log(consoleArgs['addNote'], "aaaa")
// console.log(consoleArgs['a'], "vvvvvv")
switch( argv.getFirstArg() ){
case 'addNote':
json.addNote( getNote() )
break;
case 'dropNote':
json.removeNote( getNote() )
break;
}
|
var swagger = require('../../../'),
expect = require('chai').expect,
_ = require('lodash'),
files = require('../../fixtures/files'),
helper = require('./helper');
describe('Mock Response', function() {
'use strict';
var api;
beforeEach(function() {
api = _.cloneDeep(files.parsed.petStore);
});
it('should use the 200 response, if it exists',
function(done) {
api.paths['/pets'].get.responses = {
'100': {description: ''},
'204': {description: ''},
'default': {description: ''},
'300': {description: ''},
'200': {description: ''},
'400': {description: ''}
};
helper.initTest(api, function(supertest) {
supertest
.get('/api/pets')
.expect(200)
.end(helper.checkResults(done));
});
}
);
it('should use the lowest 2XX response that exists',
function(done) {
api.paths['/pets'].get.responses = {
'100': {description: ''},
'204': {description: ''},
'default': {description: ''},
'203': {description: ''},
'201': {description: ''},
'102': {description: ''},
'404': {description: ''}
};
helper.initTest(api, function(supertest) {
supertest
.get('/api/pets')
.expect(201)
.end(helper.checkResults(done));
});
}
);
it('should use the lowest 3XX response that exists',
function(done) {
api.paths['/pets'].get.responses = {
'100': {description: ''},
'304': {description: ''},
'default': {description: ''},
'302': {description: ''},
'303': {description: ''},
'400': {description: ''}
};
helper.initTest(api, function(supertest) {
supertest
.get('/api/pets')
.expect(302)
.end(helper.checkResults(done));
});
}
);
it('should use the lowest 1XX response that exists',
function(done) {
api.paths['/pets'].get.responses = {
'102': {description: ''},
'404': {description: ''},
'500': {description: ''},
'101': {description: ''},
'400': {description: ''},
'504': {description: ''}
};
helper.initTest(api, function(supertest) {
supertest
.get('/api/pets')
.expect(101)
.end(helper.checkResults(done));
});
}
);
it('should use a 200 response if "default" exists',
function(done) {
api.paths['/pets'].get.responses = {
'100': {description: ''},
'400': {description: ''},
'default': {description: ''},
'402': {description: ''},
'500': {description: ''},
'102': {description: ''}
};
helper.initTest(api, function(supertest) {
supertest
.get('/api/pets')
.expect(200)
.end(helper.checkResults(done));
});
}
);
it('should use a 201 response for POST operations if "default" exists',
function(done) {
api.paths['/pets'].post.responses = {
'100': {description: ''},
'400': {description: ''},
'default': {description: ''},
'402': {description: ''},
'500': {description: ''},
'102': {description: ''}
};
helper.initTest(api, function(supertest) {
supertest
.post('/api/pets')
.send({Name: 'Fido', Type: 'dog'})
.expect(201)
.end(helper.checkResults(done));
});
}
);
it('should not use a 201 response for POST operations if "default" does not exist',
function(done) {
api.paths['/pets'].post.responses = {
'400': {description: ''},
'402': {description: ''},
'500': {description: ''},
'102': {description: ''}
};
helper.initTest(api, function(supertest) {
supertest
.post('/api/pets')
.send({Name: 'Fido', Type: 'dog'})
.expect(102)
.end(helper.checkResults(done));
});
}
);
it('should use a 201 response for PUT operations if "default" exists',
function(done) {
api.paths['/pets'].put = api.paths['/pets'].post;
api.paths['/pets'].put.responses = {
'100': {description: ''},
'400': {description: ''},
'default': {description: ''},
'402': {description: ''},
'500': {description: ''},
'102': {description: ''}
};
helper.initTest(api, function(supertest) {
supertest
.put('/api/pets')
.send({Name: 'Fido', Type: 'dog'})
.expect(201)
.end(helper.checkResults(done));
});
}
);
it('should not use a 201 response for PUT operations if "default" does not exist',
function(done) {
api.paths['/pets'].put = api.paths['/pets'].post;
api.paths['/pets'].put.responses = {
'101': {description: ''},
'400': {description: ''},
'402': {description: ''},
'500': {description: ''},
'102': {description: ''}
};
helper.initTest(api, function(supertest) {
supertest
.put('/api/pets')
.send({Name: 'Fido', Type: 'dog'})
.expect(101)
.end(helper.checkResults(done));
});
}
);
it('should use a 204 response for DELETE operations if "default" exists',
function(done) {
api.paths['/pets/{PetName}'].delete.responses = {
'100': {description: ''},
'400': {description: ''},
'default': {description: ''},
'402': {description: ''},
'500': {description: ''},
'102': {description: ''}
};
helper.initTest(api, function(supertest) {
supertest
.delete('/api/pets/Fido')
.expect(204)
.end(helper.checkResults(done));
});
}
);
it('should not use a 204 response for DELETE operations if "default" does not exist',
function(done) {
api.paths['/pets/{PetName}'].delete.responses = {
'101': {description: ''},
'400': {description: ''},
'402': {description: ''},
'500': {description: ''},
'102': {description: ''}
};
helper.initTest(api, function(supertest) {
supertest
.delete('/api/pets/Fido')
.expect(101)
.end(helper.checkResults(done));
});
}
);
});
|
var status = require("../status.json");
exports.home = function(req, res)
{
if (status["loginStatus"]["loggedIn"]=="false")
{
res.redirect('/');
}
else if(status["loginStatus"]["loggedIn"]=="true" && status["loginStatus"]["userType"]=="student")
{
res.redirect('/student');
}
else if(status["loginStatus"]["loggedIn"]=="true" && status["loginStatus"]["userType"]=="instructor")
{
res.redirect('/instructor');
}
else
{
console.log("error");
}
}; |
"use strict";
var mambo = require('mambo'),
Schema = mambo.Schema,
StringField = mambo.StringField,
NumberField = mambo.NumberField,
JSONField = mambo.JSONField,
DateField = mambo.DateField;
var Comment = new mambo.Model(new Schema(
'Comments', ['post_id', 'created'],
{
'post_id': NumberField,
'created': DateField,
'comment': StringField,
'author': StringField,
'liked_by': JSONField
}
), new Schema('Users', 'username', {
'username': StringField,
'name': StringField,
'lastCommentPosted': DateField
})
);
Comment.getAll = function(postId, cb){
this.objects('comments', postId)
.limit(5)
.fetch().then(function(comments){
cb(null, comments);
}, function(err){
cb(err, null);
});
};
Comment.post = function(postId, author, comment, cb){
this.insert('comments',
{
'post_id': postId,
'created': new Date(),
'author': author,
'comment': comment,
'liked_by': []
})
.commit()
.then(function(){
cb(null);
}, function(err){
cb(err);
}
);
};
module.exports = Comment; |
/*
@ author leeenx
@ version 1.0.0
@ data: 2015-12-07
@ 页面翻页
@ 用法:
$.cardslider(
{
container: "#wrap",
direction:'Y',
cover: 0,//封面索引
scale:true,
offset:50,
duration:300,
infinite:true,
onchange:function(o,i){
//通过this[0]可以取对应的分页哦
//o滑出页索引,i滑入页索引
console.log(o,i);
}
}
);
或是直接:
$("#wrap").cardSlider(
{
direction:'Y',
cover: 0,//封面索引
scale:true,
offset:50,
duration:300,
infinite:true,
onchange:function(o,i){
//通过this[0]可以取对应的分页哦
//o滑出页索引,i滑入页索引
console.log(o,i);
}
}
);
*/
define("cardSlider",function(require,exports,module){
var webkit=require("prefix"),isDom=require("isDom");
var _cardSlider=function(arg){
/*
@参数改成object类型,调用更灵活,也能起到return object;一样的效果
arg={
dom:string|HTMLDOM,
direction:'X'|'Y'
}
*/
var dom,isY,translateL='',translateR='',originXorY,pageXorY,ch=document.documentElement.clientHeight,needScale,transformOriginT,transformOriginB;
if(typeof(arg.container)=="string"){
dom=document.querySelector(arg.container);
if(dom){
throw('Container unexist!');//分页容器不存在
return ;
}
}else if(!arg.container.nodeType||arg.container.nodeType!=1){
throw('Container unexist!');//分页容器不存在
return ;
}else{
dom=arg.container;
}
arg.onchange=typeof(arg.onchange)=="function"?arg.onchange:function(){};
arg.duration=arg.duration||300;
arg.duration2=arg.duration2||100;
arg.direction=arg.direction||'Y';
needScale=!!arg.scale;
isY=arg.direction=="Y";
isY?(translateL='translate3d(0,',translateR=',0)'):(translateL='translate3d(',translateR=',0,0)');//默认是垂直方向翻页
pageXorY=isY?'pageY':'pageX';
transformOriginT=isY?'center top':'left center';
transformOriginB=isY?'center bottom':'right center';
ch=isY?document.documentElement.clientHeight:document.documentElement.clientWidth;
//var page=dom.querySelectorAll("[haloslider]");
var page=function(){
//改用容器下的子元素为它的分页
var childNodes=dom.childNodes,res=[];
for(var i=0,len=childNodes.length;i<len;++i){
if(dom.childNodes[i].nodeType==1){
//是节点
res.push(dom.childNodes[i]);
}
}
return res;
}();
if(!page.length)return ;//没有分页存在
var totalPage=page.length;
arg.cover=arg.cover||0;//翻页初始化第一页
if(arg.cover>=totalPage)arg.cover=totalPage-1;//超过最后一页,就认为是最后一页
else if(arg.cover<0)arg.cover=0;//小于0,就认为是第一页
var cur=arg.cover,next=cur+1,prev=cur-1;
if(arg.infinite){
if(prev<0)prev=totalPage-1;
if(next>totalPage-1)next=0;
}
dom.parentNode.style.overflow="hidden";
window.addEventListener('resize',function(){//动态获取高度
ch=isY?document.documentElement.clientHeight:document.documentElement.clientWidth;
});
var timeoutId,timeCb,
_setTimeout=function(cb,time){
//单线程setTimeout代替函数
timeCb=cb;
timeoutId=setTimeout(function(){
cb();
timeCb=cb=null;
},time);
},_finishedTimeout=function(){
clearTimeout(timeoutId);
typeof(timeCb)=="function"&&timeCb();
};
var isTopEdge=false,isBottomEdge=false;//触底触顶
var _touchstart=function(e){
var touches=e.targetTouches||e.changedTouches,touch=touches[0];
x=touch.pageX,y=touch.pageY;
originXorY=touch[pageXorY];
_finishedTimeout();
},
_touchmove1=function(e){
var touches=e.targetTouches||e.changedTouches,touch=touches[0],curXorY=touch[pageXorY];
var offset=curXorY-originXorY;
page[prev].style[webkit+"transform"]=translateL+(offset-ch)+'px'+translateR;
//page[cur].style[webkit+"transform"]=translateL+offset+'px'+translateR;
page[next].style[webkit+"transform"]=translateL+(offset+ch)+'px'+translateR;
doScale(offset);
},
_touchmove2=function(e){
var touches=e.targetTouches||e.changedTouches,touch=touches[0],curXorY=touch[pageXorY];
var offset=curXorY-originXorY;
if(cur<totalPage-1&&cur>0){
page[prev].style[webkit+"transform"]=translateL+(offset-ch)+'px'+translateR;
//page[cur].style[webkit+"transform"]=translateL+offset+'px'+translateR;
page[next].style[webkit+"transform"]=translateL+(offset+ch)+'px'+translateR;
doScale(offset);
isTopEdge=isBottomEdge=false;
}else{
if(offset>0){
if(cur==0){
//触顶
page[cur].style[webkit+"transform"]=translateL+offset/3+'px'+translateR;
page[next].style[webkit+"transform"]=translateL+ch+'px'+translateR;
isTopEdge=true;
}else{
//向上
page[prev].style[webkit+"transform"]=translateL+(offset-ch)+'px'+translateR;
//page[cur].style[webkit+"transform"]=translateL+offset+'px'+translateR;
doScale(offset);
isBottomEdge=false;
}
}else if(offset<0){
if(cur==totalPage-1){
//触底
page[cur].style[webkit+"transform"]=translateL+offset/3+'px'+translateR;
page[prev].style[webkit+"transform"]=translateL+(-1*ch)+'px'+translateR;
isBottomEdge=true;
}else{
//向下
//page[cur].style[webkit+"transform"]=translateL+offset+'px'+translateR;
page[next].style[webkit+"transform"]=translateL+(offset+ch)+'px'+translateR;
doScale(offset);
isTopEdge=false;
}
}
}
},
doScale=function(offset){
//将scale操作单独封装起来,因为多次调用,且方法一样
//需要scale模式
if(needScale){
if(offset>0){
page[cur].style[webkit+"transform-origin"]=transformOriginB;
page[cur].style[webkit+"transform"]="scale("+(1-.2*Math.abs(offset/ch))+") translateZ(0)";
}else if(offset<0){
page[cur].style[webkit+"transform-origin"]=transformOriginT;
page[cur].style[webkit+"transform"]="scale("+(1-.2*Math.abs(offset/ch))+") translateZ(0)";
}else{
page[cur].style[webkit+"transform-origin"]='';
page[cur].style[webkit+"transform"]='';
}
}
},
_touchend1=function(e){
var touches=e.changedTouches||e.targetTouches,touch=touches[0],curXorY=touch[pageXorY];
var offset=curXorY-originXorY;
if(offset>0&&offset>=arg.offset){
//往下
var transition=webkit+'transform '+arg.duration/1000+'s linear';
page[prev].style[webkit+'transition']=transition,page[prev].style[webkit+"transform"]=translateL+0+'px'+translateR;
if(needScale){
page[cur].style[webkit+'transition']=transition,page[cur].style[webkit+"transform"]="scale(.8,.8) translateZ(0)";
}
if(next<=totalPage-1)page[next].style[webkit+"transform"]=translateL+ch+'px'+translateR;
var _cur=cur,_prev=prev,_next=next;
_setTimeout(function(){
page[_cur].style[webkit+'transition']='';
page[_cur].style[webkit+'transform']=translateL+ch+'px'+translateR;
page[_cur].style.zIndex='1';
page[_prev].style[webkit+'transition']='';
page[_prev].style.zIndex='0';
arg.onchange.call(page,_cur,_prev);
},arg.duration);
fixed(-1);
}else if(offset<0&&-1*offset>=arg.offset){
//往上
var transition=webkit+'transform '+arg.duration/1000+'s linear';
if(needScale){
page[cur].style[webkit+'transition']=transition,page[cur].style[webkit+"transform"]="scale(.8,.8) translateZ(0)";
}
page[next].style[webkit+'transition']=transition,page[next].style[webkit+"transform"]=translateL+0+'px'+translateR;
if(prev>=0)page[prev].style[webkit+"transform"]=translateL+(-1*ch)+'px'+translateR;
var _cur=cur,_prev=prev,_next=next;
_setTimeout(function(){
page[_cur].style[webkit+'transition']='';
page[_cur].style[webkit+'transform']=translateL+(-1*ch)+'px'+translateR;
page[_cur].style.zIndex='1';
page[_next].style[webkit+'transition']='';
page[_next].style.zIndex='0';
arg.onchange.call(page,_cur,_next);
},arg.duration);
fixed(1);
}else if(offset!=0){
//回弹
var transition=webkit+'transform '+arg.duration2/1000+'s linear';
if(prev>=0)page[prev].style[webkit+'transition']=transition,page[prev].style[webkit+"transform"]=translateL+(-1*ch)+'px'+translateR;
if(needScale){
page[cur].style[webkit+'transition']=transition,page[cur].style[webkit+"transform"]="scale(1,1) translateZ(0)";
}
if(next<=totalPage-1)page[next].style[webkit+'transition']=transition,page[next].style[webkit+"transform"]=translateL+ch+'px'+translateR;
var _cur=cur,_prev=prev,_next=next;
_setTimeout(function(){
if(!isMoving){
page[_cur].style[webkit+'transition']='';
}
if(prev>=0)page[_prev].style[webkit+'transition']='';
if(next<=totalPage-1)page[_next].style[webkit+'transition']='';
},arg.duration2);
}
},
isMoving=false,
_touchend2=function(e){
if(isTopEdge||isBottomEdge){
//如触底或触顶了,回弹
page[cur].style[webkit+'transition']=webkit+'transform '+arg.duration2/1000+'s linear'
page[cur].style[webkit+"transform"]=translateL+0+'px'+translateR;
_setTimeout(function(){
isTopEdge=isBottomEdge=false;
page[cur].style[webkit+'transition']='';
},arg.duration2);
}else{
_touchend1(e);
}
},
fixed=function(n){
//确定cur,next,prev的数值
cur=cur+n,prev=cur-1,next=cur+1;
if(!arg.infinite)return;
if(cur>=totalPage){
cur=0;
prev=totalPage-1;
next=1;
}else if(cur==totalPage-1){
next=0;
}else if(cur<0){
cur=totalPage-1;
prev=cur-1;
next=0;
}else if(cur==0){
prev=totalPage-1;
}
},
bindEvent=function(){
for(var i=0,len=page.length;i<len;++i){
page[i].addEventListener('touchstart',_touchstart);
if(arg.infinite){
page[i].addEventListener('touchmove',_touchmove1);
page[i].addEventListener('touchend',_touchend1);
page[i].addEventListener('touchcancel',_touchend1);
}else{
//将方法分拆写,可以提高touchmove的效率
page[i].addEventListener('touchmove',_touchmove2);
page[i].addEventListener('touchend',_touchend2);
page[i].addEventListener('touchcancel',_touchend2);
}
};
},
unbindEvent=function(){
for(var i=0,len=page.length;i<len;++i){
page[i].removeEventListener('touchstart',_touchstart);
if(arg.infinite){
page[i].removeEventListener('touchmove',_touchmove1);
page[i].removeEventListener('touchend',_touchend1);
page[i].removeEventListener('touchcancel',_touchend1);
}else{
//将方法分拆写,可以提高touchmove的效率
page[i].removeEventListener('touchmove',_touchmove2);
page[i].removeEventListener('touchend',_touchend2);
page[i].removeEventListener('touchcancel',_touchend2);
}
};
};
for(var i=0,len=page.length;i<len;++i){
/*arg.cover初始化首页*/
page[i].style.cssText="position:absolute; left:0; top:0; width:100%; height:100%; "+(arg.cover==i?" z-index:0;":webkit+"transform:"+translateL+ch+"px"+translateR+"; z-index:1;");
}
bindEvent();//初始化绑定
var x=0,y=0;
var o={};
o.lock=function(){
//锁定
unbindEvent();
},
o.unlock=function(){
//解锁
bindEvent();
},
o.move=function(index){
index=parseInt(index)||0;
if(index==cur)return ;
if(index>=0||index<=totalPage-1){
//合法页码
var transition=webkit+'transform '+arg.duration/1000+'s linear',flag=index>cur?-1:1;
if(arg.infinite){
flag=page[index].style[webkit+'transform'].indexOf('-')>=0?1:-1;
}
console.log(flag);
//page[cur].style[webkit+'transition']=transition,page[cur].style[webkit+"transform"]=translateL+(flag*ch)+'px'+translateR;
if(needScale){
if(flag==-1){
page[cur].style[webkit+'transform-origin']=transformOriginT;
}else{
page[cur].style[webkit+'transform-origin']=transformOriginB;
}
page[cur].style[webkit+'transition']=transition,page[cur].style[webkit+"transform"]='scale(.8,.8) translateZ(0)';
}
page[index].style[webkit+'transition']=transition,page[index].style[webkit+"transform"]=translateL+0+'px'+translateR;
isMoving=true;
var _cur=cur,_next=index;
_setTimeout(function(){
isMoving=false;
page[_cur].style[webkit+'transition']='';
page[_cur].style[webkit+'transform-origin']='';
page[_cur].style[webkit+'transform']='';
page[_cur].style.zIndex=1;
page[_cur].style[webkit+'transform']=translateL+(flag*ch)+'px'+translateR;
page[_next].style[webkit+'transition']='';
page[_next].style.zIndex=0;
arg.onchange.call(page,_cur,_next);
},arg.duration);
if(arg.infinite){
cur=index,prev=cur-1,next=cur+1;
if(prev<0)prev=totalPage-1;
if(next>totalPage-1)next=0;
}
else{
cur=index,prev=cur-1,next=cur+1;
}
}
};
return o;
};
module.exports=function(arg){
if(isDom(this)){
//是fn扩展过来的
arg.container=this;
_cardSlider(arg);
}else if(Object.prototype.toString.call(this)=="[object Array]"){
for(var i=0,len=this.length;i<len;++len){
arg.container=this[i];
isDom(this[i])&&_cardSlider(arg);
}
}else{
_cardSlider(arg);
}
};
window.$&&($.cardSlider=$.fn.cardSlider=module.exports);
});
|
var stage;
var queue;
var grid;
function init() {
//var $j = jQuery.noConflict();
$(window).resize(function(e) {
// Make canvas full screen
var canvas = document.getElementById('canvas');
canvas.height = window.innerHeight - 5;
canvas.width = window.innerWidth;
// Make canvas not blurry
var context = canvas.getContext('2d');
context.webkitImageSmoothingEnabled = false;
context.mozImageSmoothingEnabled = false;
context.imageSmoothingEnabled = false;
});
$(window).resize();
/** Stage Setup **/
stage = new createjs.Stage('canvas');
createjs.Ticker.setFPS(60);
createjs.Ticker.addEventListener("tick", tick);
/** Image Progress Bar **/
var loading = new Loading();
loading.name = "loading";
stage.addChild(loading);
/** Load assets into queue **/
queue = new createjs.LoadQueue();
queue.on("fileload", handleFileLoad, this);
queue.on("complete", handleComplete, this);
queue.on("progress", handleFileProgress, this);
$.get('manifest.json?' + Math.random(), function(data) {
if (typeof data == 'string')
queue.loadManifest(JSON.parse(data));
else
queue.loadManifest(data);
});
}
function tick() {
stage.update();
}
function handleFileLoad(q) {
}
function handleFileProgress(e) {
var p = e.progress;
var loading = stage.getChildByName('loading');
loading.progress(p);
}
function handleComplete(e) {
stage.removeChild(stage.getChildByName('loading'));
// keybindings
Mousetrap.bind('d', function() {
});
var img = queue.getItem('rpgTile040');
var bitmap = new createjs.Bitmap(img.src);
grid = new Grid(5, 5, 64, 64);
grid.fill(bitmap.clone());
stage.addChild(grid);
}
|
/*
* Google search pagemod functions
*
* @author Arend-Jan Tetteroo <aj@thegreenwebfoundation.org>
* @copyright Cleanbits/The Green Web Foundation 2010-2014
*/
/**
* On Request, find all hrefs and assign green or grey icon
*/
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.data){
data = request.data;
var links = $('.TGWF');
$(links).each(function (i) {
var loc = getUrl($(this).parent().attr('href'));
if(data[loc]){
$(this).html(getResultNode(data[loc]).append(' '));
}
});
}
});
/**
* If document is ready, find the urls to check
*/
$(document).ready(function() {
chrome.storage.local.get("tgwf_search_disabled", function(items) {
if(items.tgwf_search_disabled == 1){
// Green web search is disabled, return
return;
}
$('#footer').append("<p id='thegreenweb' style='text-align:center;'>" + getLinkImage('green','The Green Web extension shows if a site is sustainably hosted') + ' The Green Web is enabled<span id=\'thegreenwebenabled\'/></p>');
(function checkLoop() {
// Check if search results have 'greenweb' link
var results = $('#res').find('h3.r > a');
if ( $('.TGWF').length != results.length) {
// Remove all cleanbits links
$('.TGWF').remove();
// Check urls to see if search results are green/grey
var locs = {};
$(results).each(function (i) {
// Add TGWF link to each google listing
$(this).prepend($('<span>', { class: 'TGWF'}).append(getImageNode('greenquestion')).append(' '));
var loc = getUrl($(this).attr('href'));
locs[loc] = loc;
});
if(Object.keys(locs).length > 0) {
chrome.runtime.sendMessage({locs: locs}, function(response) {});
}
}
setTimeout(checkLoop, 100);
})();
});
}); |
var config = require(__dirname + '/../config.json');
var _ = require('lodash');
var Q = require('q');
var mongoose = require("mongoose");
var InventoryModel = require("../models/inventory.model");
var UserModel = require("../models/user.model");
var service = {};
service.getInventories = getInventories;
service.getInventory = getInventory;
service.addInventory = addInventory;
service.updateInventory = updateInventory;
service.deleteInventory = deleteInventory;
service.assignUser = assignUser;
service.changeStatus = changeStatus;
service.getMyInventories = getMyInventories;
module.exports = service;
function getInventories() {
return new Promise((resolve, reject) => {
var aggregateQuery = [
{ $match: {} },
{ $lookup: { from: "users", localField: "userId", foreignField: "_id", as: "assignedUser" } },
{ $lookup: { from: "clients", localField: "clientId", foreignField: "_id", as: "client" } },
{ $unwind: { path: "$assignedUser", preserveNullAndEmptyArrays: true } }
//{ $project: {} }
];
InventoryModel.aggregate(aggregateQuery).exec().then((data) => {
resolve(data);
}).catch((error) => {
console.log(error);
reject({ error: (error.errmsg ? error.errmsg : "Unexpected error") });
});
});
}
function getInventory(InventoryId) {
return new Promise((resolve, reject) => {
InventoryModel.findOne({ _id: mongoose.Types.ObjectId(InventoryId) }).lean().exec().then((data) => {
resolve(data);
}).catch((error) => {
reject({ error: error.errmsg });
});
});
}
function addInventory(InventoryData) {
return new Promise((resolve, reject) => {
if (InventoryData.userId) {
InventoryData.userId = mongoose.Types.ObjectId(InventoryData.userId);
}
InventoryObj = new InventoryModel(InventoryData);
InventoryObj.save(function (error, data) {
if (error) {
reject({ error: error });
} else {
resolve(data);
}
});
});
}
function updateInventory(InventoryId, InventoryData) {
return new Promise((resolve, reject) => {
if (InventoryData.userId) {
InventoryData.userId = mongoose.Types.ObjectId(InventoryData.userId);
}
InventoryModel.updateOne({ _id: mongoose.Types.ObjectId(InventoryId) }, { $set: InventoryData }).exec().then((data) => {
resolve(data);
}).catch((error) => {
reject({ error: error.errmsg });
});
});
}
function deleteInventory(InventoryId) {
return new Promise((resolve, reject) => {
InventoryModel.deleteOne({ _id: mongoose.Types.ObjectId(InventoryId) }).lean().exec().then((data) => {
resolve(data);
}).catch((error) => {
reject({ error: error.errmsg });
});
});
}
function assignUser(InventoryId, assignData) {
return new Promise((resolve, reject) => {
var pdata = {
userId: null
}
var inventoryAction = "Assign";
if (assignData.userId) {
pdata.userId = mongoose.Types.ObjectId(assignData.userId);
pdata.deviceStatus = "Assigned";
} else {
pdata.deviceStatus = "Available";
inventoryAction = "Unassign";
}
InventoryModel.findById(InventoryId, function (err, InventoryObj) {
if (err) return reject(err);
InventoryObj.history.push({
inventoryAction: inventoryAction,
prevValue: InventoryObj.userId,
newValue: pdata.userId,
comment: assignData.comment
});
InventoryObj.userId = pdata.userId;
InventoryObj.deviceStatus = pdata.deviceStatus;
InventoryObj.latestComment = assignData.comment;
InventoryObj.save(function (error) {
if (error) reject({ error });
resolve(InventoryObj);
});
});
});
}
function changeStatus(InventoryId, inventoryData) {
return new Promise((resolve, reject) => {
//if (["Repair", "Repair Done", "Scrap", "Available For Freshers", "Assigned Multiple", "Assigned OE Client", "Available OE Client", "Collect Laptop", "Yet to join", "Lost"].includes(inventoryData.deviceStatus)) {
InventoryModel.findById(InventoryId, function (err, InventoryObj) {
if (err) return handleError(err);
if (inventoryData.deviceStatus == "Repair Done") {
if (InventoryObj.userId && String(InventoryObj.userId).length > 0) {
inventoryData.deviceStatus = "Assigned";
} else {
inventoryData.deviceStatus = "Available";
}
}
InventoryObj.history.push({
inventoryAction: "Status Change",
prevValue: InventoryObj.deviceStatus,
newValue: inventoryData.deviceStatus,
affectedDate: inventoryData.affectedDate,
comment: inventoryData.comment
});
InventoryObj.deviceStatus = inventoryData.deviceStatus;
InventoryObj.latestComment = inventoryData.comment;
InventoryObj.save(function (error) {
if (error) reject(error);
resolve(InventoryObj);
});
});
// } else {
// reject({ message: "Invalid device status value!" });
// }
});
}
function getMyInventories(userId) {
return new Promise((resolve, reject) => {
InventoryModel.find({ userId: mongoose.Types.ObjectId(userId) }).exec().then((data) => {
resolve(data);
}).catch((error) => {
console.log(error);
reject({ error: (error.errmsg ? error.errmsg : "Unexpected error") });
});
});
} |
"use strict"
module.exports = function(sequelize, DataTypes) {
var Accounts = sequelize.define("Accounts", {
username: {
type: DataTypes.STRING,
primaryKey: true
},
name: {
type: DataTypes.STRING
},
email_id: {
type: DataTypes.STRING
},
password: {
type: DataTypes.STRING
}
}, {
tableName: 'accounts'
});
return Accounts;
}
|
var numeral = require('../../numeral'),
language = require('../../locale/sk');
numeral.locale('sk', language);
exports['language:sk'] = {
setUp: function (callback) {
numeral.locale('sk');
callback();
},
tearDown: function (callback) {
numeral.locale('en');
callback();
},
format: function (test) {
test.expect(16);
var tests = [
[10000,'0,0.0000','10 000,0000'],
[10000.23,'0,0','10 000'],
[-10000,'0,0.0','-10 000,0'],
[10000.1234,'0.000','10000,123'],
[-10000,'(0,0.0000)','(10 000,0000)'],
[-0.23,'.00','-,23'],
[-0.23,'(.00)','(,23)'],
[0.23,'0.00000','0,23000'],
[1230974,'0.0a','1,2mil.'],
[1460,'0a','1tis.'],
[-104000,'0a','-104tis.'],
[1,'0o','1.'],
[52,'0o','52.'],
[23,'0o','23.'],
[100,'0o','100.'],
[1,'0[.]0','1']
];
for (var i = 0; i < tests.length; i++) {
test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]);
}
test.done();
},
currency: function (test) {
test.expect(4);
var tests = [
[1000.234,'$0,0.00','€1 000,23'],
[-1000.234,'($0,0)','(€1 000)'],
[-1000.234,'$0.00','-€1000,23'],
[1230974,'($0.00a)','€1,23mil.']
];
for (var i = 0; i < tests.length; i++) {
test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]);
}
test.done();
},
percentages: function (test) {
test.expect(4);
var tests = [
[1,'0%','100%'],
[0.974878234,'0.000%','97,488%'],
[-0.43,'0%','-43%'],
[0.43,'(0.000%)','43,000%']
];
for (var i = 0; i < tests.length; i++) {
test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]);
}
test.done();
},
unformat: function (test) {
test.expect(9);
var tests = [
['10 000,123',10000.123],
['(0,12345)',-0.12345],
['(€1,23mil.)',-1230000],
['10tis.',10000],
['-10tis.',-10000],
['23e',23],
['€10 000,00',10000],
['-76%',-0.76],
['2:23:57',8637]
];
for (var i = 0; i < tests.length; i++) {
test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]);
}
test.done();
}
};
|
/*eslint-env node, mocha */
/*global expect */
/*eslint no-console: 0*/
'use strict';
// Uncomment the following lines to use the react test utilities
// import TestUtils from 'react-addons-test-utils';
import createComponent from 'helpers/shallowRenderHelper';
import CarrierComponent from 'components//CarrierComponent.js';
describe('CarrierComponent', () => {
let component;
beforeEach(() => {
component = createComponent(CarrierComponent);
});
it('should have its component name as default className', () => {
expect(component.props.className).to.equal('carrier-component');
});
});
|
"use strict";
// load up the badge model
const BadgeModel = require('../models/badge');
// =============================================================================
// Creates a new badge =========================================================
// =============================================================================
let createBadge = (name, position, expiresOn, photoURL, done) => {
if (name)
name = name.toLowerCase(); // To avoid case sensitivity of badge name
process.nextTick(() => {
BadgeModel.findOneAndUpdate({
'name': name
}, {
name,
position,
expiresOn,
photoURL,
isActive: new Date() <= new Date(expiresOn),
createdOn: new Date()
}, {
upsert: true,
new: true
}, (err, badge) => {
if (err)
return done(err);
return done(null, badge);
});
});
};
// =============================================================================
// Retrives all the valid badges ===============================================
// =============================================================================
let getBadges = (done) => {
validateBadges(); // Validates badges
let query = BadgeModel.find({
isActive: true
});
query.sort({
name: 'asc'
});
process.nextTick(() => {
query.exec((err, badges) => {
if (err)
done(err);
else {
if (badges.length) {
badges.map(function(item, index) {
item.photoURL = process.env.BADGE_IMAGE_PATH_URL + item.photoURL;
return;
});
done(badges);
} else
done({
message: 'No valid badge is available'
});
}
});
});
};
// =============================================================================
// Validates all the bdages into the database ==================================
// =============================================================================
let validateBadges = () => {
let query = {
isActive: true,
expiresOn: {
$lt: new Date()
}
};
BadgeModel.update(query, {
isActive: false
}, {
multi: true
}, (err, rawResponse) => {});
};
module.exports = {
createBadge,
getBadges
};
|
const assert = require('assert');
const convertQueryToMap = require('./convert-query-to-map');
let q = 'user.name.firstname=Bob&user.name.lastname=Smith&user.favoritecolor=Light%20Blue';
let out = {
'user': {
'name': {
'firstname': 'Bob',
'lastname': 'Smith'
},
'favoritecolor': 'Light Blue'
}
};
describe('Converts a URL Query String into an object map', function () {
it('Example', function () {
assert.deepEqual(convertQueryToMap(q), out);
});
}); |
function Keeper(id, seeds, transport, options) {
this.id = id;
this.seeds = seeds;
this.transport = transport;
this.options = options || {};
}
module.exports=function(id, seeds, transport, options){
return new Keeper(id, seeds, transport, options);
};
|
'use strict'
var PurchaseOrder = require('./purchase-order');
var map = require('../map');
module.exports = class POGarmentGeneral extends PurchaseOrder {
constructor(source) {
super(source, map.po.type.POGarmentGeneral);
this.iso = 'FM-6.00-06-005/R2';
}
} |
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* SHA-256 (FIPS 180-4) implementation in JavaScript (c) Chris Veness 2002-2017 */
/* MIT Licence */
/* www.movable-type.co.uk/scripts/sha256.html */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
'use strict';
/**
* SHA-256 hash function reference implementation.
*
* This is an annotated direct implementation of FIPS 180-4, without any optimisations. It is
* intended to aid understanding of the algorithm rather than for production use.
*
* While it could be used where performance is not critical, I would recommend using the ‘Web
* Cryptography API’ (developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest) for the browser,
* or the ‘crypto’ library (nodejs.org/api/crypto.html#crypto_class_hash) in Node.js.
*
* See csrc.nist.gov/groups/ST/toolkit/secure_hashing.html
* csrc.nist.gov/groups/ST/toolkit/examples.html
*/
class Sha256 {
/**
* Generates SHA-256 hash of string.
*
* @param {string} msg - (Unicode) string to be hashed.
* @param {Object} [options]
* @param {string} [options.msgFormat=string] - Message format: 'string' for JavaScript string
* (gets converted to UTF-8 for hashing); 'hex-bytes' for string of hex bytes ('616263' ≡ 'abc') .
* @param {string} [options.outFormat=hex] - Output format: 'hex' for string of contiguous
* hex bytes; 'hex-w' for grouping hex bytes into groups of (4 byte / 8 character) words.
* @returns {string} Hash of msg as hex character string.
*/
static hash(msg, options) {
const defaults = { msgFormat: 'string', outFormat: 'hex' };
const opt = Object.assign(defaults, options);
// note use throughout this routine of 'n >>> 0' to coerce Number 'n' to unsigned 32-bit integer
switch (opt.msgFormat) {
default: // default is to convert string to UTF-8, as SHA only deals with byte-streams
case 'string': msg = utf8Encode(msg); break;
case 'hex-bytes': msg = hexBytesToString(msg); break; // mostly for running tests
}
// constants [§4.2.2]
const K = [
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
// initial hash value [§5.3.3]
const H = [
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
// PREPROCESSING [§6.2.1]
msg += String.fromCharCode(0x80); // add trailing '1' bit (+ 0's padding) to string [§5.1.1]
// convert string msg into 512-bit blocks (array of 16 32-bit integers) [§5.2.1]
const l = msg.length / 4 + 2; // length (in 32-bit integers) of msg + ‘1’ + appended length
const N = Math.ceil(l / 16); // number of 16-integer (512-bit) blocks required to hold 'l' ints
const M = new Array(N); // message M is N×16 array of 32-bit integers
for (let i = 0; i < N; i++) {
M[i] = new Array(16);
for (let j = 0; j < 16; j++) { // encode 4 chars per integer (64 per block), big-endian encoding
M[i][j] = (msg.charCodeAt(i * 64 + j * 4 + 0) << 24) | (msg.charCodeAt(i * 64 + j * 4 + 1) << 16)
| (msg.charCodeAt(i * 64 + j * 4 + 2) << 8) | (msg.charCodeAt(i * 64 + j * 4 + 3) << 0);
} // note running off the end of msg is ok 'cos bitwise ops on NaN return 0
}
// add length (in bits) into final pair of 32-bit integers (big-endian) [§5.1.1]
// note: most significant word would be (len-1)*8 >>> 32, but since JS converts
// bitwise-op args to 32 bits, we need to simulate this by arithmetic operators
const lenHi = ((msg.length - 1) * 8) / Math.pow(2, 32);
const lenLo = ((msg.length - 1) * 8) >>> 0;
M[N - 1][14] = Math.floor(lenHi);
M[N - 1][15] = lenLo;
// HASH COMPUTATION [§6.2.2]
for (let i = 0; i < N; i++) {
const W = new Array(64);
// 1 - prepare message schedule 'W'
for (let t = 0; t < 16; t++) W[t] = M[i][t];
for (let t = 16; t < 64; t++) {
W[t] = (Sha256.σ1(W[t - 2]) + W[t - 7] + Sha256.σ0(W[t - 15]) + W[t - 16]) >>> 0;
}
// 2 - initialise working variables a, b, c, d, e, f, g, h with previous hash value
let a = H[0], b = H[1], c = H[2], d = H[3], e = H[4], f = H[5], g = H[6], h = H[7];
// 3 - main loop (note '>>> 0' for 'addition modulo 2^32')
for (let t = 0; t < 64; t++) {
const T1 = h + Sha256.Σ1(e) + Sha256.Ch(e, f, g) + K[t] + W[t];
const T2 = Sha256.Σ0(a) + Sha256.Maj(a, b, c);
h = g;
g = f;
f = e;
e = (d + T1) >>> 0;
d = c;
c = b;
b = a;
a = (T1 + T2) >>> 0;
}
// 4 - compute the new intermediate hash value (note '>>> 0' for 'addition modulo 2^32')
H[0] = (H[0] + a) >>> 0;
H[1] = (H[1] + b) >>> 0;
H[2] = (H[2] + c) >>> 0;
H[3] = (H[3] + d) >>> 0;
H[4] = (H[4] + e) >>> 0;
H[5] = (H[5] + f) >>> 0;
H[6] = (H[6] + g) >>> 0;
H[7] = (H[7] + h) >>> 0;
}
// convert H0..H7 to hex strings (with leading zeros)
for (let h = 0; h < H.length; h++) H[h] = ('00000000' + H[h].toString(16)).slice(-8);
// concatenate H0..H7, with separator if required
const separator = opt.outFormat == 'hex-w' ? ' ' : '';
return H.join(separator);
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
function utf8Encode(str) {
try {
return new TextEncoder().encode(str, 'utf-8').reduce((prev, curr) => prev + String.fromCharCode(curr), '');
} catch (e) { // no TextEncoder available?
return unescape(encodeURIComponent(str)); // monsur.hossa.in/2012/07/20/utf-8-in-javascript.html
}
}
function hexBytesToString(hexStr) { // convert string of hex numbers to a string of chars (eg '616263' -> 'abc').
const str = hexStr.replace(' ', ''); // allow space-separated groups
return str == '' ? '' : str.match(/.{2}/g).map(byte => String.fromCharCode(parseInt(byte, 16))).join('');
}
}
/**
* Rotates right (circular right shift) value x by n positions [§3.2.4].
* @private
*/
static ROTR(n, x) {
return (x >>> n) | (x << (32 - n));
}
/**
* Logical functions [§4.1.2].
* @private
*/
static Σ0(x) { return Sha256.ROTR(2, x) ^ Sha256.ROTR(13, x) ^ Sha256.ROTR(22, x); }
static Σ1(x) { return Sha256.ROTR(6, x) ^ Sha256.ROTR(11, x) ^ Sha256.ROTR(25, x); }
static σ0(x) { return Sha256.ROTR(7, x) ^ Sha256.ROTR(18, x) ^ (x >>> 3); }
static σ1(x) { return Sha256.ROTR(17, x) ^ Sha256.ROTR(19, x) ^ (x >>> 10); }
static Ch(x, y, z) { return (x & y) ^ (~x & z); } // 'choice'
static Maj(x, y, z) { return (x & y) ^ (x & z) ^ (y & z); } // 'majority'
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
if (typeof module != 'undefined' && module.exports) module.exports = Sha256; // ≡ export default Sha256 |
IntlMessageFormat.__addLocaleData({locale:"tn",pluralRuleFunction:function(e,t){return t?"other":1==e?"one":"other"}}); |
'use strict';
//var procClinFreeApp = angular.module('procClinFreeApp', ['pageFactory', 'clientFactory', 'drugFactory']);
var pcsApp = angular.module('procClinSafeApp', ['ngRoute','ui.bootstrap','ngMaterial', 'material.svgAssetsCache',
'pageFactory', 'reportService', 'clientService', 'drugService','studyService', 'deliverableService']);
pcsApp.config(function($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl : 'pages/report_wizard.html',
controller : 'reportWizardController'
})
.when('/wizard', {
templateUrl : 'pages/report_wizard.html',
controller : 'reportWizardController'
})
// route for the about page
.when('/settings', {
templateUrl : 'pages/settings.html',
controller : 'settingsController'
})
// route for the contact page
.when('/status', {
templateUrl : 'pages/status.html',
controller : 'statusController'
});
}); |
'use strict';
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var istanbul = require('gulp-istanbul');
var coveralls = require('gulp-coveralls');
var mocha = require('gulp-spawn-mocha');
var batch = require('gulp-batch');
var betterConsole = require('better-console');
var jsdoc = require('gulp-jsdoc');
var jsPaths = ['*.js', 'lib/**/*.js', 'test/**/*.js'];
var test = function(cb) {
return gulp.src(['lib/**/*.js', 'index.js'])
.pipe(istanbul())
.on('finish', function() {
gulp.src(['test/*.js'])
.pipe(mocha({reporter: 'spec', istanbul: true}))
.on('end', cb);
});
};
var lint = function() {
return gulp.src(jsPaths)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
};
var clear = function() {
betterConsole.clear();
};
gulp.task('default', ['lint', 'test', 'jsdoc']);
gulp.task('ci', ['lint', 'test', 'coveralls']);
gulp.task('watch', function() {
gulp.watch(jsPaths, batch(function(events, cb) {
clear();
lint();
test(function() {
cb();
});
}));
});
gulp.task('lint', function() {
lint();
});
gulp.task('test', function(cb) {
test(function() {
cb();
});
});
gulp.task('coveralls', ['test'], function() {
return gulp.src('coverage/lcov.info').pipe(coveralls());
});
gulp.task('jsdoc', function() {
return gulp.src(['lib/goldwasher.js', 'README.md'])
.pipe(jsdoc('./docs'));
}); |
window.addEventListener('load', function() {
var menu_open = false;
window.awe.init({
device_type: awe.AUTO_DETECT_DEVICE_TYPE,
settings: {
container_id: 'container',
fps: 30,
default_camera_position: { x:0, y:0, z:0 },
default_lights: [{
id: 'point_light',
type: 'point',
color: 0xFFFFFF
}]
},
ready: function() {
awe.util.require([
{
capabilities: ['gum','webgl'],
files: [
['lib/awe-standard-dependencies.js', 'lib/awe-standard.js'],
'lib/awe-standard-window_resized.js',
'lib/awe-standard-object_clicked.js',
'lib/awe-jsartoolkit-dependencies.js',
'lib/awe.marker_ar.js'
],
success: function() {
window.awe.setup_scene();
// Points of Interest
awe.pois.add({id: 'marker', position: {x: 0, y: 0, z: 10000}, visible: false});
awe.projections.add({
id: 'wormhole',
geometry: {shape: 'plane', height: 200, width: 200},
position: {x: 0, y: 0, z: 0},
rotation: {x: 0, z: 0},
material: {
type: 'phong',
color: 0x000000
}
}, {poi_id: 'marker'});
/*
awe.projections.add({
id: 'wormhole',
geometry: {shape: 'cube', height: 150, width: 150},
position: {x: 0, y: 0, z: 0},
rotation: {x: 0, z: 0},
material: {
type: 'phong',
color: 0x000000
}
}, {poi_id: 'marker'});
*/
/*
// Projections
awe.projections.add({
id: 'wormhole',
geometry: {shape: 'plane', height: 200, width: 200},
position: {x: 0, y: 0, z: 0},
rotation: {x: 0, z: 0},
material: {
type: 'phong',
color: 0x000000
}
}, {poi_id: 'marker'});
awe.projections.add({
id: 'ar_button_one',
geometry: {shape: 'cube', x: 60, y: 30, z: 5},
rotation: {y: 45},
position: {x: -5, y: -31, z: -5},
material: {
type: 'phong',
color: 0xFF0000
}
}, {poi_id: 'marker'});
awe.projections.add({
id: 'ar_button_two',
geometry: {shape: 'cube', x: 60, y: 30, z: 5},
rotation: {y: 45},
position: {x: -5, y: -31, z: -5},
material: {
type: 'phong',
color: 0xFF6600
}
}, {poi_id: 'marker'});
awe.projections.add({
id: 'ar_button_three',
geometry: {shape: 'cube', x: 110, y: 30, z: 5},
rotation: {y: 45},
position: {x: -5, y: -31, z: -5},
material: {
type: 'phong',
color: 0xFFFF00
}
}, {poi_id: 'marker'});
awe.projections.add({
id: 'ar_button_four',
geometry: {shape: 'cube', x: 150, y: 30, z: 5},
rotation: {y: 45},
position: {x: -5, y: -31, z: -5},
material: {
type: 'phong',
color: 0xFFFFFF
}
}, {poi_id: 'marker'});
awe.projections.add({
id: 'ar_button_five',
geometry: {shape: 'cube', x: 180, y: 30, z: 5},
rotation: {y: 45},
position: {x: -5, y: -31, z: -5},
material: {
type: 'phong',
color: 0x00FF00
}
}, {poi_id: 'marker'});
awe.projections.add({
id: 'ar_button_six',
geometry: {shape: 'cube', x: 150, y: 30, z: 5},
rotation: {y: 45},
position: {x: -5, y: -31, z: -5},
material: {
type: 'phong',
color: 0x0080FF
}
}, {poi_id: 'marker'});
awe.projections.add({
id: 'ar_button_seven',
geometry: {shape: 'cube', x: 100, y: 30, z: 5},
rotation: {y: 45},
position: {x: -5, y: -31, z: -5},
material: {
type: 'phong',
color: 0x8000FF
}
}, {poi_id: 'marker'}); */
awe.events.add([{
id: 'ar_tracking_marker',
device_types: {
pc: 1,
android: 1
},
register: function(handler) {
window.addEventListener('ar_tracking_marker', handler, false);
},
unregister: function(handler) {
window.removeEventListener('ar_tracking_marker', handler, false);
},
handler: function(event) {
if (event.detail) {
if (event.detail['64']) {
awe.pois.update({
data: {
visible: true,
position: {x: 0, y: 0, z: 0},
matrix: event.detail['64'].transform
},
where: {
id: 'marker'
}
});
awe.projections.update({
data: {
visible: true
},
where: {
id: 'wormhole'
}
});
} else if (menu_open) {
awe.projections.update({
data: {
visible: false
},
where: {
id: 'wormhole'
}
});
}
else {
awe.pois.update({
data: {
visible: false
},
where: {
id: 'marker'
}
});
}
awe.scene_needs_rendering = 1;
}
}
}]);
window.addEventListener('object_clicked', function(e) {
switch (e.detail.projection_id) {
case 'wormhole':
//alert("wormhole1");
window.open('http://www.google.de', '_blank');
/* request.open('GET', 'http://www.google.de', true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
var data = JSON.parse(request.responseText);
alert(data);
console.log(data);
}
};
request.send();*/
//alert("wormhole2");
/*
if (!menu_open) {
alert("offen");
awe.projections.update({
data: {
animation: {
duration: 1
},
position: {y: 35}
},
where: {id: 'ar_button_one'}
});
awe.projections.update({
data: {
animation: {
duration: 1
},
position: {y: 70}
},
where: {id: 'ar_button_two'}
});
awe.projections.update({
data: {
animation: {
duration: 1
},
position: {y: 105}
},
where: {id: 'ar_button_three'}
});
awe.projections.update({
data: {
animation: {
duration: 1
},
position: {y: 140}
},
where: {id: 'ar_button_four'}
});
awe.projections.update({
data: {
animation: {
duration: 1
},
position: {y: 175}
},
where: {id: 'ar_button_five'}
});
awe.projections.update({
data: {
animation: {
duration: 1
},
position: {y: 210}
},
where: {id: 'ar_button_six'}
});
awe.projections.update({
data: {
animation: {
duration: 1
},
position: {y: 245}
},
where: {id: 'ar_button_seven'}
});
} else {
alert("zu");
awe.projections.update({
data: {
animation: {
duration: 1
},
position: {y: -31}
},
where: {id: 'ar_button_one'}
});
awe.projections.update({
data: {
animation: {
duration: 1
},
position: {y: -31}
},
where: {id: 'ar_button_two'}
});
awe.projections.update({
data: {
animation: {
duration: 1
},
position: {y: -31}
},
where: {id: 'ar_button_three'}
});
awe.projections.update({
data: {
animation: {
duration: 1
},
position: {y: -31}
},
where: {id: 'ar_button_four'}
});
awe.projections.update({
data: {
animation: {
duration: 1
},
position: {y: -31}
},
where: {id: 'ar_button_five'}
});
awe.projections.update({
data: {
animation: {
duration: 1
},
position: {y: -31}
},
where: {id: 'ar_button_six'}
});
awe.projections.update({
data: {
animation: {
duration: 1
},
position: {y: -31}
},
where: {id: 'ar_button_seven'}
});
} */
menu_open = !menu_open;
//alert("test");
break;
/*
case 'ar_button_one':
case 'ar_button_two':
case 'ar_button_three':
case 'ar_button_four':
case 'ar_button_five':
case 'ar_button_six':
case 'ar_button_seven':
var request = new XMLHttpRequest();
alert("ifttt");
request.open('GET', 'http://maker.ifttt.com/trigger/'+e.detail.projection_id+'/with/key/yourkeyhere', true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
var data = JSON.parse(request.responseText);
console.log(data);
}
};
request.send();
break;
*/
}
}, false);
} // success()
},
{
capabilities: [],
success: function() {
document.body.innerHTML = '<p>Try this demo in the latest version of Chrome or Firefox on a PC or Android device</p>';
}
}
]); // awe.util.require()
} // ready()
}); // window.awe.init()
}); // load |
(function () {
'use strict';
var strip = require('cli-color/strip');
var fs = require('fs');
var prompt = require('prompt-sync');
var child_process = require('child_process');
var defaultOptions = { encoding: 'utf-8' };
exec([
'git checkout master',
'rm -rf /tmp/ngcode',
'git clone https://github.com/angular/code.material.angularjs.org.git --depth=1 /tmp/ngcode'
]);
var docs = require('/tmp/ngcode/docs.json');
docs.versions.forEach(function (version) {
exec([
'rm -rf dist',
'git checkout v' + version,
checkout('app/js/app.js'),
checkout('app/css/style.css'),
checkout('app/img/icons'),
checkout('app/partials'),
checkout('config/template/index.template.html'),
'gulp docs --release',
'cp -r dist/docs/docs.js /tmp/ngcode/' + version,
'cp -r dist/docs/docs.css /tmp/ngcode/' + version,
'cp -r dist/docs/index.html /tmp/ngcode/' + version,
'cp -r dist/docs/img/icons/* /tmp/ngcode/' + version + '/img/icons',
'git checkout master'
]);
function checkout (filename) {
return 'git checkout origin/master -- docs/' + filename;
}
});
exec([
'ls',
'rm -rf latest',
'cp -r {{docs.latest}} latest',
'git add -A',
'git commit -m "updating version picker for old releases"',
'git push'
], { cwd: '/tmp/ngcode' });
//-- utility methods
function fill(str) {
return str.replace(/\{\{[^\}]+\}\}/g, function (match) {
return eval(match.substr(2, match.length - 4));
});
}
function done () {
log('done'.green);
}
function exec (cmd, userOptions) {
if (cmd instanceof Array) {
return cmd.map(function (cmd) { return exec(cmd, userOptions); });
}
try {
var options = Object.create(defaultOptions);
for (var key in userOptions) options[key] = userOptions[key];
log('\n--------\n' + fill(cmd));
return log(child_process.execSync(fill(cmd), options).trim());
} catch (err) {
return err;
}
}
function log (msg) {
console.log(fill(msg));
}
function write (msg) {
process.stdout.write(fill(msg));
}
})();
|
for (let f of Array.from(document.querySelectorAll('.framed'))){
f.style.setProperty('--edgeLength', Math.floor(Math.random() * 100) + '%');
} |
/*
* Copyright (c) 2015 Interactive Intelligence
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
var express = require('express')
var app = express();
var fs = require('fs');
var cors = require('cors');
var path = require('path');
//var email = require('emailjs');
var request = require('request');
var util = require('util');
var os = require('os');
var sip = require('sip');
var http = require('http');
var bodyParser = require('body-parser');
var email = require('emailjs/email');
app.use(express.static('public'));
app.use(cors())
app.set('port', (process.env.PORT || 8080))
app.use(bodyParser.json());
var messageTimer = null
console.log("app starting")
//Generates a random string, used in the options message
function rstring() { return Math.floor(Math.random()*1e6).toString(); }
var config = require('./configuration.json');
var devices = {};
sip.start({}, function(rq) {});
//timeout in the sip library is 120000 and is not configurable, lets set our poll higher than that so we don't have more than 1 ping at a time
pollDevices();
messageTimer = setInterval(pollDevices, 121000);
function pollDevices(){
for(var i=0; i< config.servers.length; i++){
var server = config.servers[i];
sendOptions(server.ip, server.name)
}
}
//sends an outbound email for status changes
function sendEmail(name, data) {
if( config.notifications.email.configuration.host == null || config.notifications.email.configuration.host === ""){
return;
}
var emailConfig = config.notifications.email.configuration;
var server = email.server.connect(emailConfig);
var sendParams = config.notifications.email.message;
sendParams.subject = "SIP Stack for " + name + " is " + data.status;
sendParams.text = "Server: " + name + "\nIP: " + data.ip + "\nStatus: " + data.status
console.log("sending email to " + sendParams.to)
server.send(sendParams, function(err, message) {
if(err){
console.log("ERROR sending email: " + err)
}else{
console.log("email sent")
}
});
}
//makes the outbound POST for a webhook when the status changes.
function sendWebHook(name, data) {
if( config.notifications.webhook.host == null || config.notifications.webhook.host === ""){
return;
}
data.name = name;
// An object of options to indicate where to post to
var post_options = {
host: config.notifications.webhook.host,
port: config.notifications.webhook.port,
path: config.notifications.webhook.path,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': JSON.stringify(data).length
}
};
// Set up the request
var post_req = http.request(post_options, function(res) {
res.setEncoding('utf8');
});
// post the data
console.log("calling webhook");
post_req.write(JSON.stringify(data));
post_req.end();
}
//handles sending an options message to a server
function sendOptions(baseIp, name){
ip = "sip:" + baseIp + ":5060";
sip.send({
method: 'OPTIONS',
uri: ip,
headers: {
to: {uri: ip},
from: {uri: 'sip:test@test', params: {tag: rstring()}},
'call-id': rstring(),
cseq: {method: 'OPTIONS', seq: Math.floor(Math.random() * 1e5)},
'content-type': 'application/sdp',
}
},
function(rs) {
var status = {
ip: baseIp
}
if(rs.status == 200){
status.status = "up"
console.log(name + " UP")
}
else{
status.status = "down"
console.log(name + " DOWN")
}
var oldData = devices[name];
if(oldData != null && oldData.status != status.status){
sendWebHook(name, status);
sendEmail(name, status);
}else if(oldData == null){
sendWebHook(name, status);
sendEmail(name, status);
}
devices[name] = status;
});
}
app.listen(app.get('port'), function() {
console.log("SIP Verification app is running at localhost:" + app.get('port'))
})
app.get('/devices', function(request, response){
response.send(devices);
})
app.get('/', function(request, response){
response.sendFile(path.join(__dirname,"index.html"));
})
app.post('/webhooktest', function(req, res){
console.log('webhook received: ' + JSON.stringify(req.body));
res.send();
})
|
// XXX dups packages/minimongo/uuid.js
// Meteor.random() -- known good PRNG, replaces Math.random()
// Meteor.uuid() -- returns RFC 4122 v4 UUID.
// see http://baagoe.org/en/wiki/Better_random_numbers_for_javascript
// for a full discussion and Alea implementation.
// Copyright (C) 2010 by Johannes Baagøe <baagoe@baagoe.org>
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
Meteor._Alea = function () {
function Mash() {
var n = 0xefc8249d;
var mash = function(data) {
data = data.toString();
for (var i = 0; i < data.length; i++) {
n += data.charCodeAt(i);
var h = 0.02519603282416938 * n;
n = h >>> 0;
h -= n;
h *= n;
n = h >>> 0;
h -= n;
n += h * 0x100000000; // 2^32
}
return (n >>> 0) * 2.3283064365386963e-10; // 2^-32
};
mash.version = 'Mash 0.9';
return mash;
}
return (function (args) {
var s0 = 0;
var s1 = 0;
var s2 = 0;
var c = 1;
if (args.length == 0) {
args = [+new Date];
}
var mash = Mash();
s0 = mash(' ');
s1 = mash(' ');
s2 = mash(' ');
for (var i = 0; i < args.length; i++) {
s0 -= mash(args[i]);
if (s0 < 0) {
s0 += 1;
}
s1 -= mash(args[i]);
if (s1 < 0) {
s1 += 1;
}
s2 -= mash(args[i]);
if (s2 < 0) {
s2 += 1;
}
}
mash = null;
var random = function() {
var t = 2091639 * s0 + c * 2.3283064365386963e-10; // 2^-32
s0 = s1;
s1 = s2;
return s2 = t - (c = t | 0);
};
random.uint32 = function() {
return random() * 0x100000000; // 2^32
};
random.fract53 = function() {
return random() +
(random() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53
};
random.version = 'Alea 0.9';
random.args = args;
return random;
} (Array.prototype.slice.call(arguments)));
};
// instantiate RNG. use the default seed, which is current time.
Meteor.random = new Meteor._Alea();
// RFC 4122 v4 UUID.
Meteor.uuid = function () {
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Meteor.random() * 0x10), 1);
}
s[14] = "4";
s[19] = hexDigits.substr((parseInt(s[19],16) & 0x3) | 0x8, 1);
s[8] = s[13] = s[18] = s[23] = "-";
var uuid = s.join("");
return uuid;
};
|
import React, { Component } from 'react';
import {Button, Glyphicon, Tooltip, OverlayTrigger} from 'react-bootstrap';
import {step} from '../types/step';
export default class ImportButton extends Component {
constructor(props){
super(props);
}
componentDidMount(){
let {addSteps} = this.props;
setTimeout(() => {
addSteps([
{
text: 'The last thing, you can also Import <b style="color: #e5b560">[ Oi ]</b> SLIDE from local, have fun <i class="glyphicon glyphicon-heart"></i>',
selector: '.oi-btn-import',
position: 'bottom',
style: {
backgroundColor: '#3e4852',
borderRadius: 0,
color: 'rgba(255,255,255,.8)',
mainColor: '#a94442',
beacon: {
inner: '#a94442',
outer: '#a94442'
},
skip: {
display: 'none'
},
width: '35rem'
}
}
]);
}, 6100);
}
handleChange(e){
this.importFile(e.target);
}
importFile(target){
let file = target.files[0];
let fReader = new FileReader();
let parser = new DOMParser();
fReader.onload = (e) => {
let doc = parser.parseFromString(e.target.result, 'text/html');
if (doc.getElementById('impress'))
this.parseSteps(doc);
else
{
alert('Please import correct file (should have an impress id in your html).');
target.value = '';
}
};
if (file.type === 'text/html')
fReader.readAsText(file);
else
{
alert('Please import correct file (*.html).');
target.value = '';
}
}
parseSteps(doc){
let steps = [...doc.getElementsByClassName('step')];
let newSlides = new Array();
if ( steps.length > 0 )
{
steps.forEach((s) => {
s = new step({
id: s.id,
slide: s.classList.contains('slide'),
content: s.innerHTML,
data: {
x: s.dataset.x || 0,
y: s.dataset.y || 0,
z: s.dataset.z || 0,
scale: s.dataset.scale || 1,
rotate: s.dataset.rotate || 0,
rotateX: s.dataset.rotateX || 0,
rotateY: s.dataset.rotateY || 0,
rotateZ: s.dataset.rotateZ || 0
},
style: s.style
});
if (s.id === 'overview')
newSlides.splice(0, 0, s);
else
newSlides.push(s);
});
}
this.props.actions.importSlides(newSlides);
}
render() {
const toolTip = ( <Tooltip id={'downloadTooltip'}>Import your [ Oi ]</Tooltip> );
return (
<OverlayTrigger placement="bottom" delayShow={800} overlay={toolTip}>
<div className='btn oi-btn oi-btn-o oi-btn-import oi-btn-import-pos' style={{padding: '16px 0'}}>
<Glyphicon glyph="open" />
<input type='file' id='file' onChange={this.handleChange.bind(this)}/>
</div>
</OverlayTrigger>
);
}
}
|
// -------------------------------------------------------------------------------------------
// Copyright 2014-2015 by ChartIQ LLC
// -------------------------------------------------------------------------------------------
(function(){
function _stxSymLookup_Xignite_js(_exports) {
var STX=_exports.STX;
STX.SymbolLookupModule={
subscribedExchanges:[],
fastLookupMap:[], //use for fast lookup of description by symbol (this is parsed with dashes to fit in the headsup)
fastLookupShareMap:[], //use for fast lookup of description for sharing (this is raw)
source:"Xignite",
currentRequest:0,
maxResults:50, //default search results count
searchExchanges:[],
internalSubscribedExchanges:{
"XNYS":true,
"XASE":true,
"ARCX":true,
"XNAS":true,
"OOTC":true,
"XOTC":true,
"PINX":true,
"metals":true,
"forex":true,
"futures":true,
"mutualfund":true
},
cache:[],
cacheIt:function(body,data){
this.cache.push({body:body,data:data});
while(this.cache.length>100) this.cache.shift();
},
ready:false,
loadSymbolLookupTables:function(useDefaults){
if(this.ready) return;
if(!useDefaults) this.internalSubscribedExchanges={};
for(var i=0;i<this.subscribedExchanges.length;i++){
this.internalSubscribedExchanges[this.subscribedExchanges[i]]=true;
}
this.searchExchanges=[];
for(var j in this.internalSubscribedExchanges){
if(this.internalSubscribedExchanges[j]) this.searchExchanges.push(j);
}
this.ready=true;
},
doSymbolLookup:function(type,keyword,maxResults,cb){
var self=this;
if(!keyword){
if(cb) cb({});
return;
}
if(!maxResults) maxResults=this.maxResults;
var url="http"+(STX.isIE9?"":"s")+"://services.chartiq.com/symbol_lookup_service/";
var body="t="+encodeURIComponent(keyword)+"&m="+parseInt(maxResults,10);
if(type && type!="ALL") body+="&e="+encodeURIComponent(type);
body+="&x="+encodeURIComponent(JSON.stringify(this.searchExchanges));
for(var i=0;i<self.cache.length;i++){
if(self.cache[i].body==body){
cb(self.cache[i].data);
return;
}
}
if(body.length<1800){
url+="?"+body;
}
STX.SymbolLookupModule.currentRequest++;
var thisRequest=STX.SymbolLookupModule.currentRequest;
setTimeout(function(){
if(thisRequest!=STX.SymbolLookupModule.currentRequest) return; // another keystroke happened in the timeout period
STX.postAjax(url, body.length<1800?null:body, function(status, response){
if(thisRequest!=STX.SymbolLookupModule.currentRequest) return; // An older request got ahead of a newer request.
if(status!=200){
if(cb) cb({});
return;
}
//populate the map
var results=response.split("\r\n");
var filteredResults=[];
var names;
for(var r=1;r<results.length;r++){
if(r==1) {
names=results[0].split("|");
headers={};
for(var h=0;h<names.length;h++){
headers[names[h]]=h;
}
}
var fields=results[r].split("|");
if(!self.internalSubscribedExchanges[fields[headers.source]]) continue;
self.fastLookupShareMap[fields[headers.symbol]]=fields[headers.name];
filteredResults.push({
"symbol":fields[headers.symbol],
"name":fields[headers.name],
"exchDisp":fields[headers.exchDisp]
});
}
if(filteredResults.length>10) self.cacheIt(body,filteredResults); // Only cache "heavy" results
if(cb) cb(filteredResults);
});
},100);
}
};
return _exports;
}
{
if ( typeof define === "function" && define.amd ) {
define( ["stx"], function(_stx) { return _stxSymLookup_Xignite_js(_stx); } );
}else{
var _stx={
"STX":window.STX
};
_stxSymLookup_Xignite_js(_stx);
}
}
})();
|
(window.webpackJsonp=window.webpackJsonp||[]).push([[4],{214:function(t,e,n){"use strict";var i=n(73);n.n(i).a},228:function(t,e,n){"use strict";n.r(e);var i={functional:!0,props:{type:{type:String,default:"tip"},text:String,vertical:{type:String,default:"top"}},render:function(t,e){var n=e.props,i=e.slots;return t("span",{class:["badge",n.type],style:{verticalAlign:n.vertical}},n.text||i().default)}},r=(n(214),n(0)),a=Object(r.a)(i,void 0,void 0,!1,null,"c13ee5b0",null);e.default=a.exports},73:function(t,e,n){}}]); |
$(document).ready(function() {
var scrambleDot = function()
{
var dotPosition = 0;
var randomNum = Math.random();
console.log(randomNum);
if (randomNum <= 0.33)
{
console.log("Less than 0.33, greater than 0");
dotPosition = 50;
console.log('left property set to ' + dotPosition + 'px of #under');
}
else if (randomNum <= 0.66)
{
console.log("Less than 0.66, greater than 0.33");
dotPosition = 160;
console.log('left property set to ' + dotPosition + 'px of #under');
}
else if (randomNum <= 1)
{
console.log("Less than 1, greater than 0.33");
dotPosition = 270;
console.log('left property set to ' + dotPosition + 'px of #under');
}
$('#under').css({'left':dotPosition});
};
scrambleDot();
$('#reveal').click(function() {
$('.cover').css({'visibility':'hidden'});
$('#under').css({'visibility':'visible'});
$('#conceal').click(function() {
$('.cover').css({'visibility':'visible'});
$('#under').css({'visibility':'hidden'});
scrambleDot();
})
})
}) |
'use strict';
import * as _ from 'lodash';
import { NumberExt } from './number-ext';
export function Color(r, g, b) {
this._r = r;
this._g = g;
this._b = b;
}
Object.defineProperties(Color.prototype, {
r: {
get: function() {
return this._r;
},
enumerable: true
},
g: {
get: function() {
return this._g;
},
enumerable: true
},
b: {
get: function() {
return this._b;
},
enumerable: true
}
});
Color.createFromRgb = function(r, g, b) {
return new Color(r, g, b);
};
Color.createFromHex = function(hexStr) {
let h = hexStr;
if (hexStr.charAt(0) === '#') {
h = h.substring(1, 7);
}
return new Color(parseInt(h.substring(0, 2), 16), parseInt(h.substring(2, 4), 16), parseInt(h.substring(4, 6), 16));
};
Color.createGradient = function(startColor, endColor, steps) {
return _.range(steps + 1).map(function(val, i) {
return new Color(
NumberExt.toInteger(Color._inter(startColor.r, endColor.r, i, steps)),
NumberExt.toInteger(Color._inter(startColor.g, endColor.g, i, steps)),
NumberExt.toInteger(Color._inter(startColor.b, endColor.b, i, steps))
);
});
};
Color._inter = function(start, end, step, max) {
if (start < end) {
return (end - start) * (step / max) + start;
} else {
return (start - end) * (1 - step / max) + end;
}
};
_.extend(Color.prototype, {
toRgbString: function() {
return 'rgb(' + this.r + ',' + this.g + ',' + this.b + ')';
},
toHexString: function() {
return '#' + ((1 << 24) + (this.r << 16) + (this.g << 8) + this.b).toString(16).slice(1);
}
});
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.