-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcommon.js
More file actions
39 lines (31 loc) · 850 Bytes
/
common.js
File metadata and controls
39 lines (31 loc) · 850 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
29
30
31
32
33
34
35
36
37
38
39
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isDefined = isDefined;
exports.getOrUndefined = getOrUndefined;
exports.assert = assert;
exports.typeCheck = typeCheck;
/** @private */
function isDefined(value) {
return typeof value !== 'undefined' && value !== null;
}
/** @private */
function getOrUndefined(value) {
return isDefined(value) ? value : undefined;
}
/** @private */
function assert(condition, msg) {
if (!condition) throw TypeError(msg);
}
/** @private */
function typeCheck(values, ...types) {
types = new Set(types);
new Set(values.map(x => {
let t = typeof x;
if (t === 'object') t = x.constructor.name;
return t;
})).forEach(t => {
assert(types.has(t), `[${[...types].toString()}] 중 하나를 기대했지만 ${t} 타입이 들어왔습니다!`);
});
}