{"id":20662414,"url":"https://github.com/evanzhoudev/utilkit","last_synced_at":"2025-06-29T08:32:36.082Z","repository":{"id":104237818,"uuid":"599892050","full_name":"EvanZhouDev/UtilKit","owner":"EvanZhouDev","description":null,"archived":false,"fork":false,"pushed_at":"2023-02-15T01:38:46.000Z","size":340,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-10T05:55:17.455Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/EvanZhouDev.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":"2023-02-10T05:22:14.000Z","updated_at":"2023-04-30T05:33:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"80255a89-ca6a-492a-84c0-f187b7a582f2","html_url":"https://github.com/EvanZhouDev/UtilKit","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/EvanZhouDev/UtilKit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvanZhouDev%2FUtilKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvanZhouDev%2FUtilKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvanZhouDev%2FUtilKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvanZhouDev%2FUtilKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EvanZhouDev","download_url":"https://codeload.github.com/EvanZhouDev/UtilKit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvanZhouDev%2FUtilKit/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262564481,"owners_count":23329508,"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":[],"created_at":"2024-11-16T19:14:04.935Z","updated_at":"2025-06-29T08:32:36.035Z","avatar_url":"https://github.com/EvanZhouDev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A light toolkit library to do useful things.\nUtilKit is designed to make it simple to do things that JS makes complicated.\nEach function is chosen for a reason and designed specifically to make JS more pleasing to use.\n\n\n\n\u003e **Warning**\n\u003e This module is still in development, probably not a good idea to use it in production!\n\n## Installation:\nIt's pretty simple!\n```bash\nnpm install utilkit-js\n```\n\n## Installation/Usage\nUtilKit usage is slightly different than most `node` modules.\n\n\u003e **Warning**\n\u003e This module doesn't work with the `Bun` runtime as of now.\n\nUtilKit is available in many flavors of JS!\n\nThere are two ways of usage\n1. Inject functions directly into `global` (*Slightly* dangerous; probably safe)\n2. Use UtilKit normally under a namespace\n\nChoose your installation here:\n* [CJS](#cjs)\n\t* [Expose Functions to Global](#expose-functions-to-global-for-cjs)\n\t* [Use Under Namespace](#use-under-namespace-for-cjs)\n* [ESM](#esm)\n\t* [Expose Functions to Global](#expose-functions-to-global-for-esm)\n\t* [Use Under Namespace](#use-under-namespace-for-esm)\n* [Thoughts/Safety about injecting to global and how it works](#thoughts-and-safety-of-injecting-to-global)\n\n### CJS\n#### Expose Functions to Global for CJS\nTo use, put this at the top of your JS code:\n```javascript\nrequire(\"utilkit-js\")(global);\n```\n\nNow, you can use all of the functions as if they were native functions:\n```javascript\nconsole.log(len(\"Hello, world!\")) // len() is a utilkit function\n```\n\n#### Use Under Namespace for CJS\nTo use, put this at the top of your JS code:\n```javascript\nlet utk = require(\"utilkit-js\")();\n```\n\nNow, you can use all of the functions like a normal `node` module\n```javascript\nconsole.log(utk.len(\"Hello, world!\"))\n```\n\n### ESM\n#### Expose Functions to Global for ESM\nTo use, put this at the top of your JS code:\n```javascript\nimport utilkit from \"utilkit-js\"\nutilkit(global);\n```\n\nNow, you can use all of the functions as if they were native functions:\n```javascript\nconsole.log(len(\"Hello, world!\")) // len() is a utilkit function\n```\n\n#### Use Under Namespace for ESM\nTo use, put this at the top of your JS code:\n```javascript\nimport utilkit from \"utilkit-js\"\nlet utk = utilkit();\n```\n\nNow, you can use all of the functions like a normal `node` module\n```javascript\nconsole.log(utk.len(\"Hello, world!\"))\n```\n\n### Thoughts and Safety of Injecting to Global\n(+ How it works!)\n\n\u003e TL;DR: Inject to global most of the time, but if you have a specific reason not to, then don't.\n\n#### Why use it? (And why not?)\nThe pro side of this is the fact that your code will look cleaner, and be shorter.\nThe con side of this is that it may interfere with other modules and `node` itself.\nI'd say that most of the time injecting to global is fine, but in that small percentage of time, UtilKit has you covered with the Use Under Namespace feature.\n\n#### Here's how it works\nInternally, when you are requiring/importing, it gives this callback for the `len()` function:\n(Assume that `len()` has already been implemented in the UtilKit module code somewhere, and that it takes in one `obj` parameter)\n```javascript\nmodule.exports = function (target) {\n    target.len = (obj) =\u003e len(obj)\n}\n```\nNow, in the client's code, this is written:\n```javascript\nrequire(\"utilkit-js\")(global)\n```\nIt simply puts the functions into global so you can use them as if they were just your average function!\n\nThis allows the UtilKit functions to feel native. All it takes is one line of code!\n\nSo... is injecting to global safe?\nShort Answer: It probably should be, but to be safe, put UtilKit last in your dependency list if you're using this method!\n\u003cdetails\u003e\n  \u003csummary\u003eHere's why...\u003c/summary\u003e  \nJavascript itself has a grand total of 6 top-level functions, and `node` does add a few more.\n\nAll other functions, however, are bundled under certain objects, like `console.log()` and others. Because theses methods are constantly modified and added in new releases, it is one reason why extending prototypes can be dangerous. However, the limited amount of top-level functions means that they're less likely to be added to. \n\t\nThus, we can pretty much assume that these functions would rarely be added to or changed.\nBecause of this, UtilKit's implementation of injecting native functions **should** be safe for most of the time. *However, I do not guarentee it will be for all the time to come.*\n\nAnother thing that may happen is that functions implemented in UtilKit are used by some of your other dependencies. Because of the way `node` is structured and the way that UtilKit is implemented, your using the same function name as UtilKit in another dependency will cause conflicts. However, if you put it last, your code should be perfectly fine.\n\nI do realize that this isn't necessarily an excuse, as all other modules can say \"Put my module last!\" and it would only work for theirs. However, because I do not know necessarily of other modules that have this implementation, it should be fine for now.\n  \n\u003c/details\u003e\n\n\n# Functions\nAll the goodies in UtilKit bundle!\n\n### Length\nThe built-in length function has some problems, and, surprisingly, most major programming languages don't fix it.\nThe `len()` function is implemented so that the characters you see in a string is the length you get.\nThere are also changes for objects!\n\n#### Usage:\nThe usage is pretty simple:\n```javascript\nconst chalk = require(\"chalk\");\n\n// String w/ Emojis and Escape Codes\nlen(chalk.blue(\"👋 Hi!\")) // Returns 5 correctly\nchalk.blue(\"👋 Hi!\").length // Returns 16 incorrectly\n\n// Numbers\nlet x = 123; // Also works with BigInts and floats!\nlen(123) // Returns 3\nx.length // Undefined\n\n// Objects\nlet obj = {\n    a: 1,\n    b: 2,\n    c: 3\n}\nlen(obj) // Returns 3 (number of keys in the object)\nobj.length // Undefined\n\n// Arrays\nlen([1,2,3]) === [1,2,3].length // Still works the same!\n```\n\n### Trigonometric Functions\nThe built-in trig function are pretty simple; they take in the angle in radian and gives you the corresponding value. However, upon plugging in some common values in terms of `Math.PI`, you will notice a problem: there are some floating point errors.\nThe UtilKit functions fix this.\n\n#### Usage:\nMake sure that the pi approximation you use is `Math.PI` specifically. Other approximations may not work.\n```javascript\nlet PI = Math.PI\nsin(PI) // 0\nMath.sin(PI) // 1.2246467991473532e-16 (VERY close to 0, but not 0?)\n\ncos(PI/2) // 1\nMath.cos(PI/2) // 6.123233995736766e-17 (Similar problem)\n\ntan(PI/2) // Error\nMath.tan(PI/2) // 16331239353195370 (There is no tangent of 90°)\n```\nMany floating point errors have been fixed, including tangent of 90° etc.\n\n### `Reverse` and `Reversed`\nReversing anything that isn't a array in JS is a pain.\nFor an array, you can do `Array.reverse()`. For a string, you have to do `String.split(\"\").reverse().join(\"\")`. UtilKit fixes this.\n\n#### Usage:\nReverse and reversed do essentially the same thing for everything that isn't an array (because arrays pass by reference and everything else passes by value).\n`reverse` mutates the array, and `reversed` doesn't.\n```javascript\nlet myArr = [1,2,3]\nreverse(myArr) // [3,2,1]\nmyArr // [3,2,1]\n\nlet myArr2 = [1,2,3]\nreversed(myArr) // [3,2,1]\nmyArr // [1,2,3]\n\nreverse(\"hello\") // \"olleh\"\nreverse(123.4) // 4.321\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevanzhoudev%2Futilkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevanzhoudev%2Futilkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevanzhoudev%2Futilkit/lists"}