Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
version 1
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 127 changed files with 3,047 additions and 4,109 deletions.
22 changes: 22 additions & 0 deletions build/end/documentReady.js
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);
});
}
});
});
6 changes: 4 additions & 2 deletions build/end/end.js
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;
}
12 changes: 3 additions & 9 deletions build/end/info.js
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');
35 changes: 14 additions & 21 deletions build/modules/array/array.js
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;
5 changes: 0 additions & 5 deletions build/modules/array/modules/apply.js

This file was deleted.

12 changes: 12 additions & 0 deletions build/modules/array/modules/arrayLast.js
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;
};
118 changes: 59 additions & 59 deletions build/modules/array/modules/bsearch.js
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;
};
};
20 changes: 9 additions & 11 deletions build/modules/array/modules/chunk.js
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;
6 changes: 3 additions & 3 deletions build/modules/array/modules/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
* console.log(b, b === a);
* // -> [1, 2, 3] false
*/
$.clone = function (item) {
return item.slice(0);
};
$.cloneArray = function (item) {
return stringSliceCall(item,0);
};
2 changes: 1 addition & 1 deletion build/modules/array/modules/compact.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @returns {Array} The new array containing only the truthy values from the original array.
*
* @example
* [0, 1, false, 2, '', 3].compact();
* [0, 1, false, 2, emptyString, 3].compact();
* // -> [1, 2, 3]
*/
$.compact = compact;
30 changes: 14 additions & 16 deletions build/modules/array/modules/countby.js
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 }
*/
*/
6 changes: 3 additions & 3 deletions build/modules/array/modules/createrange.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $.createRange = function (array,start_arg, stop_arg, increment) {
i_check = i + increment;
}
}
array.push(i);
pushArray(array,i);
if (increment) {
if (i_check == stop) {
break;
Expand All @@ -31,12 +31,12 @@ $.createRangeTo = function (array,start_arg, stop_arg, increment) {
i_check = i + increment;
}
}
array.push(i);
pushArray(array,i);
if (increment) {
if (i_check == stop) {
break;
}
}
}
return array;
};
};
Loading

0 comments on commit 452c233

Please sign in to comment.