Comparing version 1.0.8 to 1.1.0
@@ -31,3 +31,3 @@ // Copyright 2021 Google LLC | ||
import SHDispatch from './SHDispatch.js'; | ||
import Test from './Test.js' | ||
/** | ||
@@ -242,2 +242,15 @@ * Creates a new SHDispatch object that represents a command to be executed. | ||
} | ||
/** | ||
* Determine a javascript type | ||
* | ||
* @param {any} fn - Any let type | ||
* @returns {string} The "real" object / typeof name | ||
*/ | ||
const jsType = (fn) => { | ||
if (fn === undefined) return 'undefined'; | ||
const type = Object.prototype.toString.call(fn).slice(8, -1); | ||
return type === 'Object' ? fn.constructor.name : type; | ||
}; | ||
export { | ||
@@ -251,3 +264,6 @@ SH, | ||
expBackoff, | ||
parseArgs | ||
parseArgs, | ||
jsType, | ||
Test, | ||
assert | ||
} |
@@ -5,3 +5,3 @@ { | ||
"type": "module", | ||
"version": "1.0.8", | ||
"version": "1.1.0", | ||
"description": "Execute shell commands on Linux-based systems from javascript", | ||
@@ -26,3 +26,2 @@ "main": "lib/SH.js", | ||
"dependencies": {}, | ||
"devDependencies": {}, | ||
"bugs": { | ||
@@ -34,2 +33,4 @@ "url": "https://codeberg.org/duin/sh/issues" | ||
"shell", | ||
"typeof", | ||
"test", | ||
"posix", | ||
@@ -52,2 +53,2 @@ "linux", | ||
] | ||
} | ||
} |
@@ -69,2 +69,5 @@ # @j-o-r/sh | ||
- `expBackoff(max, rand)`: Generate intervals for exponential backoff. | ||
- `jsType(any)`: Get the 'real' javascript variable type | ||
- `assert.`: Node assert library | ||
- `new Test()`: A small sync/async minimal test framework | ||
@@ -129,3 +132,3 @@ ## SHDispatch | ||
* @param {string} text | ||
* @retruns {Promise<string>} | ||
* @returns {Promise<string>} | ||
*/ | ||
@@ -145,4 +148,29 @@ const copyToClipboard = async (text) => { | ||
``` | ||
- Create and run a test | ||
```javascript | ||
import { assert, jsType, Test} from '@j-o-r/sh'; | ||
const test = new Test(); | ||
test.add('Test is test in sync', () => { | ||
assert.strictEqual(jsType(test), 'Test'); | ||
}); | ||
test.add('Test an Array in sync', () => { | ||
assert.strictEqual(jsType([]), 'Array'); | ||
}); | ||
test.add('Test is test in async', async () => { | ||
assert.strictEqual(jsType(test), 'Test'); | ||
}); | ||
test.add('Test is test in a promise', | ||
new Promise((resolve, _reject) => { | ||
assert.strictEqual(jsType(test), 'Test'); | ||
resolve(); | ||
}) | ||
) | ||
await test.run(); | ||
``` | ||
## License | ||
This project is licensed under the Apache License, Version 2.0. |
@@ -86,2 +86,11 @@ /** | ||
export function parseArgs(args: string[]): object; | ||
/** | ||
* Determine a javascript type | ||
* | ||
* @param {any} fn - Any let type | ||
* @returns {string} The object / let type name | ||
*/ | ||
export function jsType(fn: any): string; | ||
import Test from './Test.js'; | ||
import SHDispatch from './SHDispatch.js'; | ||
export { Test, assert }; |
47717
11
1045
174