is-where 1.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Luca Ban - Mesqueeb
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # is Where? 🙈
2
+
3
+ <a href="https://www.npmjs.com/package/is-where"><img src="https://img.shields.io/npm/v/is-where.svg" alt="Total Downloads"></a>
4
+ <a href="https://www.npmjs.com/package/is-where"><img src="https://img.shields.io/npm/dw/is-where.svg" alt="Latest Stable Version"></a>
5
+
6
+ Very simple & small JS environment check functions.
7
+
8
+ ```
9
+ npm i is-where
10
+ ```
11
+
12
+ <!-- Or for deno available at: `"deno.land/x/is_where"` -->
13
+
14
+ > Also check out [is-what 🙉](https://github.com/mesqueeb/is-what)
15
+
16
+ ## Motivation
17
+
18
+ I built is-where because I kept Stack Overflowing the same things for every project.
19
+
20
+ I was looking for:
21
+
22
+ - A simple way to check which environment (Node, Browser, Deno, ...)
23
+ - A simple way to check for which browser (WebKit, Safari, Chrome, Firefox, ...)
24
+ - Functions that don't crash when executed in any environment
25
+ - 0 dependencies
26
+
27
+ ## Usage
28
+
29
+ is-where is really easy to use, and most functions work just like you'd expect.
30
+
31
+ ```js
32
+ // import functions you want to use like so:
33
+ import { isBrowser, isNode, isWebKit } from 'is-where'
34
+ ```
35
+
36
+ ```js
37
+ isBrowser() // true / false
38
+ isNode() // true / false
39
+ isWebKit() // true / false
40
+ ```
41
+
42
+ ### List of functions
43
+
44
+ Environments
45
+
46
+ - `isNode()`
47
+ - `isBrowser()`
48
+ - `isWebWorker()`
49
+ - `isJsDom()`
50
+ - `isDeno()`
51
+
52
+ Browsers
53
+
54
+ - `isWebKit()`
55
+ - `isSafari()`
56
+
57
+ ## Meet the family
58
+
59
+ - [is-what 🙉](https://github.com/mesqueeb/is-what)
60
+ - [is-where 🙈](https://github.com/mesqueeb/is-where)
61
+ - [merge-anything 🥡](https://github.com/mesqueeb/merge-anything)
62
+ - [filter-anything ⚔️](https://github.com/mesqueeb/filter-anything)
63
+ - [find-and-replace-anything 🎣](https://github.com/mesqueeb/find-and-replace-anything)
64
+ - [compare-anything 🛰](https://github.com/mesqueeb/compare-anything)
65
+ - [copy-anything 🎭](https://github.com/mesqueeb/copy-anything)
66
+ - [flatten-anything 🏏](https://github.com/mesqueeb/flatten-anything)
67
+
68
+ ## Source code
69
+
70
+ See the full source code [here](https://github.com/mesqueeb/is-where/blob/production/src/index.ts).
package/dist/index.cjs ADDED
@@ -0,0 +1,82 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /**
6
+ * returns `true` if the current environment is Node
7
+ */
8
+ function isNode() {
9
+ return typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
10
+ }
11
+ /**
12
+ * returns `true` if the current environment is a browser
13
+ */
14
+ function isBrowser() {
15
+ return typeof window !== 'undefined' && typeof window.document !== 'undefined';
16
+ }
17
+ /**
18
+ * returns `true` if the current environment is a Web Worker
19
+ */
20
+ function isWebWorker() {
21
+ return (typeof self === 'object' &&
22
+ self.constructor &&
23
+ self.constructor.name === 'DedicatedWorkerGlobalScope');
24
+ }
25
+ /**
26
+ * returns `true` if the current environment is JS DOM
27
+ */
28
+ function isJsDom() {
29
+ return ((typeof window !== 'undefined' && window.name === 'nodejs') ||
30
+ (typeof navigator !== 'undefined' &&
31
+ (navigator.userAgent.includes('Node.js') || navigator.userAgent.includes('jsdom'))));
32
+ }
33
+ /**
34
+ * returns `true` if the current environment is Deno
35
+ */
36
+ function isDeno() {
37
+ // @ts-ignore
38
+ return typeof Deno !== 'undefined' && typeof Deno.core !== 'undefined';
39
+ }
40
+ /**
41
+ * returns `true` if the current browser is based on WebKit
42
+ *
43
+ * This includes:
44
+ * - Safari on macOS
45
+ * - Safari on iOS & iPadOS
46
+ * - Google Chrome on iOS & iPadOS
47
+ * - Firefox on iOS & iPadOS
48
+ * - ... on iOS & iPadOS
49
+ *
50
+ * All mobile browsers on iOS & iPadOS use WebKit
51
+ */
52
+ function isWebKit() {
53
+ return (isBrowser() &&
54
+ !!navigator.vendor &&
55
+ navigator.vendor.indexOf('Apple') !== -1 &&
56
+ !!navigator.userAgent);
57
+ }
58
+ /**
59
+ * returns `true` if the current browser is Safari
60
+ *
61
+ * This includes:
62
+ * - Safari on macOS
63
+ * - Safari on iOS & iPadOS
64
+ *
65
+ * It does not include other browser on iOS & iPadOS
66
+ */
67
+ function isSafari() {
68
+ return (isBrowser() &&
69
+ !!navigator.vendor &&
70
+ navigator.vendor.indexOf('Apple') !== -1 &&
71
+ !!navigator.userAgent &&
72
+ navigator.userAgent.indexOf('CriOS') == -1 &&
73
+ navigator.userAgent.indexOf('FxiOS') == -1);
74
+ }
75
+
76
+ exports.isBrowser = isBrowser;
77
+ exports.isDeno = isDeno;
78
+ exports.isJsDom = isJsDom;
79
+ exports.isNode = isNode;
80
+ exports.isSafari = isSafari;
81
+ exports.isWebKit = isWebKit;
82
+ exports.isWebWorker = isWebWorker;
@@ -0,0 +1,72 @@
1
+ /**
2
+ * returns `true` if the current environment is Node
3
+ */
4
+ function isNode() {
5
+ return typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
6
+ }
7
+ /**
8
+ * returns `true` if the current environment is a browser
9
+ */
10
+ function isBrowser() {
11
+ return typeof window !== 'undefined' && typeof window.document !== 'undefined';
12
+ }
13
+ /**
14
+ * returns `true` if the current environment is a Web Worker
15
+ */
16
+ function isWebWorker() {
17
+ return (typeof self === 'object' &&
18
+ self.constructor &&
19
+ self.constructor.name === 'DedicatedWorkerGlobalScope');
20
+ }
21
+ /**
22
+ * returns `true` if the current environment is JS DOM
23
+ */
24
+ function isJsDom() {
25
+ return ((typeof window !== 'undefined' && window.name === 'nodejs') ||
26
+ (typeof navigator !== 'undefined' &&
27
+ (navigator.userAgent.includes('Node.js') || navigator.userAgent.includes('jsdom'))));
28
+ }
29
+ /**
30
+ * returns `true` if the current environment is Deno
31
+ */
32
+ function isDeno() {
33
+ // @ts-ignore
34
+ return typeof Deno !== 'undefined' && typeof Deno.core !== 'undefined';
35
+ }
36
+ /**
37
+ * returns `true` if the current browser is based on WebKit
38
+ *
39
+ * This includes:
40
+ * - Safari on macOS
41
+ * - Safari on iOS & iPadOS
42
+ * - Google Chrome on iOS & iPadOS
43
+ * - Firefox on iOS & iPadOS
44
+ * - ... on iOS & iPadOS
45
+ *
46
+ * All mobile browsers on iOS & iPadOS use WebKit
47
+ */
48
+ function isWebKit() {
49
+ return (isBrowser() &&
50
+ !!navigator.vendor &&
51
+ navigator.vendor.indexOf('Apple') !== -1 &&
52
+ !!navigator.userAgent);
53
+ }
54
+ /**
55
+ * returns `true` if the current browser is Safari
56
+ *
57
+ * This includes:
58
+ * - Safari on macOS
59
+ * - Safari on iOS & iPadOS
60
+ *
61
+ * It does not include other browser on iOS & iPadOS
62
+ */
63
+ function isSafari() {
64
+ return (isBrowser() &&
65
+ !!navigator.vendor &&
66
+ navigator.vendor.indexOf('Apple') !== -1 &&
67
+ !!navigator.userAgent &&
68
+ navigator.userAgent.indexOf('CriOS') == -1 &&
69
+ navigator.userAgent.indexOf('FxiOS') == -1);
70
+ }
71
+
72
+ export { isBrowser, isDeno, isJsDom, isNode, isSafari, isWebKit, isWebWorker };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * returns `true` if the current environment is Node
3
+ */
4
+ export declare function isNode(): boolean;
5
+ /**
6
+ * returns `true` if the current environment is a browser
7
+ */
8
+ export declare function isBrowser(): boolean;
9
+ /**
10
+ * returns `true` if the current environment is a Web Worker
11
+ */
12
+ export declare function isWebWorker(): boolean;
13
+ /**
14
+ * returns `true` if the current environment is JS DOM
15
+ */
16
+ export declare function isJsDom(): boolean;
17
+ /**
18
+ * returns `true` if the current environment is Deno
19
+ */
20
+ export declare function isDeno(): boolean;
21
+ /**
22
+ * returns `true` if the current browser is based on WebKit
23
+ *
24
+ * This includes:
25
+ * - Safari on macOS
26
+ * - Safari on iOS & iPadOS
27
+ * - Google Chrome on iOS & iPadOS
28
+ * - Firefox on iOS & iPadOS
29
+ * - ... on iOS & iPadOS
30
+ *
31
+ * All mobile browsers on iOS & iPadOS use WebKit
32
+ */
33
+ export declare function isWebKit(): boolean;
34
+ /**
35
+ * returns `true` if the current browser is Safari
36
+ *
37
+ * This includes:
38
+ * - Safari on macOS
39
+ * - Safari on iOS & iPadOS
40
+ *
41
+ * It does not include other browser on iOS & iPadOS
42
+ */
43
+ export declare function isSafari(): boolean;
package/package.json ADDED
@@ -0,0 +1,118 @@
1
+ {
2
+ "name": "is-where",
3
+ "sideEffects": false,
4
+ "type": "module",
5
+ "version": "1.0.0",
6
+ "description": "JS environment check functions like `isWebkit() isSafari() isBrowser() isNode()` etc. A simple & small integration.",
7
+ "module": "./dist/index.es.js",
8
+ "main": "./dist/index.cjs",
9
+ "types": "./dist/types/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.es.js",
13
+ "require": "./dist/index.cjs",
14
+ "types": "./dist/types/index.d.ts"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "engines": {
21
+ "node": ">=14"
22
+ },
23
+ "scripts": {
24
+ "test": "vitest run",
25
+ "lint": "tsc --noEmit && eslint ./src --ext .ts",
26
+ "build": "rollup -c ./scripts/build.js",
27
+ "release": "npm run lint && del dist && npm run build && np"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/mesqueeb/is-where.git"
32
+ },
33
+ "keywords": [
34
+ "javascript",
35
+ "typescript",
36
+ "envchecker",
37
+ "check-environment",
38
+ "check-browser",
39
+ "is-browser",
40
+ "is-node",
41
+ "is-deno",
42
+ "is-safari",
43
+ "is-chrome",
44
+ "is-webkit",
45
+ "is-edge",
46
+ "is-firefox",
47
+ "is-opera",
48
+ "is-ie",
49
+ "is-ssr",
50
+ "is-server",
51
+ "browser-checking",
52
+ "browser-checker",
53
+ "browser-check",
54
+ "environment-checking",
55
+ "environment-checker",
56
+ "environment-check"
57
+ ],
58
+ "author": "Luca Ban - Mesqueeb",
59
+ "funding": "https://github.com/sponsors/mesqueeb",
60
+ "license": "MIT",
61
+ "bugs": {
62
+ "url": "https://github.com/mesqueeb/is-where/issues"
63
+ },
64
+ "homepage": "https://github.com/mesqueeb/is-where#readme",
65
+ "devDependencies": {
66
+ "@typescript-eslint/eslint-plugin": "^5.10.1",
67
+ "@typescript-eslint/parser": "^5.10.1",
68
+ "del-cli": "^4.0.1",
69
+ "eslint": "^8.7.0",
70
+ "eslint-config-prettier": "^8.3.0",
71
+ "eslint-plugin-tree-shaking": "^1.10.0",
72
+ "np": "^7.6.0",
73
+ "prettier": "^2.5.1",
74
+ "rollup": "^2.66.1",
75
+ "rollup-plugin-typescript2": "^0.31.1",
76
+ "typescript": "^4.5.5",
77
+ "vitest": "^0.2.3"
78
+ },
79
+ "ava": {
80
+ "extensions": {
81
+ "ts": "module"
82
+ },
83
+ "nodeArguments": [
84
+ "--loader=ts-node/esm"
85
+ ]
86
+ },
87
+ "np": {
88
+ "yarn": false,
89
+ "branch": "production"
90
+ },
91
+ "eslintConfig": {
92
+ "ignorePatterns": [
93
+ "node_modules",
94
+ "dist",
95
+ "scripts",
96
+ "test"
97
+ ],
98
+ "root": true,
99
+ "parser": "@typescript-eslint/parser",
100
+ "plugins": [
101
+ "@typescript-eslint",
102
+ "tree-shaking"
103
+ ],
104
+ "extends": [
105
+ "eslint:recommended",
106
+ "plugin:@typescript-eslint/eslint-recommended",
107
+ "plugin:@typescript-eslint/recommended",
108
+ "prettier"
109
+ ],
110
+ "rules": {
111
+ "@typescript-eslint/no-empty-function": "off",
112
+ "@typescript-eslint/no-explicit-any": "off",
113
+ "@typescript-eslint/ban-ts-ignore": "off",
114
+ "tree-shaking/no-side-effects-in-initialization": "error",
115
+ "@typescript-eslint/ban-ts-comment": "off"
116
+ }
117
+ }
118
+ }