{"name":"@webcontainer/env","version":"1.0.1","keywords":["stackblitz","webcontainer","nodejs"],"author":{"name":"StackBlitz Inc."},"license":"MIT","_id":"@webcontainer/env@1.0.1","maintainers":[{"name":"d3lm","email":"elmdominic@gmx.net"},{"name":"apai4","email":"iamalbertpai@gmail.com"},{"name":"ericmsimons","email":"eric@esft.com"}],"homepage":"https://github.com/stackblitz/webcontainer-core","bugs":{"url":"https://github.com/stackblitz/webcontainer-core/issues"},"dist":{"shasum":"9cf6798078db61c7c36d6f325aec26a7236f68a6","tarball":"http://registry-npm.ywwl.com/@webcontainer/env/download/@webcontainer/env-1.0.1.tgz","fileCount":7,"integrity":"sha512-q5sD2asa7IY/elCA37zbzTH1DiiIooTuUcW9O5Zvrtfyy7PtqAmPpgpDCbWzA/fRWShfUnPp6yDzmpq5K4YtjA==","signatures":[{"sig":"MEQCIC4n/+P/TA88bHuGavOBixgjIIMgNBoAauHHZx5jb5J4AiA1BTv3q8X9hru1XUbujzcwIeutM22VkMyquJm5C14izw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":9660,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiemsBACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqzGRAApKLPlsTpXgb/UJbFE271kt4N1V0P8ainu3qJUupTtggvkO7i\r\nD67ZdTTQgImYT0lHEBuumvToxSNHhPqJyzKGHKEhZ2iLXF3vp78Shd8ktv0F\r\nW7OZ8WnE8rXk2aEbrRRH+d9d4WYPoYgJL8pjA1SsCXWPlCBQ1eotMeuqM+PD\r\nT2LkpIayIgN5JHB3NdM7fVvizSVfC/C959j5TGXv7EioU3imEvgkp/IKevuy\r\ngbcEBJnObQc3AT7m+uZHy1wj9fdN2WSUU4w4pOsPmVtfsVb902uLlw01DXf2\r\nqTagWz1PLinrRqt4WdMZSWYPm2QFMkJU6DsOQzYiSCqj+9YggjDc74xcNFL+\r\nQyrvpBD6PByN1w0v/dcuy7aDJBGBZ+0vEa8Sas+1GK9xvzsGLzoFXI4KMiMx\r\nRSduPRK2NODJ0O+4u8iB2y1IV8f5/G2aJdE3PFhLzrA+618UoBbUK40hT4oQ\r\n+yi0QKAuonByt/MochkhLmgUCsbqq5nKLnFVLd0c7xwLYP8XIi77/iskg3KX\r\nRNQkU7ylHKQI8zZXkKlzBivHvf+V2DMcvUru8PfSXAwQ5v1FFNVZ6MbFF4N1\r\n5akeGr7ovXhVIwRkWfHnnw4c48brrYKI8vdhyx5L4AVpTjP8XrbBoqZgjLcA\r\npCCLUyWVrgyuZyRQ+6KwKBA/NYXNRH2fZgM=\r\n=VVyL\r\n-----END PGP SIGNATURE-----\r\n","size":4046,"noattachment":false,"key":"/@webcontainer/env/-/@webcontainer/env-1.0.1.tgz"},"main":"dist/index.js","types":"dist/index.d.ts","exports":{"import":"./dist/index.js","require":"./dist/index.js"},"gitHead":"1becece65fb9e6d89d27bbe87eedd4d64b37a3a4","scripts":{"test":"jest","build":"esbuild src/index.ts --bundle --minify --keep-names --platform=node --external:@blitz/env --outfile=dist/index.js && tsc --project tsconfig.build.json --emitDeclarationOnly","prepack":"npm run test && npm run build"},"_npmUser":{"name":"d3lm","email":"elmdominic@gmx.net"},"repository":{"url":"git+https://github.com/stackblitz/webcontainer-core.git","type":"git"},"_npmVersion":"8.5.0","description":"Set of environment utilities for WebContainers","directories":{},"_nodeVersion":"16.14.2","_hasShrinkwrap":false,"devDependencies":{"esbuild":"^0.14.38"},"_npmOperationalInternal":{"tmp":"tmp/env_1.0.1_1652189953244_0.35090178759948065","host":"s3://npm-registry-packages"},"readme":"# @webcontainer/env\n\n> ⚠️ Important ⚠️\n>\n> We strongly recommend that you update to version `1.1.0` or greater as we\n> recently introduced a breaking change in WebContainer, making older versions of\n> `@webcontainer/api` generate invalid `HostURL.href` and `HostURL.hostname`\n> when those methods are called inside a WebContainer.\n\nSet of environment utilities for [WebContainers](https://blog.stackblitz.com/posts/introducing-webcontainers/).\n\n## Install\n\n```shell\n$ npm install @webcontainer/env\n```\n\n## API\n\n### `isWebContainer(): boolean` (method)\n\nReturns a `boolean` indicating whether the program runs in a WebContainer.\n\n### `HostURL` (class)\n\nThe `HostURL` class represents a host specific URL. It can be used to parse a regular URL, such as\n`http://localhost:1234`, into a `HostURL`. Only if the program is executed in a WebContainer,\nthe `hostname` is resolved to a WebContainer hostname, e.g. `http://blitz--1234.local.webcontainer.io`.\nThis can be useful to create platform-dependent OAuth callback URLs.\n\n#### [`HostURL.port(): string`](https://developer.mozilla.org/en-US/docs/Web/API/URL/port) (getter)\n\n#### [`HostURL.hash(): string`](https://developer.mozilla.org/en-US/docs/Web/API/URL/hash) (getter)\n\n#### [`HostURL.host(): string`](https://developer.mozilla.org/en-US/docs/Web/API/URL/host) (getter)\n\n#### [`HostURL.hostname(): string`](https://developer.mozilla.org/en-US/docs/Web/API/URL/hostname) (getter)\n\n#### [`HostURL.href(): string`](https://developer.mozilla.org/en-US/docs/Web/API/URL/href) (getter)\n\n#### [`HostURL.origin(): string`](https://developer.mozilla.org/en-US/docs/Web/API/URL/origin) (getter)\n\n#### [`HostURL.username(): string`](https://developer.mozilla.org/en-US/docs/Web/API/URL/username) (getter)\n\n#### [`HostURL.password(): string`](https://developer.mozilla.org/en-US/docs/Web/API/URL/password) (getter)\n\n#### [`HostURL.pathname(): string`](https://developer.mozilla.org/en-US/docs/Web/API/URL/pathname) (getter)\n\n#### [`HostURL.protocol(): string`](https://developer.mozilla.org/en-US/docs/Web/API/URL/protocol) (getter)\n\n#### [`HostURL.search(): string`](https://developer.mozilla.org/en-US/docs/Web/API/URL/search) (getter)\n\n#### [`HostURL.searchParams(): URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URL/searchParams) (getter)\n\n#### `HostURL.parse(url: string | URL): HostURL` (static method)\n\nParses a `url` into a `HostURL`. On local this is a no-op but when running in a WebContainer it resolves `localhost`\nto a WebContainer hostname.\n\n**Example**\n\n```js\nimport { HostURL, isWebContainer } from '@webcontainer/env';\n\nconst hostURL = HostURL.parse('http://localhost:1234');\n\n/**\n * Note that this branching would not be necessary as the host URL gets parsed\n * and resolved automatically through `HostURL.parse()` (see above). So `href`\n * will return a different value depending on the environment. This is illustrated\n * with the following `if` statement.\n */\nif (isWebContainer()) {\n  console.log(hostURL.href); // http://blitz--1234.local.webcontainer.io\n} else {\n  console.log(hostURL.href); // http://localhost:1234\n}\n```\n\n#### `HostURL.update(change: Partial<UpdateableURLProperties>): HostURL` (method)\n\nUpdates the `HostURL`.\n\n##### **change**\n\nObject containing the URL changes. Note that some properties are immutable (read-only), e.g. `origin` or `searchParams`. When updating the `port` it automatically updates the `host`.\n\nType: `Partial<UpdateableURLProperties>`\n\n```js\ninterface UpdateableURLProperties {\n  hash: string;\n  host: string;\n  hostname: string;\n  href: string;\n  password: string;\n  pathname: string;\n  port: string;\n  protocol: string;\n  search: string;\n  username: string;\n}\n```\n\n#### `HostURL.toString(): string` (method)\n\nStringifies the HostURL. It is effectively a read-only version of `HostURL.href`.\n\n#### `HostURL.toJSON(): string` (method)\n\nReturns a string containing a serialized version of the `HostURL`.\n","publish_time":1652189953409,"_cnpm_publish_time":1652189953409,"dist-tags":{"latest":"1.1.1"}}