From d7e74ed49bcd503173d000a673a9bf11e483f11b Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 3 Jun 2022 12:32:43 +0300 Subject: [PATCH] feat: integrate node-ip package --- README.md | 12 ++++++++++-- npm-shrinkwrap.json | 11 +++++++++++ package.json | 1 + src/main/js/index.mjs | 3 ++- src/test/js/test.mjs | 7 ++++++- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2d77ffe..821c3c7 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,20 @@ yarn add zx-extra ``` ## Usage -Inherits zx, so all origin methods are available. +Inherits zx, so all origin methods are available. Follow [the upstream docs](https://github.com/google/zx) for details. ## Extras +### `ip` +Resolves the current IP address via [node-ip](https://github.com/indutny/node-ip). +```js +import {ip} from 'zx-extra' + +ip.address() // 1.2.3.4 +``` + ### `semver` -Semantic versioning api from [node-semver](https://github.com/npm/node-semver) +Semantic versioning API provided by [node-semver](https://github.com/npm/node-semver) ```js import {semver} from 'zx-extra' diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 9d09bea..82e05db 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -12,6 +12,7 @@ "@qiwi/deep-proxy": "^1.9.0", "@types/node": "^17.0.38", "@types/semver": "^7.3.9", + "ip": "^1.1.8", "npm-run-path": "^5.1.0", "zx": "^6.2.0" }, @@ -279,6 +280,11 @@ "node": ">= 4" } }, + "node_modules/ip": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/ip/-/ip-1.1.8.tgz", + "integrity": "sha512-PuExPYUiu6qMBQb4l06ecm6T6ujzhmh+MeJcW9wa89PoAz5pvd4zPgN5WJV104mb6S2T1AwNIAaB70JNrLQWhg==" + }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -820,6 +826,11 @@ "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", "integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==" }, + "ip": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/ip/-/ip-1.1.8.tgz", + "integrity": "sha512-PuExPYUiu6qMBQb4l06ecm6T6ujzhmh+MeJcW9wa89PoAz5pvd4zPgN5WJV104mb6S2T1AwNIAaB70JNrLQWhg==" + }, "is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", diff --git a/package.json b/package.json index e8ee2f3..4ccc950 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "@qiwi/deep-proxy": "^1.9.0", "@types/node": "^17.0.38", "@types/semver": "^7.3.9", + "ip": "^1.1.8", "npm-run-path": "^5.1.0", "zx": "^6.2.0" } diff --git a/src/main/js/index.mjs b/src/main/js/index.mjs index e5c2c50..7f616a3 100644 --- a/src/main/js/index.mjs +++ b/src/main/js/index.mjs @@ -4,8 +4,9 @@ import {isTemplateSignature, randomId} from './util.mjs' import {npmRunPath} from 'npm-run-path' import {DeepProxy} from '@qiwi/deep-proxy' -export { semver } from './semver.mjs' export * from 'zx' +export { default as ip } from 'ip' +export { semver } from './semver.mjs' export const $ = new DeepProxy(_$, ({DEFAULT, trapName, args}) => { if (trapName === 'apply') { diff --git a/src/test/js/test.mjs b/src/test/js/test.mjs index 421b235..19066c4 100644 --- a/src/test/js/test.mjs +++ b/src/test/js/test.mjs @@ -1,5 +1,5 @@ import {strict as assert} from 'node:assert' -import {$, semver, createHook} from '../../main/js/index.mjs' +import {$, semver, createHook, ip} from '../../main/js/index.mjs' // $.raw { @@ -105,3 +105,8 @@ import {$, semver, createHook} from '../../main/js/index.mjs' $.verbose = 2 } +// ip +{ + assert(/(\d+\.){3}\d+/.test(ip.address())) +} +