{"id":16317417,"url":"https://github.com/samhirtarif/helper-methods-js","last_synced_at":"2025-03-08T19:30:55.541Z","repository":{"id":65281285,"uuid":"574049512","full_name":"samhirtarif/helper-methods-js","owner":"samhirtarif","description":"A repo that contains helper methods for common and not-so-common use cases","archived":false,"fork":false,"pushed_at":"2023-04-29T09:12:20.000Z","size":54,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-04T18:43:29.012Z","etag":null,"topics":["async","dedupe","deduplication","deepcopy","indexesof","isasync"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samhirtarif.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-04T09:09:10.000Z","updated_at":"2023-08-08T10:59:44.000Z","dependencies_parsed_at":"2024-10-22T19:12:18.312Z","dependency_job_id":null,"html_url":"https://github.com/samhirtarif/helper-methods-js","commit_stats":{"total_commits":10,"total_committers":2,"mean_commits":5.0,"dds":0.5,"last_synced_commit":"c85a56912875ffa332b48c47af670454af0a8587"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samhirtarif%2Fhelper-methods-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samhirtarif%2Fhelper-methods-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samhirtarif%2Fhelper-methods-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samhirtarif%2Fhelper-methods-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samhirtarif","download_url":"https://codeload.github.com/samhirtarif/helper-methods-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242600823,"owners_count":20156239,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","dedupe","deduplication","deepcopy","indexesof","isasync"],"created_at":"2024-10-10T22:08:23.141Z","updated_at":"2025-03-08T19:30:55.225Z","avatar_url":"https://github.com/samhirtarif.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **Helper methods**\nA package that provides helper methods for common and not-so-common use cases\n\n## **Contributions are welcome!**\n\n## Installation\n```sh\nnpm install helper-methods-js\n```\n\n## Methods\n- [**`deepcopy`**](#deepcopy)\n- [**`dedupe`**](#dedupe)\n- [**`indexesOf`**](#indexesOf)\n- [**`isAsyncFunction`**](#isAsyncFunction)\n- [**`trimDelimeters`**](#trimDelimeters)\n\n\u003cbr /\u003e\n\n---\n\u003cbr /\u003e\n\n### **`deepcopy`**\n\nThis method creates a deep copy of the provided object to the given depth. Beyond that depth, the object is shallow copied\n\n| Parameter     | Description     | Default Value |\n| :------------ |:---------------| :-------------|\n| `obj`           | The object to be copied                | N/A             |\n| `max_depth` (optional)     | Maximum depth to which the function would copy the object. Beyond this depth shallow copies would be created. A value of `0` implies that the entire object should be deep copied.    | `0`             |\n\n\u003cbr /\u003e\n\n#### Sample usage\n```js\nimport { deepcopy } from 'helper-methods-js'\n\ndeepcopy({ name: 'bob' }, 0);\n```\n---\n\u003cbr /\u003e\n\n### **`dedupe`**\n\nThis method provides implementation to remove duplicates from an array.\n\n| Parameter     | Description     | Default Value |\n| :------------ |:---------------| :-------------|\n| `array`           | The array that needs duplicates removed                | N/A             |\n| `condition` (optional)    | A function that returns either `true` or `false`. This condition is executed for each array value and the values for which it returns `true` are removed. In case this condition is not provided, elements are removed on equality comparison.    | N/A             |\n\n\u003cbr /\u003e\n\n#### Sample usage\n```js\nimport { dedupe } from 'helper-methods-js'\n\nconst cars = [\n  { name: \"audi\", owner: \"a\" },\n  { name: \"bmw\", owner: \"x\" },\n  { name: \"audi\", owner: \"b\" },\n  { name: \"bmw\", owner: \"b\" },\n];\n\ndedupe(cars, (e, i) =\u003e e.owner === i.owner)\n```\n---\n\u003cbr /\u003e\n\n### **`indexesOf`**\n\nThis method provides implementation to return indexes of all elements that match a specific condition\n\n| Parameter     | Description     | Default Value |\n| :------------ |:---------------| :-------------|\n| `array`           | The array that needs duplicates removed                | N/A             |\n| `condition`    | It can either be a value or a functions. In case of a function, the function should return `true` or `false`. This condition is executed for each array value and the values for which it returns `true` are added to the list of indexes returned. In case this condition is not provided, elements are removed on equality comparison.    | N/A             |\n\n\u003cbr /\u003e\n\n#### Sample usage\n```js\nimport { indexesOf } from 'helper-methods-js'\n\nconst objs = [\n  { age: 21, nationality: \"a\" },\n  { age: 24, nationality: \"a\" },\n  { age: 21, nationality: \"b\" },\n  { age: 32, nationality: \"c\" },\n  { age: 42, nationality: \"b\" },\n  { age: 52, nationality: \"c\" },\n  { age: 21, nationality: \"a\" },\n]\n\nconst indexes = indexesOf(objs, (i: any) =\u003e i.nationality === \"b\")\n```\n---\n\u003cbr /\u003e\n\n### **`isAsyncFunction`**\n\nThis method returns whether a function is async or not.\n\n| Parameter     | Description     | Default Value |\n| :------------ |:---------------| :-------------|\n| `fn`    | The function for which it needs to be determined whether it is async or not.    | N/A             |\n\n\u003cbr /\u003e\n\n#### Sample usage\n```js\nimport { isAsyncFunction } from 'helper-methods-js'\n\nconst testFn = async () =\u003e {};\nisAsyncFunction(testFn) // returns true\n\nconst testFnSync = () =\u003e {};\nisAsyncFunction(testFnSync) // returns false\n```\n---\n\u003cbr /\u003e\n\n### **`trimDelimeters`**\n\nThis method takes a string and removes the provided delimeters from the start and end of the string.\n\n| Parameter     | Description     | Default Value |\n| :------------ |:---------------| :-------------|\n| `str`           | The string to be trimed                | N/A             |\n| `delimeters`    | A list of delimeters to be trimned from the start and/or end of the string provided.    | N/A             |\n| `options` (optional)    | An object with values `trimStart` and `trimEnd` that represent if the string should only be trimmed from start and/or end respectively.     | `{ trimStart: true, trimEnd: true }`            |\n\n\u003cbr /\u003e\n\n#### Sample usage\n```js\nimport { trimDelimeters } from 'helper-methods-js'\n\ntrimDelimeters(\"\u0026\u0026*ABC*(\u0026\", [\"\u0026\", \"*\"]) // outputs \"ABC*(\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamhirtarif%2Fhelper-methods-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamhirtarif%2Fhelper-methods-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamhirtarif%2Fhelper-methods-js/lists"}