@lowentry/utils 1.1.1 → 1.2.1

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/LeUtils.js CHANGED
@@ -2263,6 +2263,59 @@ export const LeUtils = {
2263
2263
  window.localStorage.removeItem('LeUtils_' + id);
2264
2264
  },
2265
2265
 
2266
+ /**
2267
+ * Returns whether the current hostname (window.location.hostname) is private (such as localhost, 192.168.1.1, etc).
2268
+ * This can be used to determine if the app is running in a development environment or not.
2269
+ *
2270
+ * Only "localhost" and IPv4 addresses are supported. IPv6 addresses will always return false.
2271
+ *
2272
+ * @returns {boolean}
2273
+ */
2274
+ isCurrentHostPrivate:
2275
+ (() =>
2276
+ {
2277
+ let lastHostname = null;
2278
+ let lastResult = false;
2279
+
2280
+ return () =>
2281
+ {
2282
+ const hostname = window.location.hostname;
2283
+ if(lastHostname === hostname)
2284
+ {
2285
+ return lastResult;
2286
+ }
2287
+ lastHostname = hostname;
2288
+ lastResult = LeUtils.isGivenHostPrivate(lastHostname);
2289
+ return lastResult;
2290
+ };
2291
+ })(),
2292
+
2293
+ /**
2294
+ * Returns true if the given hostname is private (such as localhost, 192.168.1.1, etc).
2295
+ *
2296
+ * Only "localhost" and IPv4 addresses are supported. IPv6 addresses will always return false.
2297
+ *
2298
+ * @param {string} host
2299
+ * @returns {boolean}
2300
+ */
2301
+ isGivenHostPrivate:
2302
+ (host) =>
2303
+ {
2304
+ host = STRING(host).trim().toLowerCase();
2305
+ if((host === 'localhost') || (host === '127.0.0.1'))
2306
+ {
2307
+ return true;
2308
+ }
2309
+ if(!/^(\d{1,3}\.){3}\d{1,3}$/.test(host))
2310
+ {
2311
+ return false;
2312
+ }
2313
+ const parts = host.split('.');
2314
+ return (parts[0] === '10') || // 10.0.0.0 - 10.255.255.255
2315
+ ((parts[0] === '172') && ((parseInt(parts[1], 10) >= 16) && (parseInt(parts[1], 10) <= 31))) || // 172.16.0.0 - 172.31.255.255
2316
+ ((parts[0] === '192') && (parts[1] === '168')); // 192.168.0.0 - 192.168.255.255
2317
+ },
2318
+
2266
2319
  /**
2267
2320
  * Creates and returns a new TreeSet.
2268
2321
  * A TreeSet is a set of elements, sorted by a comparator.
@@ -1,19 +1,20 @@
1
1
  image: node:lts
2
2
 
3
3
  pipelines:
4
- default:
5
- - step:
6
- name: Build and Test
7
- script:
8
- - npm install
9
- - npm test
10
- - step:
11
- name: Publish
12
- deployment: production
13
- script:
14
- - npm version patch -m "Upgrade to %s [skip ci]"
15
- - git push && git push --tags
16
- - pipe: atlassian/npm-publish:1.1.0
17
- variables:
18
- NPM_TOKEN: $NPM_TOKEN
19
- EXTRA_ARGS: "--access public"
4
+ branches:
5
+ master:
6
+ - step:
7
+ name: Build and Test
8
+ script:
9
+ - npm install
10
+ - npm test
11
+ - step:
12
+ name: Publish
13
+ deployment: production
14
+ script:
15
+ - npm version patch -m "Upgrade to %s [skip ci]"
16
+ - git push && git push --tags
17
+ - pipe: atlassian/npm-publish:1.1.0
18
+ variables:
19
+ NPM_TOKEN: $NPM_TOKEN
20
+ EXTRA_ARGS: "--access public"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowentry/utils",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Provides utilities for general JavaScript development.",