Node module for Array, Object, String, Decorator, extention Utils like for Python and more for Node.js
Find the demos in the demos folder
var ArrayExtended = require("extenders").ArrayExtended;
let arr = ArrayExtended([1,2,3,4,5,6]);
console.log(arr);
arr.clear();
console.log(arr);
var ArrayExtended = import("extenders").ArrayExtended;
let arr = ArrayExtended([1,2,3,4,5,6]);
console.log(arr);
arr.clear();
console.log(arr);
import ArrayExtended from "extenders";
let arr = ArrayExtended([1,2,3,4,5,6]);
console.log(arr);
arr.clear();
console.log(arr);
The extenders library's array extended functions tries to add many common use cases of array modifiers and functions missing or used constantly in projects. This library tries to provide/ incorporate all (or atleast most) 1. python list/ tuple functions 2. common use cases of Math, and other array like functions 3. _ (underscore) functions missing from python list, tuple, common functions
var extendArray = require("extenders").extendArray;
extendArray();
let arr = [1,2,3,4,5,6];
console.log(arr);
arr.clear();
console.log(arr);
var ArrayExtended = require("extenders").ArrayExtended;
let arr = ArrayExtended([1,2,3,4,5,6]);
console.log(arr);
arr.clear();
console.log(arr);
var extendArray = require("extenders").extendArray;
extendArray();
// Below find the usage of the extended functions
Execute the function provided that takes the iterator as an argument of the function.
[1, 2, 3, 4].execute(executeFunction)
Extend or Concat the provided iterable at provided index
. The default is last index of the array.
[1, 2, 3, 4].extend(iterable, index)
Returns the provided number (count) of maximum values in the array from start
index to end
index.
[1, 2, 3, 4].max(count, start, end)
Returns the provided number (count) of maximum values with their indexes in the array from start
index to end
index.
[1, 2, 3, 4].maxIndexes(count, start, end)
Returns the provided number (count) of minimal values in the array from start
index to end
index.
[1, 2, 3, 4].min(count, start, end)
Returns the provided number (count) of minimal values with their indexes in the array from start
index to end
index.
[1, 2, 3, 4].minIndexes(count, start, end)
Returns the average of all the number or decimal values in the array from start
index to end
index.
[1, 2, 3, 4].average(start, end)
Returns the sum of all the number or decimal values in the array from start
index to end
index.
[1, 2, 3, 4].sum(start, end)
Modifies the array with acos
of all the values. Modifies the whole array in place. The method option has two options - replace
(replace the whole array with these values) and inrange
(just replace the range of items with the new array values keeping the left and right array items in place)
[1, 2, 3, 4].acosMap(start, end, method = "replace", thisValue)
Modifies the array with cos
of all the values. Modifies the whole array in place. The method option has two options - replace
(replace the whole array with these values) and inrange
(just replace the range of items with the new array values keeping the left and right array items in place)
[1, 2, 3, 4].cosMap(start, end, method = "replace", thisValue)
Modifies the array with sin
of all the values. Modifies the whole array in place. The method option has two options - replace
(replace the whole array with these values) and inrange
(just replace the range of items with the new array values keeping the left and right array items in place)
[1, 2, 3, 4].sinMap(start, end, method = "replace", thisValue)
Modifies the array with asin
of all the values. Modifies the whole array in place. The method option has two options - replace
(replace the whole array with these values) and inrange
(just replace the range of items with the new array values keeping the left and right array items in place)
[1, 2, 3, 4].asinMap(start, end, method = "replace", thisValue)
Modifies the array with absolute
of all the values. Modifies the whole array in place. The method option has two options - replace
(replace the whole array with these values) and inrange
(just replace the range of items with the new array values keeping the left and right array items in place)
[1, 2, 3, 4].absMap(start, end, method = "replace", thisValue)
Returns the factorial value
of all number values of the array from start
index to end
index.
[1, 2, 3, 4].factorialMap(start, end, thisValue)
Returns the array with cos
of all the values of the array from start
index to end
index. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].cosMapCopy(start, end, method = "replace", thisValue)
Returns the array with acos
of all the values of the array from start
index to end
index. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].acosMapCopy(start, end, method = "replace", thisValue)
Returns the array with sin
of all the values of the array from start
index to end
index. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].sinMapCopy(start, end, method = "replace", thisValue)
Returns the array with asin
of all the values of the array from start
index to end
index. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].asinMapCopy(start, end, method = "replace", thisValue)
Returns the array with absMap
of all the values of the array from start
index to end
index. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].absMapCopy(start, end, method = "replace", thisValue)
Modifies the array with floor
of all the number values from start
index to end
index. Modifies the whole array in place. The method option has two options - replace (replace the whole array with these values) and inrange (just replace the range of items with the new array values keeping the left and right array items in place).
[1, 2, 3, 4].floorMap(start, end, method = "replace", thisValue)
Modifies the array with ceil
of all the number values from start
index to end
index. Modifies the whole array in place. The method option has two options - replace (replace the whole array with these values) and inrange (just replace the range of items with the new array values keeping the left and right array items in place).
[1, 2, 3, 4].ceilMap(start, end, method = "replace", thisValue)
Modifies the array with round
of all the number values from start
index to end
index. Modifies the whole array in place. The method option has two options - replace (replace the whole array with these values) and inrange (just replace the range of items with the new array values keeping the left and right array items in place).
[1, 2, 3, 4].roundMap(start, end, method = "replace", thisValue)
Returns the copy of array with floor
of all the number values from start
index to end
index. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].floorMapCopy(start, end, method = "replace", thisValue)
Returns the copy of array with ceil
of all the number values from start
index to end
index. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].ceilMapCopy(start, end, method = "replace", thisValue)
Returns the copy of array with round
of all the number values from start
index to end
index. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].roundMapCopy(start, end, method = "replace", thisValue)
Modifies the array with square
of all the array values from start
index to end
index. Modifies the whole array in place. The method option has two options - replace (replace the whole array with these values) and inrange (just replace the range of items with the new array values keeping the left and right array items in place)
[1, 2, 3, 4].squareMap(start, end, method = "replace", thisValue)
Modifies the array with square root
of all the array values from start
index to end
index. Modifies the whole array in place. The method option has two options - replace (replace the whole array with these values) and inrange (just replace the range of items with the new array values keeping the left and right array items in place)
[1, 2, 3, 4].sqrtMap(start, end, method = "replace", thisValue)
Modifies the array with power
of all the array values with the provided power value from start
index to end
index. Modifies the whole array in place. The method option has two options - replace (replace the whole array with these values) and inrange (just replace the range of items with the new array values keeping the left and right array items in place)
[1, 2, 3, 4].powMap(power, start, end, method = "replace", thisValue)
Modifies the array with multiplication
of all the array values from start
index to end
index with provided multiplier. Modifies the whole array in place. The method option has two options - replace (replace the whole array with these values) and inrange (just replace the range of items with the new array values keeping the left and right array items in place)
[1, 2, 3, 4].multiplyMap(multiplier, start, end, method = "replace", thisValue)
Returns the array with square
of all the array values from start
index to end
index. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].squareMapCopy(start, end, method = "replace", thisValue)
Returns the array with square root
of all the array values from start
index to end
index. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].sqrtMapCopy(start, end, method = "replace", thisValue)
Returns the array with power
of all the array values with provided power value from start
index to end
index. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].powMapCopy(power, start, end, method = "replace", thisValue)
Returns the array with multiplication
of provided multiplier with all the array values from start
index to end
index. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].multiplyMapCopy(multiplier, start, end, method = "replace", thisValue)
Returns the array with count number of array items with random values multiplied with the provided multiplier. Modifies the array in place.
[1, 2, 3, 4].randomRange(count, multiplier)
Modifies the array with array items with random values multiplied with the provided multiplier from start
index to end
index. Modifies the array in place.
[1, 2, 3, 4].fillRange(item, start, end, method = "inrange", thisValue)
Append the item to the array. Modifies the array in place.
[1, 2, 3, 4].append(item)
Returns if the provided iterable is an array. Alternatively, if the iterable is not provided then it check if the object is an Array.
[1, 2, 3, 4].isArray(iterable)
Insert the item to the array at index provided. Modifies the array in place.
[1, 2, 3, 4].insert(index, item, thisArray)
Insert the array or list of items to the array at index provided. Modifies the array in place.
[1, 2, 3, 4].insertAll(index, array, thisArray)
Concat the array or list of items to the array at index provided. Modifies the array in place.
[1, 2, 3, 4].concatMerge(array, thisValue, ...args)
Concat the array or list of items to the array at index provided. Modifies the array in place.
[1, 2, 3, 4].merge(array, thisValue, ...args)
Count the number of items in the array from start
index to end
index.
[1, 2, 3, 4].count(item, start, end, method = "replace", thisValue)
Replace the item to the array at index provided from start
index to end
index. Modifies the array in place.
[1, 2, 3, 4].replace(index, item, thisValue)
Replace the item to the array at index provided from start
index to end
index. Returns an new modified array.
[1, 2, 3, 4].replaceCopy(index, item, thisValue)
Replace the item to the array at index provided from start
index to end
index. Modifies the array in place.
[1, 2, 3, 4].replaceAll(item, replaceValue, start, end, method = "replace", thisValue)
Replace the item to the array at index provided from start
index to end
index. Returns an new modified array.
[1, 2, 3, 4].replaceAllCopy(item, replaceValue, start, end, method = "replace", thisValue)
Removes the first found equal item and Returns the removed item of array from start
index to end
index. Modifies the array in place.
[1, 2, 3, 4].remove(item, thisArray)
Removes all items and Returns the removed items of array from start
index to end
index. Modifies the array in place.
[1, 2, 3, 4].removeAll(item, start, end, method = "replace", thisValue)
Removes the first found equal item and Returns the removed item of array from start
index to end
index. Returns a new modified array object.
[1, 2, 3, 4].removeCopy(item, thisArray)
Removes all items and Returns the removed items of array from start
index to end
index. Returns a new modified array object.
[1, 2, 3, 4].removeAllCopy(item, start, end, method = "replace", thisValue)
Removes and Returns the removed item index of array. Modifies the array in place.
[1, 2, 3, 4].pop(index)
Clears the array from start
index to end
index. Modifies the array in place.
[1, 2, 3, 4].clear(start, end)
Returns the index of array from start
index to end
index. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].index(item, start, end, thisArray)
Modifies the array with a sort from start
index to end
index. Modifies the array in place.
[1, 2, 3, 4].sort(key = null, reverse = false, start, end, method = "replace", thisValue)
Return a one level reverse copy of the array from start
index to end
index. Modifies the array in place. The method option has two options - replace (replace the whole array with these values) and inrange (just replace the range of items with the new array values keeping the left and right array items in place)
[1, 2, 3, 4].reverse(start, end, thisValue)
Returns a deep reverse copy of the array from start
index to end
index. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].reverseCopy(start, end, thisValue)
Returns a deep copy of the array from start
index to end
index. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].copy(start, end, thisValue)
Returns the converted dictionary from the array from start
index to end
index. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].diction(mapperFunction, arg, start, end, keyconvertor, thisValue, keyArrayValue)
Check if the array from start
index to end
index is a subset of the other provided iterator. Returns a boolean.
[1, 2, 3, 4].subset(iterable, start, end, thisValue)
Check if the array from start
index to end
index is a superset of the other provided iterator. Returns a boolean.
[1, 2, 3, 4].superset(iterable, start, end, thisValue)
Returns an object that has different items from start
index to end
index in the provided iterator when compared to the array. Returns a new object and does not modify the array in place
[1, 2, 3, 4].diffIterable(iterable, start, end, thisValue)
Returns an object that has different items from start
index to end
index in the array when compared to other provided iterator. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].diffSelf(iterable, start, end, thisValue)
Returns an object that has different items from start
index to end
index in both the array when compared to other provided iterator. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].diffBoth(iterable, start, end, thisValue)
Check is the array from start
index to end
index and provided iterator have similar number of items, similar items, and similar indexes.
[1, 2, 3, 4].equal(iterable, start, end, thisValue)
Check if the array from start
index to end
index and provided iterator have similar number of items and similar item values.
[1, 2, 3, 4].similar(iterable, start, end, thisValue)
Modifies the array from start
index to end
index into all the unique items in an array. Modifies the array in place. The method option has two options - replace (replace the whole array with these values) and inrange (just replace the range of items with the new array values keeping the left and right array items in place).
[1, 2, 3, 4].uniques(start, end, method = "replace", thisValue)
Returns all the unique items of an array from start
index to end
index. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].uniquesCopy(start, end, method = "replace", thisValue)
Modifies the array from start
index to end
index into (only) all the duplicate items in an array. Modifies the array in place. The method option has two options - replace (replace the whole array with these values) and inrange (just replace the range of items with the new array values keeping the left and right array items in place).
[1, 2, 3, 4].duplicates(start, end, method = "replace", thisValue)
Returns (only) all the duplicate items of an array from start
index to end
index. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].duplicatesCopy(start, end, method = "replace", thisValue)
Insert the item of into an array using the push method (Bottom FIFO queue execution)
[1, 2, 3, 4].enqueue(item)
Remove the first item of an array using the shift method (Bottom FIFO queue execution)
[1, 2, 3, 4].dequeue()
Transpose the array from start
index to end
index. Modifies the array in place. The method option has two options - replace (replace the whole array with these values) and inrange (just replace the range of items with the new array values keeping the left and right array items in place).
[1, 2, 3, 4].transpose(iterator, start, end, method = "replace", thisValue)
Transpose the array from start
index to end
index. Returns a new object and does not modify the array in place.
[1, 2, 3, 4].transposeCopy(iterator, start, end, method = "replace", thisValue)
Create an array into immutable array using the freeze
method. Modifies the array in place unless an array
is provided. array
option provided returns a frozen object as if .freeze
is a frozen array object creator.
[1, 2, 3, 4].immutables(array)
[1, 2, 3, 4].freeze(array)
[1, 2, 3, 4].tuple(array)
[1, 2, 3, 4].immutables()
[1, 2, 3, 4].freeze()
[1, 2, 3, 4].tuple()
Flatten the array from start
index to end
index . Modify's the array in place. The method option has two options - replace (replace the whole array with these values) and inrange (just replace the range of items with the new array values keeping the left and right array items in place).
[1, 2, 3, 4].flatten(start, end, method = "replace", thisValue)
Deep Flatten the array from start
index to end
index . Modify's the array in place. The method option has two options - replace (replace the whole array with these values) and inrange (just replace the range of items with the new array values keeping the left and right array items in place).
[1, 2, 3, 4].flattenDeep(start, end, method = "replace", thisValue)
Flatten the array from start
index to end
index . Returns a new object and does not modify the array in place.
[1, 2, 3, 4].flattenCopy(start, end, method = "replace", thisValue)
Deep Flatten the array from start
index to end
index . Returns a new object and does not modify the array in place.
[1, 2, 3, 4].flattenDeepCopy(start, end, method = "replace", thisValue)
Create a range of numbers from start
index to end
index with a increment of provided step
.
[1, 2, 3, 4].range(start, stop, step)
Enumerate an array into an iteratable array of objects with structure {index, value}
or [index, value]
in each item. Type can be object or array.
[1, 2, 3, 4].enumerate(type = "object", thisValue)
Generator is a function that returns a generator function from an array into a iteratable generator function with its values of objects with structure {index, value}
or [index, value]
. Type can be object or array.
[1, 2, 3, 4].generator(type = "object", thisValue)
Delete items of an array from start index to end index.
[1, 2, 3, 4].del(start, end, thisValue)
Log items of an array from start
index to end
index to console.
[1, 2, 3, 4].log(start, end, message = "", callback = console.log, thisValue)
var extendObject = require("extenders").extendObject;
extendObject();
let arr = [1,2,3,4,5,6];
console.log(arr);
arr.clear();
console.log(arr);
var ObjectExtended = require("extenders").ObjectExtended;
let obj = ObjectExtended.create({ "test" : "test", "tester" : "100" });
console.log(obj);
obj.clear();
console.log(obj);
var StringExtended = require("extenders").StringExtended;
let str = new StringExtended("Tesing my modified String JS object functions");
console.log(str);
str.clear();
console.log(str);
var extendString = require("extenders").extendString;
extendString();
let str = "Tesing my modified String JS object functions";
console.log(str);
str.clear();
console.log(str);
"Test string".clear(start, end)
var NumberExtended = require("extenders").NumberExtended;
let str = new NumberExtended("Tesing my modified String JS object functions");
console.log(str);
str.clear();
console.log(str);
var extendNumber = require("extenders").extendNumber;
extendNumber();
let str = "Tesing my modified String JS object functions";
console.log(str);
str.clear();
console.log(str);
.imul(...args)
var extendMath = require("extenders").extendMath;
extendMath();
let arr = [1,2,3,4,5,6,7,8,9];
console.log(arr);
arr.imul();
console.log(arr);
.imul(...args)
.clear(start, end)
singleton(key, object, replace, freeze)
var singleton = require("extenders").singleton;
let key = "somename";
let object = { "test": "value" };
let replace = true;
let freeze = true;
let inst = singleton(key, object, replace, freeze);
console.log(inst);
.createClassDecorator(decoratorFunction)
const createClassDecorator = require('./src/decorator').createClassDecorator;
function addLogMethod(target, prefix = "") {
target.prototype.log = function (msg) {
console.log(`[${prefix}${this.constructor.name}] ${msg}`);
};
}
const loggable = createClassDecorator(addLogMethod);
@loggable("Prefix ")
class Example {
constructor(name) {
this.name = name;
}
}
const exloggable = new Example("example");
exloggable.log("Hello, world!"); // logs "[Prefix Example] Hello, world!"
.createMethodDecorator(decoratorFunction)
const createMethodDecorator = require('./src/decorator').createMethodDecorator;
// Method
const addPrefix = createMethodDecorator((result, prefix) => {
return `${prefix}: ${result}`;
});
class Example {
@addPrefix("Result")
add(a, b) {
return a b;
}
}
const exaddPrefix = new Example();
console.log(exaddPrefix.add(2, 3)); // logs "Result: 5"
.clear()
.clear()
.clear()
- In development for Object, String, Decorator, Math, Numbers.
Check .todo file for latest TODO list
The MIT License (MIT) - See LICENSE for further details
Copyright © 2023 - till library works