{"id":21082248,"url":"https://github.com/olsonpm/universal","last_synced_at":"2025-03-14T04:43:07.164Z","repository":{"id":80606834,"uuid":"76158322","full_name":"olsonpm/universal","owner":"olsonpm","description":null,"archived":false,"fork":false,"pushed_at":"2016-12-15T05:19:16.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-20T23:45:33.305Z","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/olsonpm.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":"2016-12-11T06:29:45.000Z","updated_at":"2016-12-11T06:29:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"71c07af1-772b-43f9-9100-95fe56be8b7d","html_url":"https://github.com/olsonpm/universal","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olsonpm%2Funiversal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olsonpm%2Funiversal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olsonpm%2Funiversal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olsonpm%2Funiversal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/olsonpm","download_url":"https://codeload.github.com/olsonpm/universal/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243526853,"owners_count":20305112,"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-19T20:13:25.293Z","updated_at":"2025-03-14T04:43:07.155Z","avatar_url":"https://github.com/olsonpm.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Universal\n\nProvides accessors to both `global` and `window` without having to worry about\nreference errors.  This is useful for isomorphic applications which may use one\nor the other while still being consumed in both.\n\nIf you still have questions just look at the code - it's pocket-sized.\n\nexamples\n\n### global and window properties\n```js\nconsole.log(universal.global);\n// prints the global object which falls back to an empty object in\n//   browser environments\n\nconsole.log(universal.window);\n// prints the window object which falls back to an empty object in\n//   node environments\n```\n\n### getWindowProp() and getGlobalProp()\n - both functions take an array of strings which constitute the path to\n   the property.\n\n```js\n// router.js\nimport universal from 'universal';\n\nconst pathname = universal.getWindowProp(['location', 'pathname']);\nconsole.log(pathname);\n// prints the result of 'window.location.pathname' which will return undefined\n//   in node environments and the pathname in browser environments.\n\nconst nodeEnv = universal.getGlobalProp(['process', 'env', 'NODE_ENV']);\nconsole.log(nodeEnv);\n// prints the result of 'global.process.env.NODE_ENV' which will return\n//   undefined in browser environments and the NODE_ENV environment variable in\n//   node environments\n```\n\n### invokeWindowPropWith() and invokeGlobalPropWith()\n - both functions take two arguments.\n   1) an array of strings which constitute the path to the property.\n   2) an array of arguments applied to the property\n\n *Note: this method is a noop when called in the incorrect context.  e.g.\n   `invokeGlobalPropWith` in the browser does nothing*\n\n```js\n// router.js\nimport universal from 'universal';\n\nuniversal.invokeWindowPropWith(['location', 'replace'], ['https://www.google.com']);\n// calls \"window.location.replace('https://www.google.com')\" which on the node\n//   environment won't do anything and its function will return undefined.\n```\n\n### setWindowProp() and setGlobalProp()\n - both functions take two arguments.\n   1) an array of strings which constitute the path to the property.\n   2) an value to set the property to\n - returns undefined\n\n*Note: this method is a noop when called in the incorrect context.  e.g.\n  `setGlobalProp` in the browser does nothing*\n\n```js\n// router.js\nimport universal from 'universal';\n\nuniversal.setWindowProp(['document', 'onmousemove'], event =\u003e { /* do something */ });\n// In a browser this sets \"window.document.onmousemove\" to the following\n//   function.  In a node environment, nothing is set.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folsonpm%2Funiversal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Folsonpm%2Funiversal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folsonpm%2Funiversal/lists"}