Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9afb568c86 | |||
| 091f7fec01 | |||
| d61a1cf7f6 | |||
| 1477ceda5d | |||
| 2632bf2082 | |||
| 9803cf6b90 | |||
| 83cd9507ac | |||
| 0837945b81 | |||
| 68c064f260 | |||
| bd95de9152 | |||
| 6864bed88d | |||
| 0bdddc32d1 | |||
| 40651a5660 | |||
| 5f1b4a784e | |||
| 2da9122c68 | |||
| 5d80323baa | |||
| 72fccebf14 | |||
| 7faf31147d | |||
| d479cd9e7e | |||
| f479c11574 | |||
| 7df770f9fb |
-128
@@ -1,128 +0,0 @@
|
|||||||
# gitzone ci_default
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .npmci_cache/
|
|
||||||
key: '$CI_BUILD_STAGE'
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- security
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- metadata
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
- pnpm install -g pnpm
|
|
||||||
- pnpm install -g @shipzone/npmci
|
|
||||||
- npmci npm prepare
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
# ====================
|
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
auditProductionDependencies:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command pnpm audit --audit-level=high --prod
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
auditDevDependencies:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command pnpm audit --audit-level=high --dev
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# test stage
|
|
||||||
# ====================
|
|
||||||
|
|
||||||
testStable:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
testBuild:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command npm run build
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# metadata stage
|
|
||||||
# ====================
|
|
||||||
codequality:
|
|
||||||
stage: metadata
|
|
||||||
allow_failure: true
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
script:
|
|
||||||
- npmci command npm install -g typescript
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci trigger
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
pages:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command npm run buildDocs
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
||||||
allow_failure: true
|
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"@ship.zone/szci": {
|
||||||
|
"npmGlobalTools": [],
|
||||||
|
"npmRegistryUrl": "registry.npmjs.org"
|
||||||
|
},
|
||||||
|
"@git.zone/cli": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "code.foss.global",
|
||||||
|
"gitscope": "push.rocks",
|
||||||
|
"gitrepo": "smartping",
|
||||||
|
"shortDescription": "Node.js ping utility",
|
||||||
|
"description": "A utility for performing ping operations in Node.js environments.",
|
||||||
|
"npmPackagename": "@push.rocks/smartping",
|
||||||
|
"license": "MIT",
|
||||||
|
"keywords": [
|
||||||
|
"ping",
|
||||||
|
"network",
|
||||||
|
"connectivity",
|
||||||
|
"Node.js",
|
||||||
|
"utility",
|
||||||
|
"async",
|
||||||
|
"promise"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"release": {
|
||||||
|
"registries": [
|
||||||
|
"https://verdaccio.lossless.digital",
|
||||||
|
"https://registry.npmjs.org"
|
||||||
|
],
|
||||||
|
"accessLevel": "public"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@git.zone/tsdoc": {
|
||||||
|
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 2026-05-01 - 1.0.10 - fix(readme)
|
||||||
|
refresh README with clearer API documentation and usage examples
|
||||||
|
|
||||||
|
- Rewrites the package overview to better explain Smartping, ping, and pingAlive
|
||||||
|
- Adds quick start, API reference, usage patterns, and runtime notes for Node.js environments
|
||||||
|
- Clarifies timeout behavior and error-handling expectations for health check use cases
|
||||||
|
|
||||||
|
## 2026-05-01 - 1.0.9 - fix(package)
|
||||||
|
modernize package configuration and stabilize ping typings and tests
|
||||||
|
|
||||||
|
- add package exports and include project metadata files in published package
|
||||||
|
- update build and test tooling to current @git.zone packages and newer ping dependency
|
||||||
|
- replace external host-based tests with localhost node tests for more reliable execution
|
||||||
|
- derive ping response type from the ping library and simplify pingAlive error handling
|
||||||
|
|
||||||
|
## 2026-03-01 - 1.0.8 - maintenance
|
||||||
|
Project maintenance and repository metadata updates across the 1.0.8 line.
|
||||||
|
|
||||||
|
- Removed the `.gitlab-ci.yml` configuration
|
||||||
|
- Updated package metadata and repository hosting configuration
|
||||||
|
- Refreshed TypeScript configuration and project description
|
||||||
|
- Consolidates trivial maintenance changes from 2023-07-10 through 2026-03-01
|
||||||
|
|
||||||
|
## 2023-04-19 - 1.0.8 - core
|
||||||
|
Core update release.
|
||||||
|
|
||||||
|
- Applied a core update
|
||||||
|
|
||||||
|
## 2022-10-21 - 1.0.7 - core
|
||||||
|
Patch release continuing a series of core fixes.
|
||||||
|
|
||||||
|
- Applied a core update
|
||||||
|
- Summarizes repeated trivial patch releases across 1.0.4 to 1.0.7
|
||||||
|
|
||||||
|
## 2018-11-18 - 1.0.1 - core
|
||||||
|
Initial recorded core patch release.
|
||||||
|
|
||||||
|
- Applied a core update
|
||||||
|
- Includes the initial version tagging activity through 1.0.2
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 2022 Lossless GmbH (hello@lossless.com)
|
Copyright (c) 2026 Task Venture Capital GmbH <hello@task.vc>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
+29
-9
@@ -1,18 +1,38 @@
|
|||||||
{
|
{
|
||||||
"gitzone": {
|
"@ship.zone/szci": {
|
||||||
|
"npmGlobalTools": [],
|
||||||
|
"npmRegistryUrl": "registry.npmjs.org"
|
||||||
|
},
|
||||||
|
"@git.zone/cli": {
|
||||||
"projectType": "npm",
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "code.foss.global",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "smartping",
|
"gitrepo": "smartping",
|
||||||
"description": "a ping utility",
|
"shortDescription": "Node.js ping utility",
|
||||||
"npmPackagename": "@pushrocks/smartping",
|
"description": "A utility for performing ping operations in Node.js environments.",
|
||||||
|
"npmPackagename": "@push.rocks/smartping",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"projectDomain": "push.rocks"
|
"projectDomain": "push.rocks",
|
||||||
|
"keywords": [
|
||||||
|
"ping",
|
||||||
|
"network",
|
||||||
|
"connectivity",
|
||||||
|
"Node.js",
|
||||||
|
"utility",
|
||||||
|
"async",
|
||||||
|
"promise"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"release": {
|
||||||
|
"registries": [
|
||||||
|
"https://verdaccio.lossless.digital",
|
||||||
|
"https://registry.npmjs.org"
|
||||||
|
],
|
||||||
|
"accessLevel": "public"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"npmci": {
|
"@git.zone/tsdoc": {
|
||||||
"npmGlobalTools": [],
|
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||||
"npmAccessLevel": "public"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Generated
-13432
File diff suppressed because it is too large
Load Diff
+33
-15
@@ -1,27 +1,29 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartping",
|
"name": "@push.rocks/smartping",
|
||||||
"version": "1.0.3",
|
"version": "1.0.10",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a ping utility",
|
"description": "A utility for performing ping operations in Node.js environments.",
|
||||||
|
"exports": {
|
||||||
|
".": "./dist_ts/index.js"
|
||||||
|
},
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"author": "Lossless GmbH",
|
"author": "Task Venture Capital GmbH <hello@task.vc>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/ --web)",
|
"test": "tstest test/",
|
||||||
"build": "(tsbuild --web --allowimplicitany)",
|
"build": "tsbuild",
|
||||||
"buildDocs": "(tsdoc)"
|
"buildDocs": "tsdoc"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"ping": "^1.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@git.zone/tsbuild": "^4.4.0",
|
||||||
"@gitzone/tsbundle": "^2.0.5",
|
"@git.zone/tstest": "^3.6.3",
|
||||||
"@gitzone/tsdoc": "^1.1.10",
|
"@types/node": "^25.6.0"
|
||||||
"@gitzone/tstest": "^1.0.44",
|
|
||||||
"@pushrocks/tapbundle": "^5.0.3",
|
|
||||||
"@types/node": "^17.0.41"
|
|
||||||
},
|
},
|
||||||
"dependencies": {},
|
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
],
|
],
|
||||||
@@ -34,7 +36,23 @@
|
|||||||
"dist_ts_web/**/*",
|
"dist_ts_web/**/*",
|
||||||
"assets/**/*",
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
|
".smartconfig.json",
|
||||||
|
"license",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
]
|
],
|
||||||
|
"keywords": [
|
||||||
|
"ping",
|
||||||
|
"network",
|
||||||
|
"connectivity",
|
||||||
|
"Node.js",
|
||||||
|
"utility",
|
||||||
|
"async",
|
||||||
|
"promise"
|
||||||
|
],
|
||||||
|
"homepage": "https://code.foss.global/push.rocks/smartping",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://code.foss.global/push.rocks/smartping.git"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+7515
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
@@ -1,39 +1,156 @@
|
|||||||
# @pushrocks/smartping
|
# @push.rocks/smartping
|
||||||
a ping utility
|
|
||||||
|
|
||||||
## Availabililty and Links
|
Small, typed, promise-first ping checks for Node.js. `@push.rocks/smartping` wraps the proven [`ping`](https://www.npmjs.com/package/ping) package behind a tiny TypeScript API, so service health checks, diagnostics, readiness probes, and connectivity tests stay easy to read.
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartping)
|
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartping)
|
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smartping)
|
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartping/)
|
|
||||||
|
|
||||||
## Status for master
|
It uses the system `ping` command through the underlying dependency, so it is designed for Node.js environments with a working platform ping utility available.
|
||||||
|
|
||||||
Status Category | Status Badge
|
## Issue Reporting and Security
|
||||||
-- | --
|
|
||||||
GitLab Pipelines | [](https://lossless.cloud)
|
|
||||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
|
||||||
npm | [](https://lossless.cloud)
|
|
||||||
Snyk | [](https://lossless.cloud)
|
|
||||||
TypeScript Support | [](https://lossless.cloud)
|
|
||||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
Code Style | [](https://lossless.cloud)
|
|
||||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
|
||||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
|
||||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
|
||||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
|
||||||
|
|
||||||
## Usage
|
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
|
||||||
|
|
||||||
Use TypeScript for best in class intellisense
|
## Install
|
||||||
|
|
||||||
## Contribution
|
```bash
|
||||||
|
pnpm add @push.rocks/smartping
|
||||||
|
```
|
||||||
|
|
||||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
## What You Get
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
- `Smartping`: a lightweight class for probing hosts.
|
||||||
|
- `ping(host, timeout?)`: returns the full ping response from the underlying `ping.promise.probe(...)` call.
|
||||||
|
- `pingAlive(host, timeout?)`: returns a boolean and converts ping failures into `false`.
|
||||||
|
- TypeScript types, ESM exports, and direct async/await ergonomics.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
## Quick Start
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
```typescript
|
||||||
|
import { Smartping } from '@push.rocks/smartping';
|
||||||
|
|
||||||
|
const smartping = new Smartping();
|
||||||
|
|
||||||
|
const response = await smartping.ping('127.0.0.1', 1);
|
||||||
|
|
||||||
|
console.log(response.alive); // true when the host responded
|
||||||
|
console.log(response.time); // response time reported by the platform ping utility
|
||||||
|
```
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### `new Smartping()`
|
||||||
|
|
||||||
|
Creates a ping helper instance. The class is intentionally stateless, so you can create one per module, per service, or per check without setup.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { Smartping } from '@push.rocks/smartping';
|
||||||
|
|
||||||
|
const smartping = new Smartping();
|
||||||
|
```
|
||||||
|
|
||||||
|
### `smartping.ping(host, timeout?)`
|
||||||
|
|
||||||
|
Runs a ping probe and returns the full response object from `ping.promise.probe(...)`.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await smartping.ping('example.com', 2);
|
||||||
|
|
||||||
|
if (result.alive) {
|
||||||
|
console.log(`${result.host} responded in ${result.time}`);
|
||||||
|
} else {
|
||||||
|
console.log(`${result.host} did not respond`);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The `timeout` argument is passed to the underlying `ping` package as `timeout`, where it is documented as seconds. If omitted, `@push.rocks/smartping` uses its default value of `500`.
|
||||||
|
|
||||||
|
### `smartping.pingAlive(host, timeout?)`
|
||||||
|
|
||||||
|
Runs a ping probe and returns only the alive state.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const databaseHostIsReachable = await smartping.pingAlive('10.0.0.5', 1);
|
||||||
|
|
||||||
|
if (!databaseHostIsReachable) {
|
||||||
|
throw new Error('Database host is not reachable');
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`pingAlive(...)` is useful for health checks because it catches probe errors and returns `false` instead of throwing.
|
||||||
|
|
||||||
|
## Usage Patterns
|
||||||
|
|
||||||
|
### Service Health Check
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { Smartping } from '@push.rocks/smartping';
|
||||||
|
|
||||||
|
const smartping = new Smartping();
|
||||||
|
|
||||||
|
export const checkNetworkDependency = async () => {
|
||||||
|
return smartping.pingAlive('api.internal.example', 1);
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### Diagnostics With Full Response Data
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { Smartping } from '@push.rocks/smartping';
|
||||||
|
|
||||||
|
const smartping = new Smartping();
|
||||||
|
|
||||||
|
const hosts = ['127.0.0.1', 'example.com', '10.0.0.5'];
|
||||||
|
|
||||||
|
for (const host of hosts) {
|
||||||
|
const result = await smartping.ping(host, 1);
|
||||||
|
console.log({
|
||||||
|
host,
|
||||||
|
alive: result.alive,
|
||||||
|
output: result.output,
|
||||||
|
time: result.time,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Graceful Failure Handling
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { Smartping } from '@push.rocks/smartping';
|
||||||
|
|
||||||
|
const smartping = new Smartping();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await smartping.ping('example.com', 1);
|
||||||
|
console.log(result);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Ping probe failed before producing a response:', error);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Use `ping(...)` when you need response details and want to decide how to handle errors yourself. Use `pingAlive(...)` when a simple `true` or `false` is the desired contract.
|
||||||
|
|
||||||
|
## Runtime Notes
|
||||||
|
|
||||||
|
- This package targets Node.js and ESM-based TypeScript projects.
|
||||||
|
- The underlying `ping` package delegates to the operating system ping command.
|
||||||
|
- Hosts can be DNS names or IP addresses accepted by the platform ping utility.
|
||||||
|
- Timeout behavior is inherited from `ping`, including platform-specific details around system ping arguments.
|
||||||
|
|
||||||
|
## License and Legal Information
|
||||||
|
|
||||||
|
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
|
||||||
|
|
||||||
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
### Trademarks
|
||||||
|
|
||||||
|
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
|
||||||
|
|
||||||
|
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
|
||||||
|
|
||||||
|
### Company Information
|
||||||
|
|
||||||
|
Task Venture Capital GmbH
|
||||||
|
Registered at District Court Bremen HRB 35230 HB, Germany
|
||||||
|
|
||||||
|
For any legal inquiries or further information, please contact us via email at hello@task.vc.
|
||||||
|
|
||||||
|
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
|
import * as smartping from '../ts/index.js';
|
||||||
|
|
||||||
|
let testPing: smartping.Smartping;
|
||||||
|
|
||||||
|
tap.test('should create an instance of Smartping', async () => {
|
||||||
|
testPing = new smartping.Smartping();
|
||||||
|
expect(testPing).toBeInstanceOf(smartping.Smartping);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should deliver a ping result', async () => {
|
||||||
|
const result = await testPing.ping('127.0.0.1', 1);
|
||||||
|
expect(result.alive).toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should detect alive', async () => {
|
||||||
|
expect(await testPing.pingAlive('127.0.0.1', 1)).toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default tap.start();
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
import { expect, expectAsync, tap } from '@pushrocks/tapbundle';
|
|
||||||
import * as smartping from '../ts/index.js';
|
|
||||||
|
|
||||||
tap.test('first test', async () => {
|
|
||||||
console.log(smartping);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.start();
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* autocreated commitinfo by @pushrocks/commitinfo
|
* autocreated commitinfo by @push.rocks/commitinfo
|
||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/smartping',
|
name: '@push.rocks/smartping',
|
||||||
version: '1.0.3',
|
version: '1.0.10',
|
||||||
description: 'a ping utility'
|
description: 'A utility for performing ping operations in Node.js environments.'
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -1,3 +1 @@
|
|||||||
import * as plugins from './smartping.plugins.js';
|
export * from './smartping.classes.smartping.js';
|
||||||
|
|
||||||
export let demoExport = 'Hi there! :) This is an exported string';
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import * as plugins from './smartping.plugins.js';
|
||||||
|
|
||||||
|
export type TPingResponse = Awaited<ReturnType<typeof plugins.ping.promise.probe>>;
|
||||||
|
|
||||||
|
export class Smartping {
|
||||||
|
public async ping(hostArg: string, timeoutArg: number = 500): Promise<TPingResponse> {
|
||||||
|
const result = await plugins.ping.promise.probe(hostArg, {
|
||||||
|
timeout: timeoutArg
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async pingAlive(hostArg: string, timeoutArg: number = 500): Promise<boolean> {
|
||||||
|
try {
|
||||||
|
const result = await this.ping(hostArg, timeoutArg);
|
||||||
|
return result.alive;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,2 +1,5 @@
|
|||||||
const removeme = {};
|
import ping from 'ping';
|
||||||
export { removeme };
|
|
||||||
|
export {
|
||||||
|
ping
|
||||||
|
};
|
||||||
|
|||||||
+10
-4
@@ -3,8 +3,14 @@
|
|||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"useDefineForClassFields": false,
|
"useDefineForClassFields": false,
|
||||||
"target": "ES2022",
|
"target": "ES2022",
|
||||||
"module": "ES2022",
|
"module": "NodeNext",
|
||||||
"moduleResolution": "nodenext",
|
"moduleResolution": "NodeNext",
|
||||||
"esModuleInterop": true
|
"noImplicitAny": true,
|
||||||
}
|
"esModuleInterop": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"types": ["node"]
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"dist_*/**/*.d.ts"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user