1.3.30 • Published 2 years ago

array_helperz v1.3.30

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

array_helperz

License: MIT NPM Downloads Play with docs

Instructions:

npm install array_helperz
const array_helperz =  require('array_helperz')

If utilizing in html...:

<script src="./node_modules/array_helperz/index.js"></script>
<script> 
$(()=> { 
     const output =  array_helperz.method(parameter)
 })
</script>
const arrz = require("array_helperz")

let arr = [{
        title: 'I want to be free. Free to live,  and to find my own way,  to love,  or to be alone,  but at least it is my choice,  and I am so tired of not having choices,  so scared of the years rushing past beneath my feet. I do not want to die as I’ve lived,  which is no life at all.',
        status: 'to do',
        date: new Date(2020, 1, 1),
        id: 1
    },
    {
        title: 'Because we loved each other too much and found each other too interesting. And I love that about humanity,  and in fact it’s the very reason I root for us to survive—because we are so stupid about each other.',
        status: 'doing',
        date: new Date(2021, 1, 1),
        id: 2
    },
    {
        title: 'But a life without art,  without wonder,  without beautiful things—she would go mad. She has gone mad. What she needs are stories. Stories are a way to preserve one’s self. To be remembered. And to forget.',
        status: 'doing',
        date: new Date(2022, 1, 1)
        id: 3
    }
]

let arr2 = [{
    "user_id": 4,
    "task_id": 1,
    "tag": "quote",
    "snippet": "be more selfish with your time. this is your life. reach your own goals. be more confident in yourself, you got this. i want cyrus on my team",
    "hourglass_id": 4,
    "id": 1
}, {
    "user_id": 4,
    "task_id": 1,
    "tag": "quote",
    "snippet": "be more selfish with your time. this is your life. reach your own goals. be more confident in yourself, you got this. i want cyrus on my team",
    "hourglass_id": 4,
    "id": 2
}]

function removeObj(x) {
    if (x.id === 2) {
        return true;
    }
}


array_helperz.filterWithFuncObjectOrString(arr, { status: "to do" })
array_helperz.trimArr(arr) // trims if value is string
array_helperz.countByCondition(arr, "id", 1) // returns number
array_helperz.search(arr, stringValue) // returns arr
array_helperz.filterItems(arr, stringKey, stringValue) // search for specific key 
array_helperz.filterValues(arr, stringValue, arrOfKeys)
array_helperz.sortAsc(arr, stringKey)
array_helperz.sortDesc(arr, stringKey)
array_helperz.contains(arr, stringKey, stringValue)
array_helperz.doesNotContain(arr, stringKey, stringValue)
array_helperz.group(arr, stringKey)
array_helperz.getUnique(arr, stringKey)
array_helperz.intersection(arr, arr2)
array_helperz.mergeByKeys({data: arr, key: "id" }, {data: arr2, key: "id" })
array_helperz.makeChildOfAnother({data: arr, key: "id" }, {data: arr2, key: "id" })
array_helperz.getOneMakeChildOfAnother({data: arr, key: "id", value: 2 }, {data: arr2, key: "id", value: 3 })
array_helperz.removeByFunction(arr, function sort(x) {if (x.id === 1 {return true})})
array_helperz.replaceKey(arr, originalKey, replaceKey)

Functions

filterWithFuncObjectOrString(array, object, value) ⇒ any

Kind: global function
Date: 2022-03-17
Author: zen-out

ParamTypeDescription
arrayarray
objectobject
valuearray= undefined

Example

let arrTwo = [
        { name: 'Because we loved each other too much and found each other too interesting. And I love that about humanity,  and in fact it’s the very reason I root for us to survive—because we are so stupid about each other.', status: 'doing', problem_id: 2, id: 1 },
        { name: 'I want to be free. Free to live,  and to find my own way,  to love,  or to be alone,  but at least it is my choice,  and I am so tired of not having choices,  so scared of the years rushing past beneath my feet. I do not want to die as I’ve lived,  which is no life at all.', status: 'doing', problem_id: 2, id: 2 },
        { name: 'But a life without art,  without wonder,  without beautiful things—she would go mad. She has gone mad. What she needs are stories. Stories are a way to preserve one’s self. To be remembered. And to forget.', status: 'to do', problem_id: 2, id: 3 }
    ]
    function getToDo(object) {
        if (object.status === "to do") {
            return object;
        }
    }
    let func = filterWithFuncObjectOrString(arrTwo, getToDo)
    let obj = filterWithFuncObjectOrString(arrTwo, { status: "to do" })
    let keyValue = filterWithFuncObjectOrString(arrTwo, "status", "to do")
    let key = filterWithFuncObjectOrString(arrTwo, "status")

trimArr(arr) ⇒ array

trims array values

Kind: global function
Date: 2021-12-19
Author: zen-out
Author: zen-out

ParamType
arrarray

countByCondition(array, key, value) ⇒ number

Kind: global function
Returns: number - of objects that meet that condition
Date: 2022-02-17
Author: zen-out

ParamType
arrayarray
keystring
valuestring

Example

const array_helperz = require("array_helperz")
let sampleInput = [{
status: "to do",
problem: "we actually solve our problems best by looking at how other people solved them - segment each feature",
whatshouldbe: "it should be easier to develop as a whole application but that's actually quite difficult - so segment each component and make sure you test utilizing good practices",
whatactuallyis: "there's no like, database of previous problems and how people solved them, right? also, what is your current process",
hypothesis: "like, what if i wanted to start my own business, how would i do that?",
plan: "test better, when you develop, i think it would also be great actually to have an effectiveness scale - what one task really helped you?"
}, { status: "doing", problem: "we need to focus on one thing at a time", whatshouldbe: "we should be able to do that easily", whatactuallyis: "its quite difficult", hypothesis: "develop modules", plan: "make things very clear and simple" }]
let output = array_helperz.countByCondition(sampleInput, "status", "to do")
console.log("🚀 ~ file: playground.js ~ line 11 ~ output", output)

search(array, string) ⇒ array

Kind: global function
Date: 2022-03-18
Author: zen-out

ParamType
arrayarray
stringstring

Example

var data = [{
        "id": "1",
        "name": "Ali",
        "BOD": "29/10/2055",
        "type": "primary",
        "email": null,
        "mobile": "010100000000",
        "notes": ["note1", "note2.nett", "note3"]
    },
    {
        "id": "2",
        "name": "Tie",
        "BOD": "29/10/2055",
        "type": "primary",
        "email": "b@v.net",
        "mobile": "0100000000",
        "notes": ["note4", "note5", "note6"]
    }
];
// search examples .
console.log("found", search(data, ".net")); //expected data[0] data[1]

filterValues(array, keyword, arrOfKeys) ⇒ array

Kind: global function
Returns: array - of objects
Date: 2022-02-17
Author: zen-out

ParamType
arrayarray
keywordstring
arrOfKeysarray

Example

const array_helperz = require("array_helperz")
let sampleInput = [{
status: "to do",
problem: "we actually solve our problems best by looking at how other people solved them - segment each feature",
whatshouldbe: "it should be easier to develop as a whole application but that's actually quite difficult - so segment each component and make sure you test utilizing good practices",
whatactuallyis: "there's no like, database of previous problems and how people solved them, right? also, what is your current process",
hypothesis: "like, what if i wanted to start my own business, how would i do that?",
plan: "test better, when you develop, i think it would also be great actually to have an effectiveness scale - what one task really helped you?"
}, { status: "doing", problem: "we need to focus on one thing at a time", whatshouldbe: "we should be able to do that easily", whatactuallyis: "its quite difficult", hypothesis: "develop modules", plan: "make things very clear and simple" }]
let output = array_helperz.filterValues(sampleInput, "segment", ["problem"])
console.log("🚀 ~ file: playground.js ~ line 11 ~ output", output)

sortAsc(array, key) ⇒ array

Kind: global function
Returns: array - of objects
Date: 2022-02-17
Author: zen-out

ParamTypeDescription
arrayarray
keystringto sort by

Example

const array_helperz = require("array_helperz")
let sampleInput = [{
created: new Date(2020, 12, 1),
status: "to do",
problem: "we actually solve our problems best by looking at how other people solved them - segment each feature",
}, { created: new Date(2019, 12, 1), status: "doing", problem: "we need to focus on one thing at a time" }]
let output = array_helperz.sortAsc(sampleInput, "created", "date")
console.log("🚀 ~ file: playground.js ~ line 11 ~ output", output)

sortDesc(array, key) ⇒ array

Kind: global function
Returns: array - of objects
Date: 2022-02-17
Author: zen-out

ParamTypeDescription
arrayarray
keystringof object

Example

const array_helperz = require("array_helperz")
let sampleInput = [{
seconds: 500,
created: new Date(2020, 12, 1),
status: "to do",
problem: "we actually solve our problems best by looking at how other people solved them - segment each feature",
}, { seconds: 1000, created: new Date(2019, 12, 1), status: "doing", problem: "we need to focus on one thing at a time" }]
let output = array_helperz.sortDesc(sampleInput, "seconds", "integer")
console.log("🚀 ~ file: playground.js ~ line 11 ~ output", output)

contains(array, property, value) ⇒ array

Kind: global function
Returns: array - of objects
Date: 2022-02-17
Author: zen-out

ParamType
arrayarray
propertystring
valuestring

Example

const array_helperz = require("array_helperz")
let sampleInput = [{
seconds: 500,
created: new Date(2020, 12, 1),
status: "to do",
problem: "we actually solve our problems best by looking at how other people solved them - segment each feature",
}, { seconds: 1000, created: new Date(2019, 12, 1), status: "doing", problem: "we need to focus on one thing at a time" }]
let output = array_helperz.contains(sampleInput, "seconds", 500)

doesNotContain(array, property, value) ⇒ array

Kind: global function
Returns: array - of objects
Date: 2022-02-17
Author: zen-out

ParamType
arrayarray
propertystring
valuestring

Example

const array_helperz = require("array_helperz")
let sampleInput = [{
seconds: 500,
created: new Date(2020, 12, 1),
status: "to do",
problem: "we actually solve our problems best by looking at how other people solved them - segment each feature",
}, { seconds: 1000, created: new Date(2019, 12, 1), status: "doing", problem: "we need to focus on one thing at a time" }]
let output = array_helperz.doesNotContain(sampleInput, "seconds", 500)

group(data, groupByCondition) ⇒ array

Kind: global function
Date: 2022-03-06
Author: zen-out

ParamType
dataarray
groupByConditionstring

getUnique(arr, key) ⇒ any

Kind: global function
Date: 2022-03-18
Author: zen-out

ParamType
arrany
keyany

Example

let testArr = [{
        id: 1,
        hello: "whatsup"
    },
    {
        id: 2,
        hello: "whatsup"
    },
    {
        id: 1,
        hello: "whatsup"
    },
]

export function testUnique() {
    let newArr = getUnique(testArr, "id")
    console.log(newArr)
}

intersection(nums1, nums2) ⇒ any

Kind: global function
Date: 2022-03-22
Author: zen-out

ParamType
nums1any
nums2any

Example

let expected_keys =["hello"]
    let actual_keys =["hello", "whatsup"]
    let merged = intersection(expected_keys, actual_keys)
    merged will be ["hello"]

mergeByKeys(arr, object) ⇒ any

Kind: global function
Date: 2022-03-15
Author: zen-out

ParamTypeDescription
arrany
objectobject{data: arr, key: "problem_id"} -> reference to the joining to arr

Example

let arr1Child2 = { data: arr, key: "id" }
let arr22 = {
    data: arr2,
    key: "id",
}
let merged2 = array_helperz.mergeByKeys(arr1Child2, arr22)

makeChildOfAnother({data:, {data:) ⇒ array

Kind: global function
Date: 2022-03-15
Author: zen-out

ParamTypeDescription
{data:objectarr, key: "id" }
{data:objectarr2, key: "id" }

Example

let arrOne = [{
            title: 'I want to be free. Free to live,  and to find my own way,  to love,  or to be alone,  but at least it is my choice,  and I am so tired of not having choices,  so scared of the years rushing past beneath my feet. I do not want to die as I’ve lived,  which is no life at all.',
            status: 'to do',
            id: 1
        },
        {
            title: 'Because we loved each other too much and found each other too interesting. And I love that about humanity,  and in fact it’s the very reason I root for us to survive—because we are so stupid about each other.',
            status: 'doing',
            id: 2
        },
        {
            title: 'But a life without art,  without wonder,  without beautiful things—she would go mad. She has gone mad. What she needs are stories. Stories are a way to preserve one’s self. To be remembered. And to forget.',
            status: 'doing',
            id: 3
        }
    ]
    let arrTwo = [
        { name: 'Whatever', status: 'doing', problem_id: 2, id: 1 },
        { name: 'is', status: 'doing', problem_id: 2, id: 2 },
        { name: 'people', status: 'to do', problem_id: 2, id: 3 }
    ]
    let arr1 = { data: arrOne, key: "id" }
    let arr2 = { data: arrTwo, key: "problem_id" }
    let result = makeChildOfAnother(arr1, arr2)
    console.log(result)
output
[
  {
    title: 'I want to be free. Free to live,  and to find my own way,  to love,  or to be alone,  but at least it is my choice,  and I am so tired of not having choices,  so scared of the years rushing past beneath my feet. I do not want to die as I’ve lived,  which is no life at all.',
    status: 'to do',
    id: 1,
    child: []
  },
  {
    title: 'Because we loved each other too much and found each other too interesting. And I love that about humanity,  and in fact it’s the very reason I root for us to survive—because we are so stupid about each other.',
    status: 'doing',
    id: 2,
    child: [ [Object], [Object], [Object] ]
  },
  {
    title: 'But a life without art,  without wonder,  without beautiful things—she would go mad. She has gone mad. What she needs are stories. Stories are a way to preserve one’s self. To be remembered. And to forget.',
    status: 'doing',
    id: 3,
    child: []
  }
]

getOneMakeChildOfAnother({data:, {data:) ⇒ array

Kind: global function
Date: 2022-03-15
Author: zen-out

ParamTypeDescription
{data:objectarr, key: "id", value: 2 }
{data:objectarr2, key: "id", value: 3 }

Example

let arrOne = [{
            title: 'I want to be free. Free to live,  and to find my own way,  to love,  or to be alone,  but at least it is my choice,  and I am so tired of not having choices,  so scared of the years rushing past beneath my feet. I do not want to die as I’ve lived,  which is no life at all.',
            status: 'to do',
            id: 1
        },
        {
            title: 'Because we loved each other too much and found each other too interesting. And I love that about humanity,  and in fact it’s the very reason I root for us to survive—because we are so stupid about each other.',
            status: 'doing',
            id: 2
        },
        {
            title: 'But a life without art,  without wonder,  without beautiful things—she would go mad. She has gone mad. What she needs are stories. Stories are a way to preserve one’s self. To be remembered. And to forget.',
            status: 'doing',
            id: 3
        }
    ]
    let arrTwo = [
        { name: 'Whatever', status: 'doing', problem_id: 2, id: 1 },
        { name: 'is', status: 'doing', problem_id: 2, id: 2 },
        { name: 'people', status: 'to do', problem_id: 2, id: 3 }
    ]

    let arr1GetOne = { data: arrOne, key: "id", value: 2 }
    let arr2GetOne = { data: arrTwo, key: "problem_id", value: 2 }
    let result2 = getOneMakeChildOfAnother(arr1GetOne, arr2GetOne)
    console.log(result2)
output
[
  {
    title: 'Because we loved each other too much and found each other too interesting. And I love that about humanity,  and in fact it’s the very reason I root for us to survive—because we are so stupid about each other.',
    status: 'doing',
    id: 2,
    child: [ [Object], [Object], [Object] ]
  }
]

removeByFunction(arr, func) ⇒ array

Kind: global function
Date: 2022-03-22
Author: zen-out

ParamType
arrarray
funcfunction

Example

let types = [{
    "user_id": 4,
    "task_id": 1,
    "tag": "quote",
    "snippet": "be more selfish with your time. this is your life. reach your own goals. be more confident in yourself, you got this. i want cyrus on my team",
    "hourglass_id": 4,
    "id": 1
}, {
    "user_id": 4,
    "task_id": 1,
    "tag": "quote",
    "snippet": "be more selfish with your time. this is your life. reach your own goals. be more confident in yourself, you got this. i want cyrus on my team",
    "hourglass_id": 4,
    "id": 2
}]

function removeObj(x) {
    if (x.id === 2) {
        return true;
    }
}
array_helperz.removeByFunction(arr, func)

replaceKey(arr, originalKey, replaceKey) ⇒ array

replaceKey(arr, originalKey, replaceKey)

Kind: global function
Date: 2022-03-23
Author: zen-out

ParamType
arrarray
originalKeystring
replaceKeystring
1.2.0

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.3.10

2 years ago

1.3.13

2 years ago

1.0.22

2 years ago

1.3.14

2 years ago

1.0.21

2 years ago

1.3.11

2 years ago

1.0.20

2 years ago

1.3.12

2 years ago

1.3.17

2 years ago

1.3.18

2 years ago

1.0.25

2 years ago

1.3.15

2 years ago

1.0.24

2 years ago

1.3.16

2 years ago

1.0.23

2 years ago

1.3.19

2 years ago

1.3.20

2 years ago

1.3.21

2 years ago

1.3.9

2 years ago

1.3.8

2 years ago

1.3.24

2 years ago

1.3.25

2 years ago

1.3.28

2 years ago

1.3.29

2 years ago

1.3.26

2 years ago

1.3.27

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.3.7

2 years ago

1.1.9

2 years ago

1.3.6

2 years ago

1.1.8

2 years ago

1.3.5

2 years ago

1.1.7

2 years ago

1.3.4

2 years ago

1.1.6

2 years ago

1.3.3

2 years ago

1.1.5

2 years ago

1.3.2

2 years ago

1.1.4

2 years ago

1.3.1

2 years ago

1.1.3

2 years ago

1.3.0

2 years ago

1.3.30

2 years ago

1.1.12

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.15

2 years ago

1.1.14

2 years ago

1.1.13

2 years ago

1.1.18

2 years ago

1.1.17

2 years ago

1.1.23

2 years ago

1.1.22

2 years ago

1.1.21

2 years ago

1.1.20

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago