ui
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 UnJS
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
# std-env
|
||||
|
||||
[](http://npmjs.com/package/std-env)
|
||||
[](http://npmjs.com/package/std-env)
|
||||
[](https://bundlephobia.com/result?p=std-env)
|
||||
|
||||
> Detect current Javascript environment
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
# Using Yarn
|
||||
yarn add std-env
|
||||
|
||||
# Using npm
|
||||
npm i std-env
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
// ESM
|
||||
import { isWindows } from 'std-env'
|
||||
|
||||
// CommonJS
|
||||
const { isCI } = require('std-env')
|
||||
```
|
||||
|
||||
Available exports:
|
||||
|
||||
- `hasTTY`
|
||||
- `hasWindow`
|
||||
- `isCI`
|
||||
- `isDebug`
|
||||
- `isDevelopment`
|
||||
- `isLinux`
|
||||
- `isMacOS`
|
||||
- `isMinimal`
|
||||
- `isProduction`
|
||||
- `isTest`
|
||||
- `isWindows`
|
||||
- `platform`
|
||||
- `provider`
|
||||
|
||||
You can read more about how each flag works from [./src/index.ts](./src/index.ts).
|
||||
|
||||
List of well known providers can be found from [./src/providers.ts](./src/providers.ts).
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
const providers = [
|
||||
["APPVEYOR"],
|
||||
["AZURE_PIPELINES", "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"],
|
||||
["AZURE_STATIC", "INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN"],
|
||||
["APPCIRCLE", "AC_APPCIRCLE"],
|
||||
["BAMBOO", "bamboo_planKey"],
|
||||
["BITBUCKET", "BITBUCKET_COMMIT"],
|
||||
["BITRISE", "BITRISE_IO"],
|
||||
["BUDDY", "BUDDY_WORKSPACE_ID"],
|
||||
["BUILDKITE"],
|
||||
["CIRCLE", "CIRCLECI"],
|
||||
["CIRRUS", "CIRRUS_CI"],
|
||||
["CODEBUILD", "CODEBUILD_BUILD_ARN"],
|
||||
["CODEFRESH", "CF_BUILD_ID"],
|
||||
["DRONE"],
|
||||
["DRONE", "DRONE_BUILD_EVENT"],
|
||||
["DSARI"],
|
||||
["GITHUB_ACTIONS"],
|
||||
["GITLAB", "GITLAB_CI"],
|
||||
["GITLAB", "CI_MERGE_REQUEST_ID"],
|
||||
["GOCD", "GO_PIPELINE_LABEL"],
|
||||
["LAYERCI"],
|
||||
["HUDSON", "HUDSON_URL"],
|
||||
["JENKINS", "JENKINS_URL"],
|
||||
["MAGNUM"],
|
||||
["NETLIFY"],
|
||||
["NETLIFY", "NETLIFY_LOCAL", { ci: false }],
|
||||
["NEVERCODE"],
|
||||
["RENDER"],
|
||||
["SAIL", "SAILCI"],
|
||||
["SEMAPHORE"],
|
||||
["SCREWDRIVER"],
|
||||
["SHIPPABLE"],
|
||||
["SOLANO", "TDDIUM"],
|
||||
["STRIDER"],
|
||||
["TEAMCITY", "TEAMCITY_VERSION"],
|
||||
["TRAVIS"],
|
||||
["VERCEL", "NOW_BUILDER"],
|
||||
["APPCENTER", "APPCENTER_BUILD_ID"],
|
||||
["CODESANDBOX", "CODESANDBOX_SSE", { ci: false }],
|
||||
["STACKBLITZ"]
|
||||
];
|
||||
function detectProvider(env) {
|
||||
for (const provider of providers) {
|
||||
const envName = provider[1] || provider[0];
|
||||
if (env[envName]) {
|
||||
return {
|
||||
name: provider[0].toLowerCase(),
|
||||
...provider[2]
|
||||
};
|
||||
}
|
||||
}
|
||||
if (env.SHELL && env.SHELL === "/bin/jsh") {
|
||||
return {
|
||||
name: "stackblitz",
|
||||
ci: false
|
||||
};
|
||||
}
|
||||
return {
|
||||
name: "",
|
||||
ci: false
|
||||
};
|
||||
}
|
||||
|
||||
const processShim = typeof process !== "undefined" ? process : {};
|
||||
const envShim = processShim.env || {};
|
||||
const providerInfo = detectProvider(envShim);
|
||||
const nodeENV = envShim.NODE_ENV || "";
|
||||
const platform = processShim.platform;
|
||||
const provider = providerInfo.name;
|
||||
const isCI = toBoolean(envShim.CI) || providerInfo.ci !== false;
|
||||
const hasTTY = toBoolean(processShim.stdout && processShim.stdout.isTTY);
|
||||
const hasWindow = typeof window !== "undefined";
|
||||
const isDebug = toBoolean(envShim.DEBUG);
|
||||
const isTest = toBoolean(envShim.TEST);
|
||||
const isProduction = nodeENV === "production";
|
||||
const isDevelopment = nodeENV === "dev" || nodeENV === "development";
|
||||
const isMinimal = toBoolean(envShim.MINIMAL) || isCI || isTest || !hasTTY;
|
||||
const isWindows = /^win/i.test(platform);
|
||||
const isLinux = /^linux/i.test(platform);
|
||||
const isMacOS = /^darwin/i.test(platform);
|
||||
function toBoolean(val) {
|
||||
return val ? val !== "false" : false;
|
||||
}
|
||||
|
||||
exports.hasTTY = hasTTY;
|
||||
exports.hasWindow = hasWindow;
|
||||
exports.isCI = isCI;
|
||||
exports.isDebug = isDebug;
|
||||
exports.isDevelopment = isDevelopment;
|
||||
exports.isLinux = isLinux;
|
||||
exports.isMacOS = isMacOS;
|
||||
exports.isMinimal = isMinimal;
|
||||
exports.isProduction = isProduction;
|
||||
exports.isTest = isTest;
|
||||
exports.isWindows = isWindows;
|
||||
exports.platform = platform;
|
||||
exports.provider = provider;
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
declare type ProviderName = '' | 'appveyor' | 'azure_pipelines' | 'azure_static' | 'appcircle' | 'bamboo' | 'bitbucket' | 'bitrise' | 'buddy' | 'buildkite' | 'circle' | 'cirrus' | 'codebuild' | 'codefresh' | 'drone' | 'drone' | 'dsari' | 'github_actions' | 'gitlab' | 'gitlab' | 'gocd' | 'layerci' | 'hudson' | 'jenkins' | 'magnum' | 'netlify' | 'netlify' | 'nevercode' | 'render' | 'sail' | 'semaphore' | 'screwdriver' | 'shippable' | 'solano' | 'strider' | 'teamcity' | 'travis' | 'vercel' | 'appcenter' | 'codesandbox' | 'stackblitz';
|
||||
declare type ProviderInfo = {
|
||||
name: ProviderName;
|
||||
[meta: string]: any;
|
||||
};
|
||||
|
||||
/** Value of process.platform */
|
||||
declare const platform: NodeJS.Platform;
|
||||
/** Current provider name */
|
||||
declare const provider: ProviderName;
|
||||
/** Detect if `CI` environment variable is set or a provider CI detected */
|
||||
declare const isCI: boolean;
|
||||
/** Detect if stdout.TTY is available */
|
||||
declare const hasTTY: boolean;
|
||||
/** Detect if global `window` object is available */
|
||||
declare const hasWindow: boolean;
|
||||
/** Detect if `DEBUG` environment variable is set */
|
||||
declare const isDebug: boolean;
|
||||
/** Detect if `NODE_ENV` environment variable is `test` */
|
||||
declare const isTest: boolean;
|
||||
/** Detect if `NODE_ENV` environment variable is `production` */
|
||||
declare const isProduction: boolean;
|
||||
/** Detect if `NODE_ENV` environment variable is `dev` or `development` */
|
||||
declare const isDevelopment: boolean;
|
||||
/** Detect if MINIMAL environment variable is set, running in CI or test or TTY is unavailable */
|
||||
declare const isMinimal: boolean;
|
||||
/** Detect if process.platform is Windows */
|
||||
declare const isWindows: boolean;
|
||||
/** Detect if process.platform is Linux */
|
||||
declare const isLinux: boolean;
|
||||
/** Detect if process.platform is macOS (darwin kernel) */
|
||||
declare const isMacOS: boolean;
|
||||
|
||||
export { ProviderInfo, ProviderName, hasTTY, hasWindow, isCI, isDebug, isDevelopment, isLinux, isMacOS, isMinimal, isProduction, isTest, isWindows, platform, provider };
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
const providers = [
|
||||
["APPVEYOR"],
|
||||
["AZURE_PIPELINES", "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"],
|
||||
["AZURE_STATIC", "INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN"],
|
||||
["APPCIRCLE", "AC_APPCIRCLE"],
|
||||
["BAMBOO", "bamboo_planKey"],
|
||||
["BITBUCKET", "BITBUCKET_COMMIT"],
|
||||
["BITRISE", "BITRISE_IO"],
|
||||
["BUDDY", "BUDDY_WORKSPACE_ID"],
|
||||
["BUILDKITE"],
|
||||
["CIRCLE", "CIRCLECI"],
|
||||
["CIRRUS", "CIRRUS_CI"],
|
||||
["CODEBUILD", "CODEBUILD_BUILD_ARN"],
|
||||
["CODEFRESH", "CF_BUILD_ID"],
|
||||
["DRONE"],
|
||||
["DRONE", "DRONE_BUILD_EVENT"],
|
||||
["DSARI"],
|
||||
["GITHUB_ACTIONS"],
|
||||
["GITLAB", "GITLAB_CI"],
|
||||
["GITLAB", "CI_MERGE_REQUEST_ID"],
|
||||
["GOCD", "GO_PIPELINE_LABEL"],
|
||||
["LAYERCI"],
|
||||
["HUDSON", "HUDSON_URL"],
|
||||
["JENKINS", "JENKINS_URL"],
|
||||
["MAGNUM"],
|
||||
["NETLIFY"],
|
||||
["NETLIFY", "NETLIFY_LOCAL", { ci: false }],
|
||||
["NEVERCODE"],
|
||||
["RENDER"],
|
||||
["SAIL", "SAILCI"],
|
||||
["SEMAPHORE"],
|
||||
["SCREWDRIVER"],
|
||||
["SHIPPABLE"],
|
||||
["SOLANO", "TDDIUM"],
|
||||
["STRIDER"],
|
||||
["TEAMCITY", "TEAMCITY_VERSION"],
|
||||
["TRAVIS"],
|
||||
["VERCEL", "NOW_BUILDER"],
|
||||
["APPCENTER", "APPCENTER_BUILD_ID"],
|
||||
["CODESANDBOX", "CODESANDBOX_SSE", { ci: false }],
|
||||
["STACKBLITZ"]
|
||||
];
|
||||
function detectProvider(env) {
|
||||
for (const provider of providers) {
|
||||
const envName = provider[1] || provider[0];
|
||||
if (env[envName]) {
|
||||
return {
|
||||
name: provider[0].toLowerCase(),
|
||||
...provider[2]
|
||||
};
|
||||
}
|
||||
}
|
||||
if (env.SHELL && env.SHELL === "/bin/jsh") {
|
||||
return {
|
||||
name: "stackblitz",
|
||||
ci: false
|
||||
};
|
||||
}
|
||||
return {
|
||||
name: "",
|
||||
ci: false
|
||||
};
|
||||
}
|
||||
|
||||
const processShim = typeof process !== "undefined" ? process : {};
|
||||
const envShim = processShim.env || {};
|
||||
const providerInfo = detectProvider(envShim);
|
||||
const nodeENV = envShim.NODE_ENV || "";
|
||||
const platform = processShim.platform;
|
||||
const provider = providerInfo.name;
|
||||
const isCI = toBoolean(envShim.CI) || providerInfo.ci !== false;
|
||||
const hasTTY = toBoolean(processShim.stdout && processShim.stdout.isTTY);
|
||||
const hasWindow = typeof window !== "undefined";
|
||||
const isDebug = toBoolean(envShim.DEBUG);
|
||||
const isTest = toBoolean(envShim.TEST);
|
||||
const isProduction = nodeENV === "production";
|
||||
const isDevelopment = nodeENV === "dev" || nodeENV === "development";
|
||||
const isMinimal = toBoolean(envShim.MINIMAL) || isCI || isTest || !hasTTY;
|
||||
const isWindows = /^win/i.test(platform);
|
||||
const isLinux = /^linux/i.test(platform);
|
||||
const isMacOS = /^darwin/i.test(platform);
|
||||
function toBoolean(val) {
|
||||
return val ? val !== "false" : false;
|
||||
}
|
||||
|
||||
export { hasTTY, hasWindow, isCI, isDebug, isDevelopment, isLinux, isMacOS, isMinimal, isProduction, isTest, isWindows, platform, provider };
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "std-env",
|
||||
"version": "3.0.1",
|
||||
"description": "Detect current Javascript environment",
|
||||
"repository": "unjs/std-env",
|
||||
"license": "MIT",
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.cjs"
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"prepack": "unbuild",
|
||||
"release": "yarn test && standard-version && git push --follow-tags && npm publish",
|
||||
"test": "node test.cjs"
|
||||
},
|
||||
"devDependencies": {
|
||||
"standard-version": "^9.3.2",
|
||||
"unbuild": "^0.5.11"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user