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

agave

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

agave - npm Package Compare versions

Comparing version 2.0.0 to 2.2.0

6

CHANGELOG.md

@@ -0,1 +1,7 @@

## 2.2.0 (2017-04-18)
- es6-shim removed - now expects ES6. Current browsers or node version 6 and up.
- `number..months` and `number..years` added.
- Remove number methods where either Math.method an ES6 operator like `**` exists. Use those instead.
## 2.0.0 (2016-08-03)

@@ -2,0 +8,0 @@

0

CONTRIBUTING.md

@@ -0,0 +0,0 @@ # How to contribute

786

index.js

@@ -1,3 +0,1 @@

require('es6-shim');
var enabledPrefixes = {}; // Only allow agave to be enabled once per prefix

@@ -7,298 +5,287 @@

var enable = function(prefix){
"use strict";
"use strict";
prefix = prefix || '';
prefix = prefix || '';
if ( enabledPrefixes[prefix] ) {
return;
}
if ( enabledPrefixes[prefix] ) {
return;
}
const MILLISECONDS_IN_SECOND = 1000,
SECONDS_IN_MINUTE = 60,
MINUTES_IN_HOUR = 60,
HOURS_IN_DAY = 24,
DAYS_IN_WEEK = 7;
const MILLISECONDS_IN_SECOND = 1000,
SECONDS_IN_MINUTE = 60,
MINUTES_IN_HOUR = 60,
HOURS_IN_DAY = 24,
DAYS_IN_WEEK = 7,
DAYS_IN_MONTH = 30,
DAYS_IN_YEAR = 365;
const SUNDAY = 0,
MONDAY = 1,
TUESDAY = 2,
WEDNESDAY = 3,
THURSDAY = 4,
FRIDAY = 5,
SATURDAY = 6;
const SUNDAY = 0,
MONDAY = 1,
TUESDAY = 2,
WEDNESDAY = 3,
THURSDAY = 4,
FRIDAY = 5,
SATURDAY = 6;
// object.getKeys() returns an array of keys
var getKeys = function(){
return Object.keys(this);
};
// object.getKeys() returns an array of keys
var getKeys = function(){
return Object.keys(this);
};
// object.getSize() returns the number of properties in the object
var getSize = function() {
return Object.keys(this).length;
};
// object.getSize() returns the number of properties in the object
var getSize = function() {
return Object.keys(this).length;
};
// string.reverse()
var reverse = function() {
return this.split("").reverse().join("");
};
// string.reverse()
var reverse = function() {
return this.split("").reverse().join("");
};
// string.leftStrip(stripChars) returns the string with the leading chars removed
var leftStrip = function(stripChars) {
var result = this;
while ( true ) {
// Note result could be zero characters
if ( ! stripChars.includes(result.charAt(0)) || ! result) {
return result;
} else {
result = result.slice(1);
}
}
};
// string.leftStrip(stripChars) returns the string with the leading chars removed
var leftStrip = function(stripChars) {
var result = this;
while ( true ) {
// Note result could be zero characters
if ( ! stripChars.includes(result.charAt(0)) || ! result) {
return result;
} else {
result = result.slice(1);
}
}
};
// string.rightStrip(stripChars) returns the string with the trailing chars removed
var rightStrip = function(stripChars) {
return this[prefix+'reverse']()[prefix+'leftStrip'](stripChars)[prefix+'reverse']();
};
// string.rightStrip(stripChars) returns the string with the trailing chars removed
var rightStrip = function(stripChars) {
return this[prefix+'reverse']()[prefix+'leftStrip'](stripChars)[prefix+'reverse']();
};
// string.strip(stripChars) returns the string with the leading and trailing chars removed
var strip = function(stripChars) {
return this[prefix+'leftStrip'](stripChars)[prefix+'rightStrip'](stripChars);
};
// string.strip(stripChars) returns the string with the leading and trailing chars removed
var strip = function(stripChars) {
return this[prefix+'leftStrip'](stripChars)[prefix+'rightStrip'](stripChars);
};
// object.getPath - get the value of the nested keys provided in the object.
// If any are missing, return undefined. Used for checking JSON results.
var getPath = function(pathItems) {
var currentObject = this;
var delim = '/';
var result;
var stillChecking = true;
// Handle Unix style paths
if ( typeof(pathItems) === 'string' ) {
pathItems = pathItems[prefix+'strip'](delim).split(delim);
}
pathItems.forEach( function(pathItem) {
if ( stillChecking ) {
if ( ( currentObject === null ) || ( ! currentObject.hasOwnProperty(pathItem) ) ) {
result = undefined;
stillChecking = false;
} else {
result = currentObject[pathItem];
currentObject = currentObject[pathItem];
}
}
});
return result;
};
// object.getPath - get the value of the nested keys provided in the object.
// If any are missing, return undefined. Used for checking JSON results.
var getPath = function(pathItems) {
var currentObject = this;
var delim = '/';
var result;
var stillChecking = true;
// Handle Unix style paths
if ( typeof(pathItems) === 'string' ) {
pathItems = pathItems[prefix+'strip'](delim).split(delim);
}
pathItems.forEach( function(pathItem) {
if ( stillChecking ) {
if ( ( currentObject === null ) || ( ! currentObject.hasOwnProperty(pathItem) ) ) {
result = undefined;
stillChecking = false;
} else {
result = currentObject[pathItem];
currentObject = currentObject[pathItem];
}
}
});
return result;
};
// object.extent(object) adds the keys/values from the newObject provided
var objectExtend = function(newObject) {
for ( var key in newObject ) {
this[key] = newObject[key];
}
return this;
};
// object.extent(object) adds the keys/values from the newObject provided
var objectExtend = function(newObject) {
for ( var key in newObject ) {
this[key] = newObject[key];
}
return this;
};
// array.findItem(testFunction) returns the first item that matches the testFunction
var findItem = function(testFunction){
var lastIndex;
var found = this.some(function(item, index) {
lastIndex = index;
return testFunction(item);
});
if ( found ) {
return this[lastIndex];
} else {
return null;
}
};
// array.findItem(testFunction) returns the first item that matches the testFunction
var findItem = function(testFunction){
var lastIndex;
var found = this.some(function(item, index) {
lastIndex = index;
return testFunction(item);
});
if ( found ) {
return this[lastIndex];
} else {
return null;
}
};
// Run after it hasn't been invoked for 'wait' ms.
// Useful to stop repeated calls to a function overlapping each other (sometimes called 'bouncing')
var throttle = function(wait, immediate) {
var timeoutID;
var originalFunction = this;
return function() {
var context = this;
var delayedFunction = function() {
timeoutID = null;
if ( ! immediate ) {
originalFunction.apply(context, arguments);
}
};
var callNow = immediate && ! timeoutID;
clearTimeout(timeoutID);
timeoutID = setTimeout(delayedFunction, wait);
if (callNow) {
originalFunction.apply(context, arguments);
}
};
};
// Run after it hasn't been invoked for 'wait' ms.
// Useful to stop repeated calls to a function overlapping each other (sometimes called 'bouncing')
var throttle = function(wait, immediate) {
var timeoutID;
var originalFunction = this;
return function() {
var context = this;
var delayedFunction = function() {
timeoutID = null;
if ( ! immediate ) {
originalFunction.apply(context, arguments);
}
};
var callNow = immediate && ! timeoutID;
clearTimeout(timeoutID);
timeoutID = setTimeout(delayedFunction, wait);
if (callNow) {
originalFunction.apply(context, arguments);
}
};
};
// Run repeatedly
var functionRepeat = function(first, second, third){
var args, interval, leadingEdge;
if ( arguments.length === 2 ) {
args = [];
interval = first;
leadingEdge = second;
} else {
args = first;
interval = second;
leadingEdge = third;
}
if ( leadingEdge ) {
this.apply(null, args);
}
return setInterval(function(){
this.apply(null, args);
}.bind(this), interval);
};
// Run repeatedly
var functionRepeat = function(first, second, third){
var args, interval, leadingEdge;
if ( arguments.length === 2 ) {
args = [];
interval = first;
leadingEdge = second;
} else {
args = first;
interval = second;
leadingEdge = third;
}
if ( leadingEdge ) {
this.apply(null, args);
}
return setInterval(function(){
this.apply(null, args);
}.bind(this), interval);
};
// Extend an array with another array.
// Cleverness alert: since .apply() accepts an array of args, we use the newArray as all the args to push()
var arrayExtend = function(newArray) {
Array.prototype.push.apply(this, newArray);
return this;
};
// Extend an array with another array.
// Cleverness alert: since .apply() accepts an array of args, we use the newArray as all the args to push()
var arrayExtend = function(newArray) {
Array.prototype.push.apply(this, newArray);
return this;
};
// string.toHash() return a hashed value of a string
// From http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery
var toHash = function(){
var hash = 0,
length = this.length,
char;
if ( ! length ) {
return hash;
}
for (var index = 0; index < length; index++) {
char = this.charCodeAt(index);
hash = ((hash<<5)-hash)+char;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
// string.toHash() return a hashed value of a string
// From http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery
var toHash = function(){
var hash = 0,
length = this.length,
char;
if ( ! length ) {
return hash;
}
for (var index = 0; index < length; index++) {
char = this.charCodeAt(index);
hash = ((hash<<5)-hash)+char;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
// Clone an object recursively
var clone = function() {
var newObj = (this instanceof Array) ? [] : {};
for (var key in this) {
if (this[key] && typeof this[key] == "object") {
newObj[key] = this[key][prefix+'clone']();
} else {
newObj[key] = this[key];
}
}
return newObj;
};
// Clone an object recursively
var clone = function() {
var newObj = (this instanceof Array) ? [] : {};
for (var key in this) {
if (this[key] && typeof this[key] == "object") {
newObj[key] = this[key][prefix+'clone']();
} else {
newObj[key] = this[key];
}
}
return newObj;
};
// compare an object with another object
var compare = function(otherObject){
var hashObject = function(object){
return JSON.stringify(object)[prefix+'toHash']();
};
return ( hashObject(this) === hashObject(otherObject) );
};
// compare an object with another object
var compare = function(otherObject){
var hashObject = function(object){
return JSON.stringify(object)[prefix+'toHash']();
};
return ( hashObject(this) === hashObject(otherObject) );
};
// Iterate over an objects keys
// Unlike a regular for ( var key in object )
// an additional scope is created, which avoids last-item looping probs
var objectForEach = function(callback){
for ( var key in this ) {
callback(key, this[key]);
}
};
// Iterate over an objects keys
// Unlike a regular for ( var key in object )
// an additional scope is created, which avoids last-item looping probs
var objectForEach = function(callback){
for ( var key in this ) {
callback(key, this[key]);
}
};
var arrayClone = function(){
return this.slice();
};
var arrayClone = function(){
return this.slice();
};
// Array remove removes an item from an array, if it exists
var arrayRemove = function(member){
var index = this.indexOf(member);
if (index !== -1 ) {
this.splice(index, 1);
return true;
}
return false;
};
// Array remove removes an item from an array, if it exists
var arrayRemove = function(member){
var index = this.indexOf(member);
if (index !== -1 ) {
this.splice(index, 1);
return true;
}
return false;
};
var arrayFirst= function(count){
if ( ! count ) {
return this[0];
} else {
return this.slice(Math.max(arr.length - count, 1));
}
};
var arrayFirst= function(count){
if ( ! count ) {
return this[0];
} else {
return this.slice(Math.max(arr.length - count, 1));
}
};
var arrayLast = function(count){
if ( ! count ) {
return this[this.length - 1];
} else {
return this.slice(Math.max(this.length - count, 1));
}
};
var arrayLast = function(count){
if ( ! count ) {
return this[this.length - 1];
} else {
return this.slice(Math.max(this.length - count, 1));
}
};
// Helper function for before() and after()
var getTimeOrNow = function(date) {
return (date || new Date()).getTime();
};
// Helper function for before() and after()
var getTimeOrNow = function(date) {
return (date || new Date()).getTime();
};
// Return Number of seconds to time delta from date (or now if not specified)
var before = function(date) {
var time = getTimeOrNow(date);
return new Date(time-(+this));
};
// Return Number of seconds to time delta from date (or now if not specified)
var before = function(date) {
var time = getTimeOrNow(date);
return new Date(time-(+this));
};
// Return Number of seconds to time delta after date (or now if not specified)
var after = function(date) {
var time = getTimeOrNow(date);
return new Date(time+(+this));
};
// Return Number of seconds to time delta after date (or now if not specified)
var after = function(date) {
var time = getTimeOrNow(date);
return new Date(time+(+this));
};
// Round Number
var round = function () {
return Math.round(this);
};
var toSeconds = function() {
return this * MILLISECONDS_IN_SECOND;
}
var ceil = function () {
return Math.ceil(this);
};
var toMinutes = function() {
return this.seconds * SECONDS_IN_MINUTE;
}
var floor = function () {
return Math.floor(this);
};
var toHours = function() {
return this.minutes * MINUTES_IN_HOUR;
}
var abs = function () {
return Math.abs(this);
};
var toDays = function() {
return this.hours * HOURS_IN_DAY;
}
var pow = function (exp) {
return Math.pow(this, exp);
};
var toWeeks = function() {
return this.days * DAYS_IN_WEEK;
}
var toSeconds = function() {
return this * MILLISECONDS_IN_SECOND;
}
var toMonths = function() {
return this.days * DAYS_IN_MONTH;
}
var toMinutes = function() {
return this.seconds * SECONDS_IN_MINUTE;
}
var toYears = function() {
return this.days * DAYS_IN_YEAR;
}
var toHours = function() {
return this.minutes * MINUTES_IN_HOUR;
}
var toDays = function() {
return this.hours * HOURS_IN_DAY;
}
var toWeeks = function() {
return this.days * DAYS_IN_WEEK;
}
var isOnWeekend = function(){
var isOnWeekend = function(){
return this.getDay() === SUNDAY || this.getDay() === SATURDAY
}
var withoutTime = function(){
var withoutTime = function(){
var copy = new Date(this)

@@ -309,157 +296,156 @@ copy.setHours(0, 0, 0, 0, 0)

var dateClone = function(){
var dateClone = function(){
return new Date(this.getTime())
}
var kind = function(item) {
var getPrototype = function(item) {
return Object.prototype.toString.call(item).slice(8, -1);
};
var kind, Undefined;
if (item === null ) {
kind = 'null';
} else {
if ( item === Undefined ) {
kind = 'undefined';
} else {
var prototype = getPrototype(item);
if ( ( prototype === 'Number' ) && isNaN(item) ) {
kind = 'NaN';
} else {
kind = prototype;
}
}
}
return kind;
};
var kind = function(item) {
var getPrototype = function(item) {
return Object.prototype.toString.call(item).slice(8, -1);
};
var kind, Undefined;
if (item === null ) {
kind = 'null';
} else {
if ( item === Undefined ) {
kind = 'undefined';
} else {
var prototype = getPrototype(item);
if ( ( prototype === 'Number' ) && isNaN(item) ) {
kind = 'NaN';
} else {
kind = prototype;
}
}
}
return kind;
};
// Polyfill if Element.prototype.matches doesn't exist.
var prefixedMatchesMethod = ( ! global.Element || Element.prototype.msMatchesSelector || Element.prototype.mozMatchesSelector || Element.prototype.webkitMatchesSelector || Element.prototype.oMatchesSelector);
// Polyfill if Element.prototype.matches doesn't exist.
var prefixedMatchesMethod = ( ! global.Element || Element.prototype.msMatchesSelector || Element.prototype.mozMatchesSelector || Element.prototype.webkitMatchesSelector || Element.prototype.oMatchesSelector);
// Add method as a non-enumerable property on obj with the name methodName
var addMethod = function( global, objectName, prefix, methodName, method) {
var objectToExtend = global[objectName];
methodName = prefix ? prefix+methodName: methodName;
// Check - NodeLists and Elements don't always exist on all JS implementations
if ( objectToExtend ) {
// Don't add if the method already exists
if ( ! objectToExtend.prototype.hasOwnProperty(methodName) ) {
Object.defineProperty( objectToExtend.prototype, methodName, {
value: method,
writable: true
});
}
}
};
// Add method as a non-enumerable property on obj with the name methodName
var addMethod = function( global, objectName, prefix, methodName, method) {
var objectToExtend = global[objectName];
methodName = prefix ? prefix+methodName: methodName;
// Check - NodeLists and Elements don't always exist on all JS implementations
if ( objectToExtend ) {
// Don't add if the method already exists
if ( ! objectToExtend.prototype.hasOwnProperty(methodName) ) {
Object.defineProperty( objectToExtend.prototype, methodName, {
value: method,
writable: true
});
}
}
};
// There's not always a 1:1 match of functions to method names. Eg, some objects share methods,
// others re-use inbuilt methods from other objects.
var newMethods = {
'Array':{
'findItem':findItem,
'extend':arrayExtend,
'includes': String.prototype.includes,
'clone':arrayClone,
'remove':arrayRemove,
'first':arrayFirst,
'last':arrayLast
},
'Object':{
'getKeys':getKeys,
'getSize':getSize,
'getPath':getPath,
'clone':clone,
'forEach':objectForEach,
'extend':objectExtend,
'compare':compare
},
'String':{
'reverse':reverse,
'leftStrip':leftStrip,
'rightStrip':rightStrip,
'strip':strip,
'toHash':toHash,
'forEach':Array.prototype.forEach // Strings and NodeLists don't have .forEach() standard but the one from Array works fine
},
'Function':{
'throttle':throttle,
'repeat':functionRepeat
},
'Number':{
'before':before,
'after':after,
'round':round,
'ceil':ceil,
'floor':floor,
'abs':abs,
'pow':pow
},
'Date':{
'isOnWeekend': isOnWeekend,
'withoutTime': withoutTime,
'clone': dateClone
}
};
// There's not always a 1:1 match of functions to method names. Eg, some objects share methods,
// others re-use inbuilt methods from other objects.
var newMethods = {
'Array':{
'findItem':findItem,
'extend':arrayExtend,
'includes': String.prototype.includes,
'clone':arrayClone,
'remove':arrayRemove,
'first':arrayFirst,
'last':arrayLast
},
'Object':{
'getKeys':getKeys,
'getSize':getSize,
'getPath':getPath,
'clone':clone,
'forEach':objectForEach,
'extend':objectExtend,
'compare':compare
},
'String':{
'reverse':reverse,
'leftStrip':leftStrip,
'rightStrip':rightStrip,
'strip':strip,
'toHash':toHash,
'forEach':Array.prototype.forEach // Strings and NodeLists don't have .forEach() standard but the one from Array works fine
},
'Function':{
'throttle':throttle,
'repeat':functionRepeat
},
'Number':{
'before':before,
'after':after
},
'Date':{
'isOnWeekend': isOnWeekend,
'withoutTime': withoutTime,
'clone': dateClone
}
};
for ( var objectName in newMethods ) {
for ( var methodName in newMethods[objectName] ) {
addMethod(global, objectName, prefix, methodName, newMethods[objectName][methodName]);
}
}
for ( var objectName in newMethods ) {
for ( var methodName in newMethods[objectName] ) {
addMethod(global, objectName, prefix, methodName, newMethods[objectName][methodName]);
}
}
// Add sttribute as a non-enumerable property on obj with the name methodName
var addNewAttribute = function( global, objectName, prefix, methodName, method) {
var objectToExtend = global[objectName];
methodName = prefix ? prefix+methodName: methodName;
// Check - NodeLists and Elements don't always exist on all JS implementations
if ( objectToExtend ) {
// Don't add if the method already exists
if ( ! objectToExtend.prototype.hasOwnProperty(methodName) ) {
Object.defineProperty( objectToExtend.prototype, methodName, {
get: method
});
}
}
};
// Add sttribute as a non-enumerable property on obj with the name methodName
var addNewAttribute = function( global, objectName, prefix, methodName, method) {
var objectToExtend = global[objectName];
methodName = prefix ? prefix+methodName: methodName;
// Check - NodeLists and Elements don't always exist on all JS implementations
if ( objectToExtend ) {
// Don't add if the method already exists
if ( ! objectToExtend.prototype.hasOwnProperty(methodName) ) {
Object.defineProperty( objectToExtend.prototype, methodName, {
get: method
});
}
}
};
var addTimeExtension = function(name, getterFunction){
Object.defineProperty(Number.prototype, name, {
get: getterFunction
})
}
var addTimeExtension = function(name, getterFunction){
Object.defineProperty(Number.prototype, name, {
get: getterFunction
})
}
var newAttributes = {
'Number':{
'second':toSeconds,
'seconds':toSeconds,
'minute':toMinutes,
'minutes':toMinutes,
'hour':toHours,
'hours':toHours,
'day':toDays,
'days':toDays,
'week':toWeeks,
'weeks':toWeeks,
}
}
var newAttributes = {
'Number':{
'second':toSeconds,
'seconds':toSeconds,
'minute':toMinutes,
'minutes':toMinutes,
'hour':toHours,
'hours':toHours,
'day':toDays,
'days':toDays,
'week':toWeeks,
'weeks':toWeeks,
'month':toMonths,
'months':toMonths,
'year':toYears,
'years':toYears
}
}
for ( var objectToGetNewAttribute in newAttributes ) {
for ( var attributeName in newAttributes[objectToGetNewAttribute] ) {
addNewAttribute(global, objectToGetNewAttribute, prefix, attributeName, newAttributes[objectToGetNewAttribute][attributeName]);
}
}
for ( var objectToGetNewAttribute in newAttributes ) {
for ( var attributeName in newAttributes[objectToGetNewAttribute] ) {
addNewAttribute(global, objectToGetNewAttribute, prefix, attributeName, newAttributes[objectToGetNewAttribute][attributeName]);
}
}
// Add a function to the global
var addGlobal = function( global, globalName, prefix, globalFunction) {
globalName = prefix ? prefix+globalName: globalName;
// Don't add if the global already exists
if ( ! global.hasOwnProperty(globalName) ) {
global[globalName] = globalFunction;
}
};
addGlobal(global, 'kind', prefix, kind);
// Add a function to the global
var addGlobal = function( global, globalName, prefix, globalFunction) {
globalName = prefix ? prefix+globalName: globalName;
// Don't add if the global already exists
if ( ! global.hasOwnProperty(globalName) ) {
global[globalName] = globalFunction;
}
};
addGlobal(global, 'kind', prefix, kind);
enabledPrefixes[prefix] = true;
enabledPrefixes[prefix] = true;
}.bind();
module.exports = enable;

@@ -0,0 +0,0 @@ # The MIT License

{
"name": "agave",
"version": "2.0.0",
"version": "2.2.0",
"author": "Mike MacCana <mike.maccana@gmail.com>",
"description": "Cleaner, simpler JavaScript for ES6",
"description": "Cleaner, simpler JavaScript for ES6 and ES7",
"scripts": {

@@ -22,4 +22,2 @@ "test": "mocha"

"dependencies": {
"es6-shim": "^0.34.2",
"mocha": "^3.0.0"
},

@@ -34,12 +32,14 @@ "devDependencies": {

"browserify": {
"transform": [
"brfs",
[
"babelify",
{
"presets": ["es2015"]
}
]
]
"transform": [
"brfs",
[
"babelify",
{
"presets": [
"es2015"
]
}
]
]
}
}

@@ -0,0 +0,0 @@ [![Build Status](https://secure.travis-ci.org/mikemaccana/agave.png?branch=master)](https://travis-ci.org/mikemaccana/agave)

@@ -17,14 +17,14 @@ // Tests. Mocha/assert style. See

var mockObject = {
foo: 'bar',
baz: {
bam:'boo',
zar:{
zog:'victory'
}
},
null:{
'yarr':{
'parrot':'ahoy'
}
}
foo: 'bar',
baz: {
bam:'boo',
zar:{
zog:'victory'
}
},
null:{
'yarr':{
'parrot':'ahoy'
}
}
};

@@ -35,214 +35,214 @@

suite('Array.includes', function(){
test('fetches the item accurately', function(){
assert(['one','two','three'].avincludes('two') );
});
test('handles missing items accurately', function(){
assert( ! ['one','two','three'].avincludes('notthere') );
});
test('fetches the item accurately', function(){
assert(['one','two','three'].avincludes('two') );
});
test('handles missing items accurately', function(){
assert( ! ['one','two','three'].avincludes('notthere') );
});
});
suite('Array.extend', function(){
test('extends the array accurately', function(){
assert.deepEqual([1,2,3].avextend([4,5]), [1,2,3,4,5] );
});
test('extends the array accurately', function(){
assert.deepEqual([1,2,3].avextend([4,5]), [1,2,3,4,5] );
});
});
suite('String.reverse', function(){
test('reverses strings accurately', function(){
assert.equal('Hello world'.avreverse(), 'dlrow olleH');
});
test('reverses strings accurately', function(){
assert.equal('Hello world'.avreverse(), 'dlrow olleH');
});
});
suite('String.leftStrip', function(){
test('strips from the left accurately', function(){
assert.equal('Hello world'.avleftStrip('Hle'), 'o world');
});
test('strips from the left accurately', function(){
assert.equal('Hello world'.avleftStrip('Hle'), 'o world');
});
});
suite('String.rightStrip', function(){
test('strips from the right accurately', function(){
assert.equal('Hello world'.avrightStrip('ldr'), 'Hello wo');
});
test('strips from the right accurately', function(){
assert.equal('Hello world'.avrightStrip('ldr'), 'Hello wo');
});
});
suite('String.rightStrip', function(){
test('strips from the left accurately with a single character', function(){
assert.equal('a'.avleftStrip('a'), '');
});
test('strips from the left accurately with a single character', function(){
assert.equal('a'.avleftStrip('a'), '');
});
});
suite('String.strip', function(){
test('strips from the both sides accurately', function(){
assert.equal('Hello world'.avstrip('Hld'), 'ello wor');
});
test('strips from the both sides accurately', function(){
assert.equal('Hello world'.avstrip('Hld'), 'ello wor');
});
});
suite('Object.getKeys', function(){
test('fetches keys accurately', function(){
assert.deepEqual(mockObject.avgetKeys(), ["foo","baz","null"] );
});
test('fetches keys accurately', function(){
assert.deepEqual(mockObject.avgetKeys(), ["foo","baz","null"] );
});
});
suite('Object.getSize', function(){
test('counts keys accurately', function(){
assert.equal(mockObject.avgetSize(), 3);
});
test('counts keys accurately', function(){
assert.equal(mockObject.avgetSize(), 3);
});
});
suite('Array.findItem', function(){
test('correctly finds items that match the function', function(){
assert.equal(['one','two','three'].avfindItem(function(item){
return (item === 'three');
}), 'three');
});
test('correctly finds items that match the function', function(){
assert.equal(['one','two','three'].avfindItem(function(item){
return (item === 'three');
}), 'three');
});
});
suite('Array.remove', function () {
test('correctly removes the given member', function (){
var arr = [1,2,3,4,5];
arr.avremove(3);
assert.deepEqual(arr, [1,2,4,5]);
});
if('returns true if the given member was in the array', function () {
assert.equal([1,2,3,4,5].remove(3), true);
});
if('returns false if the given member was not in the array', function () {
assert.equal([1,2,3,4,5].remove(6), false);
});
test('correctly removes the given member', function (){
var arr = [1,2,3,4,5];
arr.avremove(3);
assert.deepEqual(arr, [1,2,4,5]);
});
if('returns true if the given member was in the array', function () {
assert.equal([1,2,3,4,5].remove(3), true);
});
if('returns false if the given member was not in the array', function () {
assert.equal([1,2,3,4,5].remove(6), false);
});
});
suite('Object.getPath', function(){
test('returns undefined when a value is missing', function(){
assert.equal(mockObject.avgetPath(['foo','pineapple']), undefined);
});
test('returns the value when the provided keys exist', function(){
assert.equal(mockObject.avgetPath(['baz','zar','zog']), 'victory');
});
test('returns the value when the provided keys exist, even if null is on the path', function(){
assert.equal(mockObject.avgetPath([null,'yarr','parrot']), 'ahoy');
});
test('works using Unix-style paths', function(){
assert.equal(mockObject.avgetPath('/baz/zar/zog'), 'victory');
});
test('returns undefined when a value is missing', function(){
assert.equal(mockObject.avgetPath(['foo','pineapple']), undefined);
});
test('returns the value when the provided keys exist', function(){
assert.equal(mockObject.avgetPath(['baz','zar','zog']), 'victory');
});
test('returns the value when the provided keys exist, even if null is on the path', function(){
assert.equal(mockObject.avgetPath([null,'yarr','parrot']), 'ahoy');
});
test('works using Unix-style paths', function(){
assert.equal(mockObject.avgetPath('/baz/zar/zog'), 'victory');
});
});
suite('Object.clone', function(){
var copyObject = mockObject.avclone();
test('clones objects so that modification to the new object will not affect the original', function(){
copyObject.baz.bam = 'newvalue';
assert.equal(copyObject.avgetPath(['baz','bam']), 'newvalue');
assert.equal(mockObject.avgetPath(['baz','bam']), 'boo');
});
var copyObject = mockObject.avclone();
test('clones objects so that modification to the new object will not affect the original', function(){
copyObject.baz.bam = 'newvalue';
assert.equal(copyObject.avgetPath(['baz','bam']), 'newvalue');
assert.equal(mockObject.avgetPath(['baz','bam']), 'boo');
});
});
suite('Object.forEach', function(){
var keyResults = [];
var valueResults = [];
mockObject.avforEach(function(key, value){
keyResults.push(key);
valueResults.push(value);
});
test('iterates over keys properly', function(){
assert.deepEqual(keyResults, ["foo","baz","null"]);
});
test('iterates over values properly', function(){
assert.deepEqual(valueResults, [
"bar",
{"bam":"boo",
"zar":{
"zog":"victory"
}
},
{"yarr":
{"parrot":"ahoy"}
}
]);
});
var keyResults = [];
var valueResults = [];
mockObject.avforEach(function(key, value){
keyResults.push(key);
valueResults.push(value);
});
test('iterates over keys properly', function(){
assert.deepEqual(keyResults, ["foo","baz","null"]);
});
test('iterates over values properly', function(){
assert.deepEqual(valueResults, [
"bar",
{"bam":"boo",
"zar":{
"zog":"victory"
}
},
{"yarr":
{"parrot":"ahoy"}
}
]);
});
});
suite('Object.extend', function(){
var results = mockObject.avclone().avextend({
'gnar':{
shub:'zoo'
},
'gert':{
yaz:'frub'
}
});
var results = mockObject.avclone().avextend({
'gnar':{
shub:'zoo'
},
'gert':{
yaz:'frub'
}
});
test('creates extends the object with the new properties', function(){
assert.deepEqual(results, {
"foo":"bar",
"baz":{
"bam":"boo",
"zar":{
"zog":"victory"}
},
"null":{
"yarr":{
"parrot":"ahoy"
}
},
"gnar":{
"shub":"zoo"
},
"gert":{
"yaz":"frub"
}
});
});
test('creates extends the object with the new properties', function(){
assert.deepEqual(results, {
"foo":"bar",
"baz":{
"bam":"boo",
"zar":{
"zog":"victory"}
},
"null":{
"yarr":{
"parrot":"ahoy"
}
},
"gnar":{
"shub":"zoo"
},
"gert":{
"yaz":"frub"
}
});
});
});
suite('Object.compare', function(){
test('accurately identifies similar objects', function(){
var identicalObject = {
foo: 'bar',
baz: {
bam:'boo',
zar:{
zog:'victory'
}
},
null:{
'yarr':{
'parrot':'ahoy'
}
}
};
assert(mockObject.avcompare(identicalObject));
});
test('accurately identifies different objects', function(){
var differentObject = {
foo: 'bar',
baz: {
bam:'boo',
zar:{
zog:'victory'
}
}
};
assert.equal(mockObject.avcompare(differentObject), false);
});
test('accurately identifies similar objects', function(){
var identicalObject = {
foo: 'bar',
baz: {
bam:'boo',
zar:{
zog:'victory'
}
},
null:{
'yarr':{
'parrot':'ahoy'
}
}
};
assert(mockObject.avcompare(identicalObject));
});
test('accurately identifies different objects', function(){
var differentObject = {
foo: 'bar',
baz: {
bam:'boo',
zar:{
zog:'victory'
}
}
};
assert.equal(mockObject.avcompare(differentObject), false);
});
});
suite('Function.throttle', function(){
var valueShouldOnlyBeOne = 0; // Since the function should only run once
var timesFunctionHasRan = 0;
var maxTimesToRun = 3;
test('stops function calls overlapping', function(done){
var intervalID = setInterval(function(){
// thottledFunction would normally run three times in this loop, 50ms apart, but .avthrottle() means it
// will only be run once after 70ms of inactivity
var thottledFunction = function(){
valueShouldOnlyBeOne++;
}.avthrottle(70);
thottledFunction();
timesFunctionHasRan++;
if ( timesFunctionHasRan === maxTimesToRun ) {
clearInterval(intervalID);
assert.equal(valueShouldOnlyBeOne, 1);
done();
}
}, 50);
});
var valueShouldOnlyBeOne = 0; // Since the function should only run once
var timesFunctionHasRan = 0;
var maxTimesToRun = 3;
test('stops function calls overlapping', function(done){
var intervalID = setInterval(function(){
// thottledFunction would normally run three times in this loop, 50ms apart, but .avthrottle() means it
// will only be run once after 70ms of inactivity
var thottledFunction = function(){
valueShouldOnlyBeOne++;
}.avthrottle(70);
thottledFunction();
timesFunctionHasRan++;
if ( timesFunctionHasRan === maxTimesToRun ) {
clearInterval(intervalID);
assert.equal(valueShouldOnlyBeOne, 1);
done();
}
}, 50);
});
});

@@ -252,23 +252,23 @@

test('repeats', function(done){
var count = 0
var increment = function(){
count += 1
if ( count === 3 ) {
done();
}
}
increment.repeat([], 50, true)
});
test('repeats with arguments omitted', function(done){
var count = 0
this.timeout(11 * 1000);
var increment = function(){
count += 1
if ( count === 3 ) {
done();
}
}
increment.repeat(50, true)
});
test('repeats', function(done){
var count = 0
var increment = function(){
count += 1
if ( count === 3 ) {
done();
}
}
increment.repeat([], 50, true)
});
test('repeats with arguments omitted', function(done){
var count = 0
this.timeout(11 * 1000);
var increment = function(){
count += 1
if ( count === 3 ) {
done();
}
}
increment.repeat(50, true)
});
});

@@ -279,20 +279,20 @@

suite('Number.days', function(){
test('correctly converts a number to days in seconds', function(){
assert.equal((5).avdays, 432000000);
});
test('correctly converts a number to days in seconds', function(){
assert.equal((5).avdays, 432000000);
});
});
suite('Number.weeks.before and .after', function(){
test('correctly converts a number to a period in weeks before a set date', function(){
var someDate = new Date('Thu Jun 06 2013 22:44:05 GMT+0100 (UTC)');
var timezoneOffset = someDate.getTimezoneOffset();
var targetDate = new Date('Thu May 16 2013 22:44:05 GMT+0100 (UTC)')
assert.equal((3).avweeks.avbefore(someDate).getDate(), targetDate.getDate());
});
test('correctly converts a number to a period in weeks after a set date', function(){
var someDate = new Date('Thu Jun 27 2013 22:44:05 GMT+0100 (UTC)');
var timezoneOffset = someDate.getTimezoneOffset();
var targetDate = new Date('Thu Jun 06 2013 22:44:05 GMT+0100 (UTC)');
assert.equal((3).avweeks.avbefore(someDate).getDate(), targetDate.getDate());
});
test('correctly converts a number to a period in weeks before a set date', function(){
var someDate = new Date('Thu Jun 06 2013 22:44:05 GMT+0100 (UTC)');
var timezoneOffset = someDate.getTimezoneOffset();
var targetDate = new Date('Thu May 16 2013 22:44:05 GMT+0100 (UTC)')
assert.equal((3).avweeks.avbefore(someDate).getDate(), targetDate.getDate());
});
test('correctly converts a number to a period in weeks after a set date', function(){
var someDate = new Date('Thu Jun 27 2013 22:44:05 GMT+0100 (UTC)');
var timezoneOffset = someDate.getTimezoneOffset();
var targetDate = new Date('Thu Jun 06 2013 22:44:05 GMT+0100 (UTC)');
assert.equal((3).avweeks.avbefore(someDate).getDate(), targetDate.getDate());
});
});

@@ -324,97 +324,62 @@

suite('Number.round', function () {
var num = 4.2;
test('correctly rounds a number', function () {
assert.equal(num.avround(),4);
});
});
suite('Number.ceil', function () {
var num = 4.2;
test('correctly finds a number\'s ceiling', function () {
assert.equal(num.avceil(),5);
});
});
suite('Number.floor', function () {
var num = 4.2;
test('correctly finds a number\'s floor', function () {
assert.equal(num.avfloor(),4);
});
});
suite('Number.abs', function () {
var num = -4.2;
test('correctly finds the absolute value of a number', function () {
assert.equal(num.avabs(),4.2);
});
});
suite('Number.pow', function () {
var num = 5;
test('correctly raises a number to the given power', function () {
assert.equal(num.avpow(3), 125);
});
});
suite('Agave doesn\'t affect for loops', function(){
it ('doesn\'t. really', function(){
for ( var key in mockObject ) {
assert( ! ['avgetKeys','avgetSize','avgetPath'].avincludes(key) );
}
});
it ('doesn\'t. really', function(){
for ( var key in mockObject ) {
assert( ! ['avgetKeys','avgetSize','avgetPath'].avincludes(key) );
}
});
});
suite('kind', function(){
test('shows number-like things as numbers', function(){
assert(avkind(37) === 'Number');
assert(avkind(3.14) === 'Number');
assert(avkind(Math.LN2) === 'Number');
assert(avkind(Infinity) === 'Number');
assert(avkind(Number(1)) === 'Number');
assert(avkind(new Number(1)) === 'Number');
});
test('shows NaN as NaN', function(){
assert(avkind(NaN) === 'NaN');
});
test('Shows strings as strings', function(){
assert(avkind('') === 'String');
assert(avkind('bla') === 'String');
assert(avkind(String("abc")) === 'String');
assert(avkind(new String("abc")) === 'String');
});
test('shows strings accurately', function(){
assert(avkind(true) === 'Boolean');
assert(avkind(false) === 'Boolean');
assert(avkind(new Boolean(true)) === 'Boolean');
});
test('shows arrays accurately', function(){
assert(avkind([1, 2, 4]) === 'Array');
assert(avkind(new Array(1, 2, 3)) === 'Array');
});
test('shows objects accurately', function(){
assert(avkind({a:1}) === 'Object');
assert(avkind(new Object()) === 'Object');
});
test('shows dates accurately', function(){
assert(avkind(new Date()) === 'Date');
});
test('loves Functions too', function(){
assert(avkind(function(){}) === 'Function');
assert(avkind(new Function("console.log(arguments)")) === 'Function');
assert(avkind(Math.sin) === 'Function');
});
test('shows undefined accurately', function(){
assert(avkind(undefined) === 'undefined');
});
test('shows null accurately', function(){
assert(avkind(null) === 'null');
});
test('shows number-like things as numbers', function(){
assert(avkind(37) === 'Number');
assert(avkind(3.14) === 'Number');
assert(avkind(Math.LN2) === 'Number');
assert(avkind(Infinity) === 'Number');
assert(avkind(Number(1)) === 'Number');
assert(avkind(new Number(1)) === 'Number');
});
test('shows NaN as NaN', function(){
assert(avkind(NaN) === 'NaN');
});
test('Shows strings as strings', function(){
assert(avkind('') === 'String');
assert(avkind('bla') === 'String');
assert(avkind(String("abc")) === 'String');
assert(avkind(new String("abc")) === 'String');
});
test('shows strings accurately', function(){
assert(avkind(true) === 'Boolean');
assert(avkind(false) === 'Boolean');
assert(avkind(new Boolean(true)) === 'Boolean');
});
test('shows arrays accurately', function(){
assert(avkind([1, 2, 4]) === 'Array');
assert(avkind(new Array(1, 2, 3)) === 'Array');
});
test('shows objects accurately', function(){
assert(avkind({a:1}) === 'Object');
assert(avkind(new Object()) === 'Object');
});
test('shows dates accurately', function(){
assert(avkind(new Date()) === 'Date');
});
test('loves Functions too', function(){
assert(avkind(function(){}) === 'Function');
assert(avkind(new Function("console.log(arguments)")) === 'Function');
assert(avkind(Math.sin) === 'Function');
});
test('shows undefined accurately', function(){
assert(avkind(undefined) === 'undefined');
});
test('shows null accurately', function(){
assert(avkind(null) === 'null');
});
});
suite('Functions work with no prefix at all', function(){
agave();
test('strips from the right accurately', function(){
assert.equal('Hello world'.rightStrip('ldr'), 'Hello wo');
});
agave();
test('strips from the right accurately', function(){
assert.equal('Hello world'.rightStrip('ldr'), 'Hello wo');
});
});

@@ -421,0 +386,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc