-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.mjs
More file actions
28 lines (26 loc) · 751 Bytes
/
example.mjs
File metadata and controls
28 lines (26 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { ERR_INVALID_ARG_TYPE, isNodeError } from '@flex-development/errnode'
/**
* Ensure `value` is a string.
*
* @see {@linkcode ErrInvalidArgType}
*
* @param {unknown} value
* Value supplied by user
* @param {string} name
* Name of invalid argument or property
* @return {value is string}
* `true` if `value` is a string
* @throws {import('@flex-development/errnode').ErrInvalidArgType}
* If `value` is not a string
*/
function validateString(value, name) {
if (typeof value === 'string') return true
throw new ERR_INVALID_ARG_TYPE(name, 'string', value)
}
try {
validateString(null, 'path')
} catch (e) {
console.log('isNodeError:', isNodeError(e))
console.log('TypeError:', e instanceof TypeError, '\n')
throw e
}