From d479cd9e7ebfa39a27356c2501c0c101e3e29769 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Fri, 21 Oct 2022 11:55:42 +0200 Subject: [PATCH] fix(core): update --- package.json | 4 ++++ pnpm-lock.yaml | 27 +++++++++++++++++++++++++++ test/test.ts | 11 +++++++++-- ts/00_commitinfo_data.ts | 2 +- ts/index.ts | 2 +- ts/smartping.classes.smartping.ts | 22 ++++++++++++++++++++++ ts/smartping.plugins.ts | 7 +++++-- 7 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 ts/smartping.classes.smartping.ts diff --git a/package.json b/package.json index c92c581..4975adc 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,10 @@ "build": "(tsbuild --web --allowimplicitany)", "buildDocs": "(tsdoc)" }, + "dependencies": { + "@types/ping": "^0.4.1", + "ping": "^0.4.2" + }, "devDependencies": { "@gitzone/tsbuild": "^2.1.25", "@gitzone/tsbundle": "^2.0.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bbe68da..9b6f092 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,12 @@ specifiers: '@gitzone/tstest': ^1.0.44 '@pushrocks/tapbundle': ^5.0.3 '@types/node': ^18.11.2 + '@types/ping': ^0.4.1 + ping: ^0.4.2 + +dependencies: + '@types/ping': 0.4.1 + ping: 0.4.2 devDependencies: '@gitzone/tsbuild': 2.1.65 @@ -1136,6 +1142,10 @@ packages: resolution: {integrity: sha512-SuT16Q1K51EAVPz1K29DJ/sXjhSQ0zjvsypYJ6tlwVsRV9jwW5Adq2ch8Dq8kDBCkYnELS7N7VNCSB5nC56t/g==} dev: true + /@types/ping/0.4.1: + resolution: {integrity: sha512-q/D+xQvoqrHvntvz2A0Pb0ImYwnN3zakluUp8O2qoogGoVMVbdY2K/ulxHcCh9TzYzVoojayHBa9gYQDIZ4v0A==} + dev: false + /@types/qs/6.9.7: resolution: {integrity: sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==} dev: true @@ -3466,6 +3476,14 @@ packages: engines: {node: '>=8.6'} dev: true + /ping/0.4.2: + resolution: {integrity: sha512-1uAw0bzHtrPbPo2s6no06oZAzY6KqKclEJR1JRZKIHKXKlPdrz9N0/1MPPB+BbrvMjN3Mk0pcod3bfLNZFRo9w==} + engines: {node: '>=4.0.0'} + dependencies: + q: 1.5.1 + underscore: 1.13.6 + dev: false + /pkg-dir/4.2.0: resolution: {integrity: sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==} engines: {node: '>=8'} @@ -3555,6 +3573,11 @@ packages: - utf-8-validate dev: true + /q/1.5.1: + resolution: {integrity: sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=} + engines: {node: '>=0.6.0', teleport: '>=0.2.0'} + dev: false + /qs/6.11.0: resolution: {integrity: sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==} engines: {node: '>=0.6'} @@ -4165,6 +4188,10 @@ packages: through: 2.3.8 dev: true + /underscore/1.13.6: + resolution: {integrity: sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A==} + dev: false + /unicode-trie/0.3.1: resolution: {integrity: sha1-1nHd3YkQGgi6w3tqUWEBBgIFIIU=} dependencies: diff --git a/test/test.ts b/test/test.ts index f649e90..2717bfc 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,8 +1,15 @@ import { expect, expectAsync, tap } from '@pushrocks/tapbundle'; import * as smartping from '../ts/index.js'; -tap.test('first test', async () => { - console.log(smartping); +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 detect alive', async () => { + await expectAsync(testPing.pingAlive('lossless.com', 1000)).toBeTrue(); +}) + tap.start(); diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 05e7576..4a0791f 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@pushrocks/smartping', - version: '1.0.4', + version: '1.0.5', description: 'a ping utility' } diff --git a/ts/index.ts b/ts/index.ts index bf17598..1ddb9aa 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,3 +1,3 @@ import * as plugins from './smartping.plugins.js'; -export let demoExport = 'Hi there! :) This is an exported string'; +export * from './smartping.classes.smartping.js'; diff --git a/ts/smartping.classes.smartping.ts b/ts/smartping.classes.smartping.ts new file mode 100644 index 0000000..18b7da8 --- /dev/null +++ b/ts/smartping.classes.smartping.ts @@ -0,0 +1,22 @@ +import * as plugins from './smartping.plugins.js'; + +export class Smartping { + public async ping(hostArg: string, timeoutArg: number = 500): Promise { + const result = await plugins.ping.promise.probe(hostArg, { + timeout: timeoutArg + }) + return result; + } + + public async pingAlive(hostArg: string, timeoutArg: number = 500): Promise { + const result = await plugins.ping.promise.probe(hostArg, { + timeout: timeoutArg + }).catch(); + //console.log(result); + if (result.alive) { + return true; + } else { + return false; + } + } +} \ No newline at end of file diff --git a/ts/smartping.plugins.ts b/ts/smartping.plugins.ts index 29aa9da..a3c17f5 100644 --- a/ts/smartping.plugins.ts +++ b/ts/smartping.plugins.ts @@ -1,2 +1,5 @@ -const removeme = {}; -export { removeme }; +import ping from 'ping'; + +export { + ping +} \ No newline at end of file