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.
Based off of the most recent version of Acid with modifications for script importing for Node & webworkers.
- Loading branch information
Tomek Marchi
committed
Feb 3, 2016
1 parent
c8b0764
commit 452c233
Showing
127 changed files
with
3,047 additions
and
4,109 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,22 @@ | ||
//log out the ACID version | ||
acidConsole(`Acidjs v${$.acid.version}`, 'notify'); | ||
eachArray([ | ||
[arrayNative, arrayPrototype, 'array'], | ||
[objectNative, objectPrototype, 'object'], | ||
[stringNative, stringPrototype, 'string'] | ||
], (proto) => { | ||
var name = proto[2], | ||
extendToGlobal = (key, name, funct) => { | ||
$[`${name}${ucFirst(key)}`] = funct; | ||
}; | ||
$[name] = proto[0]; | ||
eachProperty(proto[1], (item, key) => { | ||
if (isFunction(item)) { | ||
extendToGlobal(key, name, function(that) { | ||
var args = toArray(arguments); | ||
shiftArray(args); | ||
return apply(item, that, args); | ||
}); | ||
} | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
return $; | ||
}; | ||
return $;}; | ||
if(!typeof module !== 'undefined' && module.exports){ | ||
module.exports = lucy; | ||
} |
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 |
---|---|---|
@@ -1,11 +1,5 @@ | ||
//acid platform information | ||
$.lucy = { | ||
//lib name | ||
name: 'Lucy', | ||
//lib version | ||
version: 1, | ||
//platform type | ||
platform: 'stable' | ||
$.acid = { | ||
name: 'LucyJS', | ||
version: 1 | ||
}; | ||
//log out the ACID version | ||
acidConsole(`Lucy v${$.lucy.version} ${$.lucy.platform}`,'notify'); |
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 |
---|---|---|
@@ -1,44 +1,37 @@ | ||
//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)) { | ||
var _flatten_once = (arr) => { | ||
return arrayReduce(arr,(a, b) => { | ||
if (!isArray(a)) { | ||
a = [a]; | ||
} | ||
if (!_isArray(b)) { | ||
if (!isArray(b)) { | ||
b = [b]; | ||
} | ||
pushApply(a, b); | ||
return a; | ||
}); | ||
}, | ||
flatten = function(array, level) { | ||
flatten = $.flatten = (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]); | ||
array = arrayReduce(array,(previousValue, currentValue, index, array) =>{ | ||
return concatCall(previousValue,(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); | ||
return arrayReduce(array,(previousValue, currentValue, index, array) =>{ | ||
return concatCall(previousValue,(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; | ||
compact = (array) => { | ||
return eachArray(array,(item)=>{ | ||
return item || undefined; | ||
}); | ||
}; | ||
//initialize array object for array prototype | ||
var array_extend = {}; | ||
$.array=arrayNative; |
This file was deleted.
Oops, something went wrong.
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 @@ | ||
var arrayLastItem=function (array,indexFrom) { | ||
var result; | ||
if(!indexFrom){ | ||
indexFrom=1; | ||
} | ||
if (array) { | ||
result = spliceArray(array,getLength(array) - indexFrom, indexFrom); | ||
}else{ | ||
result = array[getLength(array) - 1]; | ||
} | ||
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 |
---|---|---|
@@ -1,68 +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; | ||
* 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, | ||
high = getLength(item), | ||
mid; | ||
|
||
if (compareFunction) { | ||
while (low < high) { | ||
mid = (low + high) >>> 1; | ||
var direction = compareFunction(item[mid], value); | ||
if (!direction) { | ||
return mid; | ||
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; | ||
} | ||
} | ||
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; | ||
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 |
---|---|---|
@@ -1,13 +1,11 @@ | ||
//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 arrayChunk = function(array, size) { | ||
size = size || 1; | ||
var numChunks = ceilmethod(getLength(array) / size), | ||
index = 0; | ||
return eachArray(newArray(numChunks),(item,i) =>{ | ||
return chunkSlice(array, index, (index += size)); | ||
}); | ||
}; | ||
|
||
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; | ||
}; | ||
$.chunk = arrayChunk; |
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
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
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 |
---|---|---|
@@ -1,26 +1,24 @@ | ||
//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; | ||
$.countBy = function(array, funct) { | ||
var object = {}, | ||
result; | ||
eachObject(array, (item) => { | ||
result = funct(item); | ||
if (!object[result]) { | ||
object[result] = 0; | ||
} | ||
object[result]++; | ||
}); | ||
return object; | ||
}; | ||
|
||
/* | ||
[4.3, 6.1, 6.4].countBy(function(n) { | ||
return n.floor(); | ||
$.countBy([4.3, 6.1, 6.4],function(numb) { | ||
return Math.floor(numb); | ||
}); | ||
//{ '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
Oops, something went wrong.