{"id":19777454,"url":"https://github.com/ilib-js/ilib-env","last_synced_at":"2025-04-30T19:32:26.305Z","repository":{"id":37310986,"uuid":"356004978","full_name":"iLib-js/ilib-env","owner":"iLib-js","description":"detect various things in the runtime environment","archived":true,"fork":false,"pushed_at":"2024-11-12T13:10:44.000Z","size":115,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-28T12:19:18.011Z","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/iLib-js.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2021-04-08T18:04:15.000Z","updated_at":"2024-11-21T22:03:15.000Z","dependencies_parsed_at":"2024-06-21T14:23:26.729Z","dependency_job_id":"4823e0d9-3bf1-454e-9108-de450971eec1","html_url":"https://github.com/iLib-js/ilib-env","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iLib-js%2Filib-env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iLib-js%2Filib-env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iLib-js%2Filib-env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iLib-js%2Filib-env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iLib-js","download_url":"https://codeload.github.com/iLib-js/ilib-env/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251769492,"owners_count":21640912,"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-12T05:24:56.553Z","updated_at":"2025-04-30T19:32:26.299Z","avatar_url":"https://github.com/iLib-js.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003e :warning: **Deprecation Notice** :warning:\n\u003e This repository has been deprecated. Please use the corresponding package from the [iLib-js monorepo](https://github.com/iLib-js/ilib-mono) instead.\n\n# ilib-env\n\nDetect various things in the runtime environment.\n\n## Usage\n\nThis package can be used to detect the following things:\n\n- The current platform\n- The current locale\n- The current time zone\n- The current browser\n- The top scope and whether variables are global in the current environment\n\nSee the [full API documentation](./docs/ilibEnv.md).\n\n## Installation\n\n```\nnpm install ilib-env\n\nor\n\nyarn add ilib-env\n```\n\n### The Current Platform\n\nReturn the name of the platform upon which the code is currently running.\n\n```javascript\nES2015:\n\nvar ilibEnv = require(\"ilib-env\");\nvar platform = ilibEnv.getPlatform();\n\nES6:\n\nimport { getPlatform } from 'ilib-env';\nconst platform = getPlatform();\n\nor\n\nimport ilibEnv from 'ilib-env';\nconst platform = ilibEnv.getPlatform();\n```\n\nThis will return a string that names the platform upon which the package is running.\nThe string will have one of the following values:\n\n- browser: this code is running in a browser. Use getBrowser() to you need to know which one.\n- nodejs: this code is running on nodejs\n- qt: this code is running under QML inside of QT\n- rhino: this code is running inside of Rhino or Nashorn\n- trireme: this code is running inside of Trireme\n- unknown: the platform is not recognized\n- webos-webapp: the code is running in a web application on WebOS\n- webos: the code is running in a WebOS app\n\n### The Current Locale\n\nReturn the BCP-47 locale specifier for the platform on which this code is running.\n\n```javascript\nES2015:\n\nvar ilibEnv = require(\"ilib-env\");\nvar locale = ilibEnv.getLocale();\n\nES6:\n\nimport { getLocale } from 'ilib-env';\nconst locale = getLocale();\n\nor\n\nimport ilibEnv from 'ilib-env';\nconst locale = ilibEnv.getLocale();\n```\n\nIf the platform supports the `Intl` object, this function will use it to determine\nthe current locale. (This includes most modern browsers and nodejs). If there is no\n`Intl` object, or the locale is not specified in the `Intl` object, this function\nwill check various environment variables to find the locale. If none can be found,\nit will return a default of \"en-US\".\n\n### The Current Time Zone\n\nReturn the IANA timezone specifier for the platform on which this code is running.\n\n```javascript\nES2015:\n\nvar ilibEnv = require(\"ilib-env\");\nvar timezone = ilibEnv.getTimeZone();\n\nES6:\n\nimport { getTimeZone } from 'ilib-env';\nconst timezone = getTimeZone();\n\nor\n\nimport ilibEnv from 'ilib-env';\nconst timezone = ilibEnv.getTimeZone();\n```\n\nIf the platform supports the `Intl` object, this function will use it to determine\nthe current timezone. (This includes most modern browsers and nodejs). If there is no\n`Intl` object, or the timezone is not specified in the `Intl` object, this function\nwill check various environment variables to find the timezone. If none can be found,\nit will return a default of \"local\".\n\n### The Current Browser\n\nReturn the name of the browser on which this code is running. If the code is not\nrunningn on a browser (ie. the getPlatform() function does not return \"browser\")\nthen the return value of this function is undefined.\n\n```javascript\nES2015:\n\nvar ilibEnv = require(\"ilib-env\");\nif (ilibEnv.getPlatform() === \"browser\") {\n    browser = ilibEnv.getBrowser();\n}\n\nES6:\n\nimport { getPlatform, getBrowser } from 'ilib-env';\nif (getPlatform() === \"browser\") {\n    browser = getBrowser();\n}\n\nor\n\nimport ilibEnv from 'ilib-env';\nif (ilibEnv.getPlatform() === \"browser\") {\n    browser = ilibEnv.getBrowser();\n}\n```\n\nThis function returns one of the following values:\n\n- firefox\n- opera\n- chrome\n- ie\n- safari\n- Edge\n- iOS\n\nIf the browser name cannot be determined, this function returns undefined\n\n### The Top Scope\n\nYou can retrieve the top scope of the platform using the `top()` function\nand you can check whether or not a variable is defined in the top scope\nusing the `isGlobal()` function.\n\n```javascript\nES2015:\n\nvar ilibEnv = require(\"ilib-env\");\nvar top = ilibEnv.top();\nif (ilibEnv.isGlobal(\"variableName\")) {\n    // safe to reference variableName\n}\n\nES6:\n\nimport { top, isGlobal } from 'ilib-env';\nconst top = top();\nif (isGlobal(\"variableName\")) {\n    // safe to reference variableName\n}\n\nor\n\nimport ilibEnv from 'ilib-env';\nconst top = ilibEnv.top();\nif (ilibEnv.isGlobal(\"variableName\")) {\n    // safe to reference variableName\n}\n```\n\n## License\n\nCopyright © 2021-2024, JEDLSoft\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n## Release Notes\n\n### v1.4.0\n* Update to detect webOS platform with webOSSystem value.\n\n### v1.3.3\n\n* Fixed a problem where platform detection would happen every time it was\n  called instead of using the cached value of the platform.\n* converted all tests from nodeunit to jest\n* updated dependencies\n* added the ability to test on headless browsers from the command-line\n\n### v1.3.2\n\n* This module is now a hybrid ESM/CommonJS package that works under node\n  or webpack\n\n### v1.3.1\n\n* Removed dependency on polyfills that are not needed, which should make this\n  easier to depend upon.\n\n### v1.3.0\n\n* Now ships both the ES6 modules in the src directory and the commonjs code\n  (transpiled with babel) in the lib directory. Callers can choose which one\n  they would like to use.\n\n### v1.2.1\n\n* Updated to use polyfills with babel for node 10 and for older browsers\n* Updated dependencies\n\n### v1.2.0\n\n* Added `setLocale` and `setTimeZone` functions. These override the values\n  that are gleaned from the platform. To reset them and get the values from\n  the platform again, call the functions again with no arguments before calling\n  the getters.\n\n### v1.1.0\n\n* When two different copies of ilib-env are loaded from different node_modules\n  directories or an app loads two copies of ilib-env with different version\n  numbers, they will be copies of each other with separate variables in\n  them. When that happens, setting\n  the platform, timezone, or locale for the entire app will not work because\n  each copy of ilib-env will have a different idea of what those variables are.\n  The solution is to save the settings in the global scope so that they are\n  shared between all copies of ilib-env.\n* update dependencies\n\n### v1.0.2\n\n* Fixed a bug where locales from the platform returned by getLocale() were not\n  recognized properly if any of the following apply:\n    * They have underscores in them\n    * They have a 3 letter language name (\"yue\" means \"Cantonese\" for example)\n    * They have a three digit UN.49 region name (\"001\" is the \"The World\",\n      for example)\n    * They have a variant on them (\"zh-Hant-TW-u-PostOffice\" should return the\n      basic locale \"zh-Hant-TW\" as the platform locale)\n\n### v1.0.1\n\n- fixed some lint problems\n- added API documentation\n- now can test on web browsers automatically\n- Fixed various bugs parsing the platform locales in getLocale()\n    * Locales with a script code such as \"zh-Hans-CN\"\n    * The posix \"C\" default locale\n    * Platforms where the region code is not upper-case\n    * Platforms that don't use a dash to separate the components\n    * Platforms that include a dot and a charset name after the specifier\n\n### v1.0.0\n\n- Initial version\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filib-js%2Filib-env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Filib-js%2Filib-env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filib-js%2Filib-env/lists"}