{"id":32120617,"url":"https://github.com/ac5tin/usefuljs","last_synced_at":"2025-10-20T19:59:52.973Z","repository":{"id":57388579,"uuid":"168663534","full_name":"ac5tin/usefuljs","owner":"ac5tin","description":"List of js functions that might be useful","archived":false,"fork":false,"pushed_at":"2021-05-10T11:31:03.000Z","size":342,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-20T19:59:37.739Z","etag":null,"topics":["javascript","useful","useful-scripts"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/ac5tin.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}},"created_at":"2019-02-01T08:06:16.000Z","updated_at":"2023-04-11T15:25:07.000Z","dependencies_parsed_at":"2022-09-05T07:11:22.568Z","dependency_job_id":null,"html_url":"https://github.com/ac5tin/usefuljs","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ac5tin/usefuljs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ac5tin%2Fusefuljs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ac5tin%2Fusefuljs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ac5tin%2Fusefuljs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ac5tin%2Fusefuljs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ac5tin","download_url":"https://codeload.github.com/ac5tin/usefuljs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ac5tin%2Fusefuljs/sbom","scorecard":{"id":162111,"data":{"date":"2025-08-11","repo":{"name":"github.com/ac5tin/usefuljs","commit":"58089c2097b9e97ab15e5f3e130fedaf322f023d"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.6,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-16T13:46:33.422Z","repository_id":57388579,"created_at":"2025-08-16T13:46:33.422Z","updated_at":"2025-08-16T13:46:33.422Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280151543,"owners_count":26281249,"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","status":"online","status_checked_at":"2025-10-20T02:00:06.978Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["javascript","useful","useful-scripts"],"created_at":"2025-10-20T19:59:51.848Z","updated_at":"2025-10-20T19:59:52.965Z","avatar_url":"https://github.com/ac5tin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Useful JS functions\n### List of functions that might be useful\n### Some of them are copied from others\n\n### install\n```\nyarn add usefuljs --use-pnp \n```\n\n### import\n```javascript\nimport { ajax , arr_last } from 'usefuljs' // react\n\nimport { ajax } from \"usefuljs/useful.modern.js\" // svelte\n\n\n// install node fetch first on nodejs\nglobal.fetch = require(\"node-fetch\") // if using node.js\nconst { ajax } = require(\"usefuljs\") // node.js\n```\n\n\n## ajax\nPerform ajax request using the native fetch API\n### parameters\n```\nmethod : default = GET\nurl\ndata : (if using post or put method)\nsignal : AbortController().signal (optional)\nheaders : additional headers in Object format (optional)\ncors : enable or disabled cors (boolean) (optional)\nformdata : form data object (optional),if set to true, data object is ignored\nfetcher : custom fetch (optional)\njson : parse response as json (optional), by default set to true\njsonbody : auto json stringify body before sending (optional), by default set to true\n```\n### get request\n```javascript\najax({url:'/api/users/list'}).then(res =\u003e console.log(res));\n```\n### post request\n```javascript\najax({\n        method:'POST',\n        url:'/api/users/create',\n        data:{ username:'austin',password:'abcdef'}\n    }).then(res =\u003e console.log(res));\n```\n\n### additional headers\n``` javascript\najax({\n    method:'post',\n    url:'/api/verify',\n    heades: {token: \"abc123\"},\n    data: { username: \"testuser\"}\n})\n```\n\n### abort controller signal\n```javascript\nconst controller = new AbortController();\nconst signal = this.controller.signal;\najax({url:'/api/test',signal});\n\n// -- when u want to abort the ajax requet --\ncontroller.abort();\n```\n\n\n### sapper preload fetch\n```javascript\najax({fetcher: this.fetch})\n```\n\n\n## ajaxhr\nSame as ajax but uses xhr API instead of fetch API + doesn't have the signal parameter\n\n\n\n## arr_last\nReturns last element from an array\n```javascript\narr_last(array)\n```\n\n\n## arr_rm\nRemoves an element from an array (by value)\n```javascript\narr_rm(arr,elem)\n```\n### optional 3rd parameter (mutate)\nBy default mutate is set to true\nIf set to false, array will be returned instead of mutating the original array\n```javascript\narr_rm(arr,elem,false)\n```\n\n\n\n## arr_rmi\nRemoves an element from an array (by index)\n```javascript\narr_rm(arr,index)\n```\n### optional 3rd parameter (mutate)\nBy default mutate is set to true\nIf set to false, array will be returned instead of mutating the original array\n```javascript\narr_rm(arr,index,false)\n```\n\n\n## array_push\nSimilar to the php array_push method, it adds new element to array (if value doesn't exist in array)\n```javascript\narray_push(arr,\"foo\")\n```\n\n\n## formatBytes\n### Parameters\n```\nbytes (int)\ndecimal places (int)\n```\nBytes to human readable string\n```javascript\nformatBytes(1024)\n// returns \"1 KB\"\nformatBytes(3241234,3)\n// returns \"3.091 MB\"\n```\n\n\n\n## diffObjs\nDelta/Difference between 2 objects\n```javascript\nlet a = {x: 123,y:456,c:999}\nlet b = {x: 123,y:222,c:888}\ndiffObjs(a,b)\n// returns [{y:456,c:999},{y:222,c:888}]\n```\n\n\n## prepend\nAdd an element to the beginning of an array\n```javascript\nprepend(\"foo\",array)\n```\n\n\n## arr_dedup\nDeduplicates array \n```javascript\narr_dedup([2,3,4,4,2,5,5]);\n// returns [2, 3, 4, 5]\n```\n\n\n## replaceAll\nReplaces all matches in a string\n```javascript\nreplaceAll(string1,'find','replace')\n```\n\n\n## getDistFromBottom\nGet distance from bottom of the page\n```javascript\ngetDistFromBottom()\n```\n\n\n## obj2arr\nObject into array\n```javascript\nconst a = {a:\"123\",b:\"456\",c:\"789\"};\nobj2arr(a); // \u003c-- this returns : [\"123\",\"456\",\"789\"]\n```\n\n\n## isInt\nIs the value an integer (parses string too)\n```javascript\nisInt(\"1\") // true\nisInt(1)  // true\nisInt(\"1cd\") // false\n```\n\n\n## isNum\nDoes the string contain numbers only\n```javascript\nisNum(\"222\") // true\nisNum(\"222/22\")  //false\n```\n\n## arr_chunk\nsplit array into chunks of smaller arrays\n```javascript\narr_chunk([1,2,3,4,5,6],2); // \u003c-- returns 3 arrays : [1,2] , [3,4] , [5,6]\narr_chunk([1,2,3,4,5,6],3); // \u003c-- returns 2 arrays: [1,2,3] , [4,5,6]\n```\n\n## asyncForEach\nAsync version of foreach\n```javascript\nawait asyncForEach(arr, x =\u003e console.log(x))\n```\n\n\n## obj_sort\nsort array of object by object property value\n* Supply this as the parameter of the array.sort() function *\n\n### parameters\n```\nname : key name\nlength : sort by length   boolean (default = false)\nreverse: boolean (default = false)\n```\n\n```javascript\nconst a = [{number:1}, {number:2}];\na.sort(obj_sort('number',false,true)); // \u003c- returns [{number:2}, {number:1}]\n```\n\n\n## uuidv4\ngenerates uuidv4\n```javascript\nuuidv4();\n```\n\n\n## unique_id\ngenerates a uid\n```javascript\nunique_id()\n```\n\n\n## shortuid\ngenerates a short uid\n```javascript\nshortuid()\n```\n\n\n## matching_array\nFind all matching values in 2 arrays\n```javascript\nconst a = [1,2,3];\nconst b = [4,5,6];\nconst c = [1,2,3];\n\nmatching_array(a,b); // returns []\nmatching_array(a,c); // returns [1,2,3]\n```\n\n\n## obj_prop_rename\nChange property name of an object\n```javascript\nobj_prop_rename(obj,'old','new')\n```\n\n\n## obj_filter\nFilters an object\n```javascript\nobj_filter(obj, x =\u003e x === 'abc');\n```\n\n## obj_key_filter\nFilters an object by key name\n```javascript\nobj_key_filter(obj, x =\u003e x === 'name');\n```\n\n\n## ucfirst\nUpper case first letter\n```javascript\nucfirst('foobar'); // returns Foobar\n```\n\n## sleep\nPauses\n```javascript\nsleep(1000); // \u003c-- sleep for 1000 miliseconds\n```\n\n\n## f_arr\nFilter out empty/NaN elements in array\n```javascript\nf_arr(['a',NaN,22,null]); // returns [\"a\", 22]\n```\n\n\n## f_obj\nFilter out null / undefined in object\n```javascript\nk = {x:243,y:323421,uuu:null}\nf_obj(k) // returns  {x: 243, y: 323421}\n```\n\n\n\n## escape_dq\nEscape Double Quotes\n```javascript\nconst newstring = escape_dq(oldstring);\n```\n\n\n\n## escape_HTML\nEscape HTML\n```javascript\nconst escaped = escape_HTML(html);\n```\n\n\n## colourgen\nGenerate random colour hexcode\n```javascript\nconst colour = colourgen();\n```\n\n\n## intgen\nGenerate random number integer from range\n```javascript\nintgen(1,5); // returns a random number from 1 to 5\n```\n\n\n## arrobj2objarr\nConverts array of object to object of arrays\n```javascript\narrobj2objarr([{a:1,b:2,c:3},{a:5,b:2,c:9}]); // { a:[1,5] , b:[2,2] , c:[3,9] }\n```\n\n## arrobj2obj\nConverts an array of object to a big object (user specify the column to be used as key)\n```javascript\narrobj2obj([{a:1,b:2,c:3},{a:5,b:2,c:9}],\"a\"); // { 1: {a:1,b:2,c:3}, 5: {a:5,b:2,c:9} }\n```\n\n\n## hexCode\nConvert string to hex code\n```javascript\nhexCode(\"康健雜誌\");\n// \"5eb7506596dc8a8c\"\n```\n\n\n## toCSV\nConvert Array JSON to csv\n```javascript\ntoCSV(arrJSON)\n```\n\n## crc32\nCrc32 hashes a value\n```javascript\ncrc32(\"abc\")\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fac5tin%2Fusefuljs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fac5tin%2Fusefuljs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fac5tin%2Fusefuljs/lists"}