js-utils-kit 0.0.0 → 0.2.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/LICENSE +20 -20
- package/README.md +153 -3
- package/dist/char/index.cjs +1 -0
- package/dist/char/index.d.ts +41 -0
- package/dist/char/index.js +1 -0
- package/dist/cli/index.js +50 -0
- package/dist/env/index.cjs +1 -0
- package/dist/env/index.d.ts +128 -0
- package/dist/env/index.js +1 -0
- package/dist/file/index.cjs +49 -0
- package/dist/file/index.d.ts +75 -0
- package/dist/file/index.js +49 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +1 -0
- package/dist/number/index.cjs +1 -0
- package/dist/number/index.d.ts +74 -0
- package/dist/number/index.js +1 -0
- package/dist/object/index.cjs +1 -0
- package/dist/object/index.d.ts +46 -0
- package/dist/object/index.js +1 -0
- package/dist/string/index.cjs +1 -0
- package/dist/string/index.d.ts +137 -0
- package/dist/string/index.js +1 -0
- package/package.json +110 -72
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e;function n(){switch(process.env.NODE_ENV){case exports.Environment.PROD:return exports.Environment.PROD;case exports.Environment.DEV:return exports.Environment.DEV;case exports.Environment.TEST:return exports.Environment.TEST;default:return exports.Environment.UNKNOWN}}function r(){return process.env.NODE_ENV===exports.Environment.PROD}function o(){return process.env.NODE_ENV===exports.Environment.DEV}function t(){return process.env.NODE_ENV===exports.Environment.TEST}function s(){return"undefined"!=typeof process&&null!==process.versions&&null!==process.versions.node}function i(){return"undefined"!=typeof window&&void 0!==window.document}Object.defineProperty(exports,"__esModule",{value:!0}),exports.Environment=void 0,(e=exports.Environment||(exports.Environment={})).PROD="production",e.DEV="development",e.TEST="test",e.UNKNOWN="unknown";var p={getRunTimeEnvironment:n,isProd:r,isDev:o,isTest:t,isNode:s,isBrowser:i};exports.default=p,exports.getRunTimeEnvironment=n,exports.isBrowser=i,exports.isDev=o,exports.isNode=s,exports.isProd=r,exports.isTest=t;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the standard runtime environments used in application development.
|
|
3
|
+
*
|
|
4
|
+
* This enum is typically used with `process.env.NODE_ENV` to determine
|
|
5
|
+
* whether the app is running in development, production, or test mode.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* if (process.env.NODE_ENV === Environment.DEV) {
|
|
10
|
+
* console.log('Running in development mode');
|
|
11
|
+
* }
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
declare enum Environment {
|
|
15
|
+
/** Production environment (`"production"`) */
|
|
16
|
+
PROD = "production",
|
|
17
|
+
/** Development environment (`"development"`) */
|
|
18
|
+
DEV = "development",
|
|
19
|
+
/** Testing environment (`"test"`) */
|
|
20
|
+
TEST = "test",
|
|
21
|
+
/** Unknown or undefined environment */
|
|
22
|
+
UNKNOWN = "unknown"
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns the current runtime environment as one of the defined `Environment` enum values.
|
|
26
|
+
*
|
|
27
|
+
* @returns The current environment.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const env = getRunTimeEnvironment();
|
|
32
|
+
* if (env === "development") {
|
|
33
|
+
* console.log('Dev mode enabled');
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
declare function getRunTimeEnvironment(): Environment;
|
|
38
|
+
/**
|
|
39
|
+
* Checks if the current environment is production.
|
|
40
|
+
*
|
|
41
|
+
* This is determined by comparing `process.env.NODE_ENV` with `'production'`.
|
|
42
|
+
*
|
|
43
|
+
* @returns `true` if `NODE_ENV` is set to production.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* if (isProd()) {
|
|
48
|
+
* enableAnalytics();
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
declare function isProd(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Checks if the current environment is development.
|
|
55
|
+
*
|
|
56
|
+
* This is determined by comparing `process.env.NODE_ENV` with `'development'`.
|
|
57
|
+
*
|
|
58
|
+
* @returns `true` if `NODE_ENV` is set to development.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* if (isDev()) {
|
|
63
|
+
* console.log('Dev mode enabled');
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
declare function isDev(): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Checks if the current environment is testing.
|
|
70
|
+
*
|
|
71
|
+
* This is determined by comparing `process.env.NODE_ENV` with `'test'`.
|
|
72
|
+
*
|
|
73
|
+
* @returns `true` if `NODE_ENV` is set to test.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* if (isTest()) {
|
|
78
|
+
* mockDatabase();
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
declare function isTest(): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Checks if the current runtime environment is Node.js.
|
|
85
|
+
*
|
|
86
|
+
* This function is useful to conditionally execute server-side logic.
|
|
87
|
+
* It detects the Node.js environment by verifying the presence of the
|
|
88
|
+
* global `process` object and its `versions.node` property.
|
|
89
|
+
*
|
|
90
|
+
* @returns `true` if running in Node.js, otherwise `false`.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* if (isNode()) {
|
|
95
|
+
* console.log('Running in Node.js environment');
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @see {@link https://nodejs.org/api/process.html | Node.js process documentation}
|
|
100
|
+
*/
|
|
101
|
+
declare function isNode(): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Checks if the current runtime environment is a browser.
|
|
104
|
+
*
|
|
105
|
+
* This function helps detect whether code is executing in a web browser
|
|
106
|
+
* by confirming the existence of the global `window` and `document` objects.
|
|
107
|
+
*
|
|
108
|
+
* @returns `true` if running in a browser, otherwise `false`.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* if (isBrowser()) {
|
|
113
|
+
* console.log('Running in a browser environment');
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
declare function isBrowser(): boolean;
|
|
118
|
+
|
|
119
|
+
declare const _default: {
|
|
120
|
+
getRunTimeEnvironment: typeof getRunTimeEnvironment;
|
|
121
|
+
isProd: typeof isProd;
|
|
122
|
+
isDev: typeof isDev;
|
|
123
|
+
isTest: typeof isTest;
|
|
124
|
+
isNode: typeof isNode;
|
|
125
|
+
isBrowser: typeof isBrowser;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export { Environment, _default as default, getRunTimeEnvironment, isBrowser, isDev, isNode, isProd, isTest };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var n;function e(){switch(process.env.NODE_ENV){case n.PROD:return n.PROD;case n.DEV:return n.DEV;case n.TEST:return n.TEST;default:return n.UNKNOWN}}function r(){return process.env.NODE_ENV===n.PROD}function o(){return process.env.NODE_ENV===n.DEV}function s(){return process.env.NODE_ENV===n.TEST}function t(){return"undefined"!=typeof process&&null!==process.versions&&null!==process.versions.node}function u(){return"undefined"!=typeof window&&void 0!==window.document}!function(n){n.PROD="production",n.DEV="development",n.TEST="test",n.UNKNOWN="unknown"}(n||(n={}));var i={getRunTimeEnvironment:e,isProd:r,isDev:o,isTest:s,isNode:t,isBrowser:u};export{n as Environment,i as default,e as getRunTimeEnvironment,u as isBrowser,o as isDev,t as isNode,r as isProd,s as isTest};
|