{"id":19389241,"url":"https://github.com/polioan/global-js","last_synced_at":"2025-02-24T20:04:53.906Z","repository":{"id":183319307,"uuid":"669946903","full_name":"polioan/global-js","owner":"polioan","description":"get, set global values in any js env","archived":false,"fork":false,"pushed_at":"2023-08-05T05:45:24.000Z","size":62,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-07T09:29:10.280Z","etag":null,"topics":["global","globalthis","pollute","pollution","testing","window"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@polioan/global-js","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polioan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":"polioan","custom":["https://boosty.to/polioan"]}},"created_at":"2023-07-24T00:09:20.000Z","updated_at":"2023-08-04T02:02:31.000Z","dependencies_parsed_at":"2023-07-24T00:11:53.385Z","dependency_job_id":"cad570fa-7dee-4e11-9bc3-60b214878f23","html_url":"https://github.com/polioan/global-js","commit_stats":{"total_commits":10,"total_committers":2,"mean_commits":5.0,"dds":0.09999999999999998,"last_synced_commit":"95ce5536294c3bee81f2d55fa014716d1490540c"},"previous_names":["polioan/pollute-global","polioan/global-js"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polioan%2Fglobal-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polioan%2Fglobal-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polioan%2Fglobal-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polioan%2Fglobal-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polioan","download_url":"https://codeload.github.com/polioan/global-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240549430,"owners_count":19819137,"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":["global","globalthis","pollute","pollution","testing","window"],"created_at":"2024-11-10T10:15:41.870Z","updated_at":"2025-02-24T20:04:53.879Z","avatar_url":"https://github.com/polioan.png","language":"JavaScript","funding_links":["https://github.com/sponsors/polioan","https://boosty.to/polioan"],"categories":[],"sub_categories":[],"readme":"# global-js\n[![version](https://img.shields.io/npm/v/@polioan/global-js.svg)](https://www.npmjs.com/package/@polioan/global-js)\n[![license](https://img.shields.io/github/license/polioan/global-js)](https://opensource.org/licenses/MIT)\n\nget, set global values in any js env\n\n## Use case\n\n### Test\n\n```ts\nimport { setGlobal, getEnv } from '@polioan/global-js'\n\nfunction toTest() {\n  return 333\n}\n\nif (getEnv('NODE_ENV') === 'test') {\n  setGlobal('toTest', toTest)\n}\n```\n\n### Global cache (useful for hot reload)\n\n```ts\nimport { getEnv, getGlobal, setGlobal } from '@polioan/global-js'\nimport { PrismaClient } from '@prisma/client'\n\nexport const prisma: PrismaClient = getGlobal('prisma') ?? new PrismaClient({})\n\nif (getEnv('NODE_ENV') !== 'production') {\n  setGlobal('prisma', prisma)\n}\n```\n\n### Libs for browser\n\n```ts\nimport { setGlobal } from '@polioan/global-js'\n\nclass Myjquery {}\n\nsetGlobal('$', new Myjquery())\n```\n\n### Polyfills\n\n```ts\nimport { setGlobal } from '@polioan/global-js'\n\nif (typeof structuredClone === 'undefined') {\n  setGlobal('structuredClone', value =\u003e JSON.parse(JSON.stringify(value)))\n}\n```\n\n### Creating global libraries\n\n```ts\nimport { setGlobal } from '@polioan/global-js'\n\ndeclare global {\n  var calculate: (a: number, b: number) =\u003e number\n}\n\nsetGlobal('calculate', (a: number, b: number) =\u003e a + b)\n\nconst test = calculate(2, 3) // will work\n```\n\n## Install\n\n### npm\n\n```shell\nnpm i @polioan/global-js\n```\n\n### yarn\n\n```shell\nyarn add @polioan/global-js\n```\n\n### CDN\n\n```html\n\u003cscript src=\"https://unpkg.com/@polioan/global-js@2.0.1/dist/index.global.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  setGlobal('some', 'test')\n\u003c/script\u003e\n```\n\n### Deno\n\n```ts\nimport { setGlobal } from 'https://deno.land/x/global_js@2.0.1/src/index.ts'\nsetGlobal('some', 'test')\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolioan%2Fglobal-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolioan%2Fglobal-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolioan%2Fglobal-js/lists"}