{"name":"@webcontainer/env","version":"1.1.1","keywords":["stackblitz","webcontainer","nodejs"],"author":{"name":"StackBlitz Inc."},"license":"MIT","_id":"@webcontainer/env@1.1.1","maintainers":[{"name":"nemikolh","email":"nemikolh@gmail.com"},{"name":"stackblitz-devops","email":"devops@stackblitz.com"},{"name":"_rvidal","email":"roberto.vidal@ikumene.com"},{"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":"23021b2bb24befeeef53dba8996d1886b7016515","tarball":"http://registry-npm.ywwl.com/@webcontainer/env/download/@webcontainer/env-1.1.1.tgz","fileCount":7,"integrity":"sha512-6aN99yL695Hi9SuIk1oC88l9o0gmxL1nGWWQ/kNy81HigJ0FoaoTXpytCj6ItzgyCEwA9kF1wixsTuv5cjsgng==","signatures":[{"sig":"MEYCIQDanMRybej94VJMDjr0/cyNqVKAZPPMg8NOTJM79TeIRgIhAOnfzDSatNhR0OI23GTbXxcZ1ec32aqKDYcdsJUti5Zs","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":9982,"size":4079,"noattachment":false,"key":"/@webcontainer/env/-/@webcontainer/env-1.1.1.tgz"},"main":"dist/index.js","types":"dist/index.d.ts","exports":{"import":"./dist/index.js","require":"./dist/index.js"},"gitHead":"d37f1e4ad427c6f1fbdaea8463f30dd1d4fa5555","scripts":{"test":"jest","build":"ts-node -T scripts/build.ts && 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":"9.8.1","description":"Set of environment utilities for WebContainers","directories":{},"_nodeVersion":"18.18.0","_hasShrinkwrap":false,"devDependencies":{"esbuild":"^0.19.5"},"_npmOperationalInternal":{"tmp":"tmp/env_1.1.1_1711615025771_0.7964961964544757","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":1711615025934,"_cnpm_publish_time":1711615025934,"dist-tags":{"latest":"1.1.1"}}