@js-utils-kit/env 1.3.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- let e=require(`@js-utils-kit/types`),t=require(`node:process`);function n(){switch(process.env.NODE_ENV){case e.Environment.PROD:return e.Environment.PROD;case e.Environment.DEV:return e.Environment.DEV;case e.Environment.TEST:return e.Environment.TEST;default:return e.Environment.UNKNOWN}}const r=`AC_APPCIRCLE.AGOLA_GIT_REF.APPCENTER_BUILD_ID.APPVEYOR.bamboo_planKey.BITBUCKET_COMMIT.BITRISE_IO.BUDDY_WORKSPACE_ID.BUILD_ID.BUILD_NUMBER.BUILDER_OUTPUT.BUILDKITE.CF_BUILD_ID.CF_PAGES.CI.CI_XCODE_PROJECT.CIRCLECI.CIRRUS_CI.CM_BUILD_ID.CODEBUILD_BUILD_ARN.CONTINUOUS_INTEGRATION.DRONE.DSARI.EARTHLY_CI.EAS_BUILD.GERRIT_PROJECT.GITEA_ACTIONS.GITHUB_ACTIONS.GITLAB_CI.GO_PIPELINE_LABEL.HARNESS_BUILD_ID.HUDSON_URL.JENKINS_URL.LAYERCI.MAGNUM.NETLIFY.NEVERCODE.NODE.NOW_BUILDER.PROW_JOB_ID.RELEASE_BUILD_ID.RENDER.RUN_ID.SAILCI.SCREWDRIVER.SEMAPHORE.STRIDER.TASK_ID.TEAMCITY_VERSION.TF_BUILD.TRAVIS.VELA.VERCEL.WORKERS_CI.XCS`.split(`.`).some(e=>e in t.env&&t.env[e]!=null&&t.env[e]!==`0`&&t.env[e].toLowerCase()!==`false`)||typeof t.env.CI_NAME==`string`&&[`codeship`,`sourcehut`,`woodpecker`].includes(t.env.CI_NAME.toLowerCase());exports.getRunTimeEnvironment=n,exports.isCI=r;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@js-utils-kit/types`),t=require(`node:process`);function n(){switch(process.env.NODE_ENV){case e.Environment.PROD:return e.Environment.PROD;case e.Environment.DEV:return e.Environment.DEV;case e.Environment.TEST:return e.Environment.TEST;default:return e.Environment.UNKNOWN}}const r=`AC_APPCIRCLE.AGOLA_GIT_REF.APPCENTER_BUILD_ID.APPVEYOR.bamboo_planKey.BITBUCKET_COMMIT.BITRISE_IO.BUDDY_WORKSPACE_ID.BUILD_ID.BUILD_NUMBER.BUILDER_OUTPUT.BUILDKITE.CF_BUILD_ID.CF_PAGES.CI_XCODE_PROJECT.CIRCLECI.CIRRUS_CI.CM_BUILD_ID.CODEBUILD_BUILD_ARN.DRONE.DSARI.EARTHLY_CI.EAS_BUILD.GERRIT_PROJECT.GITEA_ACTIONS.GITHUB_ACTIONS.GITLAB_CI.GO_PIPELINE_LABEL.HARNESS_BUILD_ID.HUDSON_URL.JENKINS_URL.LAYERCI.MAGNUM.NETLIFY.NEVERCODE.NOW_BUILDER.PROW_JOB_ID.RELEASE_BUILD_ID.RENDER.RUN_ID.SAILCI.SCREWDRIVER.SEMAPHORE.STRIDER.TASK_ID.TEAMCITY_VERSION.TF_BUILD.TRAVIS.VELA.VERCEL.WORKERS_CI.XCS`.split(`.`),i=[`CI`,`CONTINUOUS_INTEGRATION`],a=[`codeship`,`sourcehut`,`woodpecker`],o=e=>{let n=t.env[e]??t.env[e.toUpperCase()]??t.env[e.toLowerCase()];return n!=null&&n!==`0`&&n.toLowerCase()!==`false`},s=r.some(o),c=s||i.some(o)&&(s||typeof t.env.CI_NAME==`string`&&a.includes(t.env.CI_NAME.toLowerCase())),l=typeof window<`u`&&window.document!==void 0,u=typeof process<`u`&&process.env.NODE_ENV===e.Environment.DEV,d=typeof process<`u`&&process.env.NODE_ENV===e.Environment.PROD,f=typeof process<`u`&&process.env.NODE_ENV===e.Environment.TEST,p=typeof process<`u`&&process.versions!=null&&process.versions.node!=null;exports.getRunTimeEnvironment=n,exports.isBrowser=l,exports.isCI=c,exports.isDev=u,exports.isNode=p,exports.isProd=d,exports.isTest=f;
package/dist/index.d.cts CHANGED
@@ -20,9 +20,16 @@ declare function getRunTimeEnvironment(): Environment;
20
20
  /**
21
21
  * Determines whether the current runtime environment is a Continuous Integration (CI) environment.
22
22
  *
23
- * Detection is performed by:
24
- * 1. Checking for known CI-specific environment variables
25
- * 2. Checking value-based CI identifiers via `CI_NAME`
23
+ * Detection is conservative to avoid false positives in local development.
24
+ * It works as follows:
25
+ *
26
+ * 1. Immediately returns `true` if a known CI provider environment variable is present
27
+ * (e.g. GitHub Actions, GitLab CI, CircleCI, etc.).
28
+ * 2. If only generic CI flags (such as `CI` or `CONTINUOUS_INTEGRATION`) are present,
29
+ * they are considered valid **only when** backed by a real CI provider signal
30
+ * or a known `CI_NAME` identifier.
31
+ *
32
+ * This prevents tools like `npx`, npm, or local shells from incorrectly causing CI detection while preserving correct behavior in real CI environments.
26
33
  *
27
34
  * @example
28
35
  * ```ts
