2.2.0 • Published 4 years ago

simplifying v2.2.0

Weekly downloads
20
License
MIT
Repository
github
Last release
4 years ago

Simplifying JS

Image of simplifying

Build Status License: MIT npm version npm GitHub repo size npm bundle size Active GitHub tag Generic badge

A lightweight library containing multiple utility functions to make your life easier when dealing with arrays and objects.

HOW TO USE

Open the terminal and navigate to the root directory of your project. Install Simplifying:

npm i simplifying

If you do not have npm installed, you can download it here.

EXAMPLE CODE:
const array = require('simplifying');
let arr = [2, 3, 4, 3, 3, 2, 4];
console.log(array.removeDuplicates(arr));

//OUTPUT: [2, 3, 4]

Image of example code

List of all methods on array:

MethodParametersUse
shufflearray: ArrayShuffles array and returns it
removeDuplicatesarray: ArrayRemoves all duplicate elements and returns a new array
pickRandomarray: Array, n: Number, unique?: BooleanReturns an array of n random elements from array.The returned elements will be unique if true is passed in the third parameter
countItemarray: Array, item: anyReturns the frequency of the passed item in the array
countAllarray: ArrayReturns a map which holds the frequencies of all items in the array
searchItemsarray: Array, item: anyReturns all positions where the given item is found
removeItemsarray: Array, item: anyDeletes multiple occurances of the given item
toArrayx: (string, number)Converts string or number to array of characters or digits
mergearray1: Array, array2: Array, type?: stringMerge two arrays.type == 'merge-all': Keep the duplicatestype == 'common': Returns common elementsno type: Merge and remove common
cleanarray: ArrayRemoves null, undefined, '', NaN
flattenarray: ArrayFlattens all nested arrays inside
swapByPositionarray: Array,pos1: number,pos2: numberSwaps values in pos1 and pos2 in the array
swapByValuesarray: Array, value1: any, value2: anySwaps value1 and value2 in the array
performarray: Array, operation: stringPerforms the said operation on the array.Allowed Operations:sum, product, min, max, average
arrayToObjectarray: ArrayConverts an array to object
slidearray: Array, steps: number, direction?: stringShifts array by n steps in the given direction. The default direction is left
rangearray: Array, start: number, end: numberReturns a subarray from start to end - 1
jumparray: Array, steps: numberReturns a subarray jumping the steps mentioned
isUniquearray: ArrayReturn true if all elements are unique in the array and false otherwise

List of all methods on array of objects:

MethodParametersUse
arrayOfObjectsToObjectarray: Array, keyField: stringConverts an array of objects to an object where key is keyField
sortByKeyFieldarray: Array, keyField: string, order?: stringSorts an array of objects based on keyField. Default sorting order is ascending. Pass 'desc' to order for reverse.
getFieldsarray: Array, fields: ArrayReturns an array of objects containing only the required fields
getOneFieldarray: Array, field: stringReturns an array of all the values of the particular field
searchByKeyFieldarray: Array, searchField: string, searchValue: string, reqFields?: ArraySearches the array for the given (key, value) pair and returns only the reqFields. If nothing is passed, the whole object is returned.
deleteByKeyFieldarray: Array, field: string, value: stringDeletes an item based on the (key, value) pair
getKeysarray: ArrayReturns an array of all the keys inside the object. Assumes that all objects have the same keys
findObjectsarray: Array, func: FunctionExecutes the function on all objects and returns the satisfied objects

LICENSE

MIT

Author

Subham Das

Open an issue if you feel the need for a change or want to report any bugs.
2.2.0

4 years ago

2.1.0

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago