This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First Stable Release of Lucy
- Loading branch information
tommarchi
committed
Oct 9, 2015
1 parent
5686ff0
commit 58ba2d9
Showing
111 changed files
with
5,326 additions
and
599 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
return $; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//acid platform information | ||
$.lucy = { | ||
//lib name | ||
name: 'Lucy', | ||
//lib version | ||
version: 6.0, | ||
//platform type | ||
platform: 'stable' | ||
}; | ||
//log out the ACID version | ||
console.log('Lucy v' + $.lucy.version); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//shared functions | ||
//Flattens a nested array. Pass level to flatten up to a depth; | ||
var _flatten_once = function(arr) { | ||
return arr.reduce(function(a, b) { | ||
if (!_isArray(a)) { | ||
a = [a]; | ||
} | ||
if (!_isArray(b)) { | ||
b = [b]; | ||
} | ||
pushApply(a, b); | ||
return a; | ||
}); | ||
}, | ||
flatten = function(array, level) { | ||
if (level) { | ||
if (level === 1) { | ||
return _flatten_once(array); | ||
} | ||
for (var i = 0; i < level; i++) { | ||
array = array.reduce(function(previousValue, currentValue, index, array) { | ||
return previousValue.concat((_isArray(currentValue)) ? currentValue : [currentValue]); | ||
}, []); //initial starting value is an amepty array [] | ||
} | ||
return array; | ||
} | ||
return array.reduce(function(previousValue, currentValue, index, array) { | ||
return previousValue.concat((_isArray(currentValue)) ? flatten(currentValue) : currentValue); | ||
}, []); //initial starting value is an amepty array [] | ||
}, | ||
//cache for function that removes falsey values from array | ||
compact = function(self) { | ||
var result = []; | ||
|
||
for (var i = 0; i < self.length; i++) { | ||
if (self[i]) { | ||
result.push(self[i]); | ||
} | ||
} | ||
|
||
return result; | ||
}; | ||
//initialize array object for array prototype | ||
var array_extend = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
$.pushApply=function(item,array){ | ||
return _array_push.apply(item,array); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Finds the index of a value in a sorted array using a binary search algorithm. | ||
* | ||
* If no `compareFunction` is supplied, the `>` and `<` relational operators are used to compare values, | ||
* which provides optimal performance for arrays of numbers and simple strings. | ||
* | ||
* @function Array#bsearch | ||
* @param {*} value - The value to search for. | ||
* @param {Function} [compareFunction] - The same type of comparing function you would pass to | ||
* [`.sort()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort). | ||
* @returns {number} The index of the value if it is in the array, or `-1` if it cannot be found. | ||
* If the search value can be found at multiple indexes in the array, it is unknown which of | ||
* those indexes will be returned. | ||
* | ||
* @example | ||
* ['a', 'b', 'c', 'd'].bsearch('c'); | ||
* // -> 2 | ||
* | ||
* [1, 1, 2, 2].bsearch(2); | ||
* // -> 2 or 3 | ||
* | ||
* [1, 2, 3, 4].bsearch(10); | ||
* // -> -1 | ||
* | ||
* [1, 2, 3, 4].bsearch(1, function(a, b) { | ||
* return a - b; | ||
* }); | ||
* // -> 0 | ||
* | ||
* ['img1', 'img2', 'img10', 'img13'].bsearch('img2', String.naturalCompare); | ||
* // -> 1 | ||
* // `String.naturalCompare` is provided by the string-natural-compare npm module: | ||
* // https://www.npmjs.com/package/string-natural-compare | ||
*/ | ||
$.bsearch= function(item,value, compareFunction) { | ||
var low = 0; | ||
var high = item.length; | ||
var mid; | ||
|
||
if (compareFunction) { | ||
while (low < high) { | ||
mid = (low + high) >>> 1; | ||
var direction = compareFunction(item[mid], value); | ||
if (!direction) { | ||
return mid; | ||
} | ||
if (direction < 0) { | ||
low = mid + 1; | ||
} else { | ||
high = mid; | ||
} | ||
} | ||
} else { | ||
while (low < high) { | ||
mid = (low + high) >>> 1; | ||
if (item[mid] === value) { | ||
return mid; | ||
} | ||
if (item[mid] < value) { | ||
low = mid + 1; | ||
} else { | ||
high = mid; | ||
} | ||
} | ||
} | ||
|
||
return -1; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//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. | ||
$.chunk = function (array,chunk) { | ||
size = size || 1; | ||
|
||
var numChunks = Math.ceil(array.length / size); | ||
var result = new Array(numChunks); | ||
|
||
for (var i = 0, index = 0; i < numChunks; i++) { | ||
result[i] = chunkSlice(array, index, (index += size)); | ||
} | ||
|
||
return result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Removes all elements from the array. | ||
* | ||
* @function Array#clear | ||
* | ||
* @example | ||
* var array = [1, 2, 3]; | ||
* array.clear(); | ||
* console.log(array); | ||
* // -> [] | ||
*/ | ||
$.clear = function(array) { | ||
array.length = 0; | ||
return array; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Creates a shallow copy of the array. | ||
* | ||
* @function Array#clone | ||
* @returns {Array} A clone of the array. | ||
* | ||
* @example | ||
* var a = [1, 2, 3]; | ||
* var b = a.clone(); | ||
* console.log(b, b === a); | ||
* // -> [1, 2, 3] false | ||
*/ | ||
$.clone = function (item) { | ||
return item.slice(0); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Returns a new array with all falsey values removed. Falsey values | ||
* are `false`, `0`, `""`, `null`, `undefined`, and `NaN`. | ||
* | ||
* @function Array#compact | ||
* @returns {Array} The new array containing only the truthy values from the original array. | ||
* | ||
* @example | ||
* [0, 1, false, 2, '', 3].compact(); | ||
* // -> [1, 2, 3] | ||
*/ | ||
$.compact = compact; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//Sorts a list into groups and returns a count for the number of objects in each group. | ||
$.countBy = function (array,funct) { | ||
var object = {}, | ||
item, | ||
len = array.length; | ||
for (var i = 0; i < len; i++) { | ||
item = array[i], | ||
results = funct(item); | ||
if (!object[results]) { | ||
object[results] = 0; | ||
} | ||
object[results] = object[results] + 1; | ||
} | ||
return object; | ||
}; | ||
|
||
/* | ||
[4.3, 6.1, 6.4].countBy(function(n) { | ||
return n.floor(); | ||
}); | ||
//{ '4': 1, '6': 2 } | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//create an array from a range | ||
$.createRange = function (array,start_arg, stop_arg, increment) { | ||
var stop = (stop_arg) ? stop_arg : start_arg, | ||
start = (stop_arg) ? start_arg : 0; | ||
for (var i = start; i < stop; i++) { | ||
if (increment) { | ||
if (i > 0) { | ||
var i = i - 1 + 5, | ||
i_check = i + increment; | ||
} | ||
} | ||
array.push(i); | ||
if (increment) { | ||
if (i_check == stop) { | ||
break; | ||
} | ||
} | ||
} | ||
return array; | ||
}; | ||
|
||
//create an array from a range | ||
$.createRangeTo = function (array,start_arg, stop_arg, increment) { | ||
var stop = (stop_arg) ? stop_arg : start_arg, | ||
i, | ||
start = (stop_arg) ? start_arg : 0; | ||
for (var i = start; i <= stop; i++) { | ||
if (increment) { | ||
if (i > 0) { | ||
i = i - 1 + 5, | ||
i_check = i + increment; | ||
} | ||
} | ||
array.push(i); | ||
if (increment) { | ||
if (i_check == stop) { | ||
break; | ||
} | ||
} | ||
} | ||
return array; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//Creates an array excluding all values of the provided arrays using SameValueZero for equality comparisons. | ||
$.difference = function (array,compare) { | ||
var difference = [], | ||
len = array.length; | ||
for (var i = 0; i < len; i++) { | ||
var item = array[i], | ||
indexof=compare.indexOf(item); | ||
if (indexof == -1) { | ||
difference.push(item); | ||
} | ||
} | ||
return difference; | ||
}; | ||
|
||
//Creates an array excluding all values of the arrays using SameValueZero for equality comparisons. | ||
$.differenceAll = function (array) { | ||
var len = array.length, | ||
subitem, | ||
item, | ||
difference = []; | ||
for (var i = 0; i < len; i++) { | ||
item = array[i], | ||
sub_len = item.length; | ||
for (var a = 0; a < sub_len; a++) { | ||
subitem=item[a], | ||
indexof=difference.indexOf(subitem); | ||
if (indexof == -1) { | ||
difference.push(subitem); | ||
}else{ | ||
difference.splice(indexof,1); | ||
} | ||
} | ||
} | ||
return difference; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//Creates a an 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). | ||
$.dropWhile = function (array,funct) { | ||
var temp = [], | ||
len = array.length; | ||
for (var i = 0; i < len; i++) { | ||
var item = array[i], | ||
condition = funct(item, i, array); | ||
if (!condition) { | ||
temp.push(item); | ||
} | ||
} | ||
return temp; | ||
}; | ||
|
||
//Creates a an 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). | ||
$.dropRightWhile = function (array,funct) { | ||
var temp = [], | ||
item, | ||
len = array.length; | ||
for (var i = len-1; i >= 0; i--) { | ||
item = array[i], | ||
condition = funct(item, i, array); | ||
if (!condition) { | ||
temp[i]=item; | ||
} | ||
} | ||
return temp; | ||
}; | ||
|
||
|
||
//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. | ||
$.drop = function (array,amount) { | ||
return array.splice(amount,array.length); | ||
}; | ||
|
||
//Removes elements from array corresponding to the given indexes (from right) and returns an array of the removed elements. Indexes may be specified as an array of indexes or as individual arguments. | ||
$.dropRight = function (array,amount) { | ||
return array.slice(0,array.length-amount); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//loop through array using for loop cached | ||
$.eachArray = _each_array; | ||
|
||
//loop through array using for loop cached but without returning data | ||
$.eachRaw = eachRaw; | ||
|
||
//loop through array backwards aka from the right | ||
$.eachRight = eachArrayFromRight; | ||
|
||
//loop through array using for loop cached | ||
$.eachDo = _each_array; | ||
|
||
//each while the check function is true | ||
$.eachWhile = _eachWhile; | ||
|
||
//loop while the returned result is true | ||
$.whileTrue = _whileTrue; | ||
|
||
//loop while the returned result is false | ||
$.whileFalse = _whileFalse; | ||
|
||
//loop while the count is less than the length of the array | ||
$.whileLength = _whileLength; |
Oops, something went wrong.