@@ -31,8 +38,90 @@ declare function getRunTimeEnvironment(): Environment;
31
38
  * }
32
39
  * ```
33
40
  *
34
- * @returns `true` if running inside a CI environment
41
+ * @returns `true` if running inside a CI environment, otherwise `false`.
35
42
  */
36
43
  declare const isCI: boolean;
37
44
  //#endregion
38
- export { getRunTimeEnvironment, isCI };
45
+ //#region src/runtime.d.ts
46
+ /**
47
+ * Checks if the current runtime environment is a browser.
48
+ *
49
+ * This function helps detect whether code is executing in a web browser
50
+ * by confirming the existence of the global `window` and `document` objects.
51
+ *
52
+ * @returns `true` if running in a browser, otherwise `false`.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * if (isBrowser) {
57
+ * console.log('Running in a browser environment');
58
+ * }
59
+ * ```
60
+ */
61
+ declare const isBrowser: boolean;
62
+ /**
63
+ * Checks if the current environment is development.
64
+ *
65
+ * This is determined by comparing `process.env.NODE_ENV` with `'development'`.
66
+ *
67
+ * @returns `true` if `NODE_ENV` is set to development.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * if (isDev) {
72
+ * console.log('Dev mode enabled');
73
+ * }
74
+ * ```
75
+ */
76
+ declare const isDev: boolean;
77
+ /**
78
+ * Checks if the current environment is production.
79
+ *
80
+ * This is determined by comparing `process.env.NODE_ENV` with `'production'`.
81
+ *
82
+ * @returns `true` if `NODE_ENV` is set to production.
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * if (isProd) {
87
+ * enableAnalytics();
88
+ * }
89
+ * ```
90
+ */
91
+ declare const isProd: boolean;
92
+ /**
93
+ * Checks if the current environment is testing.
94
+ *
95
+ * This is determined by comparing `process.env.NODE_ENV` with `'test'`.
96
+ *
97
+ * @returns `true` if `NODE_ENV` is set to test.
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * if (isTest) {
102
+ * mockDatabase();
103
+ * }
104
+ * ```
105
+ */
106
+ declare const isTest: boolean;
107
+ /**
108
+ * Checks if the current runtime environment is Node.js.
109
+ *
110
+ * @remarks
111
+ * - It is useful to conditionally execute server-side logic.
112
+ * - It detects the Node.js environment by verifying the presence of the global `process` object and its `versions.node` property.
113
+ *
114
+ * @returns `true` if running in Node.js, otherwise `false`.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * if (isNode) {
119
+ * console.log('Running in Node.js environment');
120
+ * }
121
+ * ```
122
+ *
123
+ * @see {@link https://nodejs.org/api/process.html | Node.js process documentation}
124
+ */
125
+ declare const isNode: boolean;
126
+ //#endregion
127
+ export { getRunTimeEnvironment, isBrowser, isCI, isDev, isNode, isProd, isTest };
package/dist/index.d.mts CHANGED
@@ -20,9 +20,16 @@ declare function getRunTimeEnvironment(): Environment;
20
20
  /**
21
21
  * Determines whether the current runtime environment is a Continuous Integration (CI) environment.
22
22
  *
23
- * Detection is performed by:
24
- * 1. Checking for known CI-specific environment variables
25
- * 2. Checking value-based CI identifiers via `CI_NAME`
23
+ * Detection is conservative to avoid false positives in local development.
24
+ * It works as follows:
25
+ *
26
+ * 1. Immediately returns `true` if a known CI provider environment variable is present
27
+ * (e.g. GitHub Actions, GitLab CI, CircleCI, etc.).
28
+ * 2. If only generic CI flags (such as `CI` or `CONTINUOUS_INTEGRATION`) are present,
29
+ * they are considered valid **only when** backed by a real CI provider signal
30
+ * or a known `CI_NAME` identifier.
31
+ *
32
+ * This prevents tools like `npx`, npm, or local shells from incorrectly causing CI detection while preserving correct behavior in real CI environments.
26
33
  *
27
34
  * @example
28
35
  * ```ts
@@ -31,8 +38,90 @@ declare function getRunTimeEnvironment(): Environment;
31
38
  * }
32
39
  * ```
33
40
  *
34
- * @returns `true` if running inside a CI environment
41
+ * @returns `true` if running inside a CI environment, otherwise `false`.
35
42
  */
36
43
  declare const isCI: boolean;
37
44
  //#endregion
38
- export { getRunTimeEnvironment, isCI };
45
+ //#region src/runtime.d.ts
46
+ /**
47
+ * Checks if the current runtime environment is a browser.
48
+ *
49
+ * This function helps detect whether code is executing in a web browser
50
+ * by confirming the existence of the global `window` and `document` objects.
51
+ *
52
+ * @returns `true` if running in a browser, otherwise `false`.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * if (isBrowser) {
57
+ * console.log('Running in a browser environment');
58
+ * }
59
+ * ```
60
+ */
61
+ declare const isBrowser: boolean;
62
+ /**
63
+ * Checks if the current environment is development.
64
+ *
65
+ * This is determined by comparing `process.env.NODE_ENV` with `'development'`.
66
+ *
67
+ * @returns `true` if `NODE_ENV` is set to development.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * if (isDev) {
72
+ * console.log('Dev mode enabled');
73
+ * }
74
+ * ```
75
+ */
76
+ declare const isDev: boolean;
77
+ /**
78
+ * Checks if the current environment is production.
79
+ *
80
+ * This is determined by comparing `process.env.NODE_ENV` with `'production'`.
81
+ *
82
+ * @returns `true` if `NODE_ENV` is set to production.
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * if (isProd) {
87
+ * enableAnalytics();
88
+ * }
89
+ * ```
90
+ */
91
+ declare const isProd: boolean;
92
+ /**
93
+ * Checks if the current environment is testing.
94
+ *
95
+ * This is determined by comparing `process.env.NODE_ENV` with `'test'`.
96
+ *
97
+ * @returns `true` if `NODE_ENV` is set to test.
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * if (isTest) {
102
+ * mockDatabase();
103
+ * }
104
+ * ```
105
+ */
106
+ declare const isTest: boolean;
107
+ /**
108
+ * Checks if the current runtime environment is Node.js.
109
+ *
110
+ * @remarks
111
+ * - It is useful to conditionally execute server-side logic.
112
+ * - It detects the Node.js environment by verifying the presence of the global `process` object and its `versions.node` property.
113
+ *
114
+ * @returns `true` if running in Node.js, otherwise `false`.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * if (isNode) {
119
+ * console.log('Running in Node.js environment');
120
+ * }
121
+ * ```
122
+ *
123
+ * @see {@link https://nodejs.org/api/process.html | Node.js process documentation}
124
+ */
125
+ declare const isNode: boolean;
126
+ //#endregion
127
+ export { getRunTimeEnvironment, isBrowser, isCI, isDev, isNode, isProd, isTest };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{Environment as e}from"@js-utils-kit/types";import{env as t}from"node:process";function n(){switch(process.env.NODE_ENV){case e.PROD:return e.PROD;case e.DEV:return e.DEV;case e.TEST:return e.TEST;default:return e.UNKNOWN}}const r=`AC_APPCIRCLE.AGOLA_GIT_REF.APPCENTER_BUILD_ID.APPVEYOR.bamboo_planKey.BITBUCKET_COMMIT.BITRISE_IO.BUDDY_WORKSPACE_ID.BUILD_ID.BUILD_NUMBER.BUILDER_OUTPUT.BUILDKITE.CF_BUILD_ID.CF_PAGES.CI.CI_XCODE_PROJECT.CIRCLECI.CIRRUS_CI.CM_BUILD_ID.CODEBUILD_BUILD_ARN.CONTINUOUS_INTEGRATION.DRONE.DSARI.EARTHLY_CI.EAS_BUILD.GERRIT_PROJECT.GITEA_ACTIONS.GITHUB_ACTIONS.GITLAB_CI.GO_PIPELINE_LABEL.HARNESS_BUILD_ID.HUDSON_URL.JENKINS_URL.LAYERCI.MAGNUM.NETLIFY.NEVERCODE.NODE.NOW_BUILDER.PROW_JOB_ID.RELEASE_BUILD_ID.RENDER.RUN_ID.SAILCI.SCREWDRIVER.SEMAPHORE.STRIDER.TASK_ID.TEAMCITY_VERSION.TF_BUILD.TRAVIS.VELA.VERCEL.WORKERS_CI.XCS`.split(`.`).some(e=>e in t&&t[e]!=null&&t[e]!==`0`&&t[e].toLowerCase()!==`false`)||typeof t.CI_NAME==`string`&&[`codeship`,`sourcehut`,`woodpecker`].includes(t.CI_NAME.toLowerCase());export{n as getRunTimeEnvironment,r as isCI};
1
+ import{Environment as e}from"@js-utils-kit/types";import{env as t}from"node:process";function n(){switch(process.env.NODE_ENV){case e.PROD:return e.PROD;case e.DEV:return e.DEV;case e.TEST:return e.TEST;default:return e.UNKNOWN}}const r=`AC_APPCIRCLE.AGOLA_GIT_REF.APPCENTER_BUILD_ID.APPVEYOR.bamboo_planKey.BITBUCKET_COMMIT.BITRISE_IO.BUDDY_WORKSPACE_ID.BUILD_ID.BUILD_NUMBER.BUILDER_OUTPUT.BUILDKITE.CF_BUILD_ID.CF_PAGES.CI_XCODE_PROJECT.CIRCLECI.CIRRUS_CI.CM_BUILD_ID.CODEBUILD_BUILD_ARN.DRONE.DSARI.EARTHLY_CI.EAS_BUILD.GERRIT_PROJECT.GITEA_ACTIONS.GITHUB_ACTIONS.GITLAB_CI.GO_PIPELINE_LABEL.HARNESS_BUILD_ID.HUDSON_URL.JENKINS_URL.LAYERCI.MAGNUM.NETLIFY.NEVERCODE.NOW_BUILDER.PROW_JOB_ID.RELEASE_BUILD_ID.RENDER.RUN_ID.SAILCI.SCREWDRIVER.SEMAPHORE.STRIDER.TASK_ID.TEAMCITY_VERSION.TF_BUILD.TRAVIS.VELA.VERCEL.WORKERS_CI.XCS`.split(`.`),i=[`CI`,`CONTINUOUS_INTEGRATION`],a=[`codeship`,`sourcehut`,`woodpecker`],o=e=>{let n=t[e]??t[e.toUpperCase()]??t[e.toLowerCase()];return n!=null&&n!==`0`&&n.toLowerCase()!==`false`},s=r.some(o),c=s||i.some(o)&&(s||typeof t.CI_NAME==`string`&&a.includes(t.CI_NAME.toLowerCase())),l=typeof window<`u`&&window.document!==void 0,u=typeof process<`u`&&process.env.NODE_ENV===e.DEV,d=typeof process<`u`&&process.env.NODE_ENV===e.PROD,f=typeof process<`u`&&process.env.NODE_ENV===e.TEST,p=typeof process<`u`&&process.versions!=null&&process.versions.node!=null;export{n as getRunTimeEnvironment,l as isBrowser,c as isCI,u as isDev,p as isNode,d as isProd,f as isTest};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@js-utils-kit/env",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "Environment utilities",
5
5
  "private": false,
6
6
  "license": "MIT",
@@ -30,12 +30,12 @@
30
30
  "types": "./dist/index.d.cts",
31
31
  "exports": {
32
32
  ".": {
33
- "require": "./dist/index.cjs",
34
- "import": "./dist/index.mjs"
33
+ "import": "./dist/index.mjs",
34
+ "require": "./dist/index.cjs"
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@js-utils-kit/types": "1.2.0"
38
+ "@js-utils-kit/types": "1.3.0"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "tsdown",