Move assert functions to assert.ts
This commit is contained in:
39
config-serializer/assert.ts
Normal file
39
config-serializer/assert.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
function assertUInt8(target: any, key: string) {
|
||||
let val = this[key];
|
||||
if (delete this[key]) {
|
||||
Object.defineProperty(target, key, {
|
||||
get: function () {
|
||||
return val;
|
||||
},
|
||||
set: function (newVal) {
|
||||
if (newVal < 0 || newVal > 255) {
|
||||
throw `Invalid ${target.constructor.name}.${key}: ${newVal} is not uint8`;
|
||||
}
|
||||
val = newVal;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function assertEnum<E>(enumerated: E) {
|
||||
return function(target: any, key: string) {
|
||||
let val = this[key];
|
||||
if (delete this[key]) {
|
||||
Object.defineProperty(target, key, {
|
||||
get: function () {
|
||||
return val;
|
||||
},
|
||||
set: function (newVal) {
|
||||
if (enumerated[newVal] === undefined) {
|
||||
throw `Invalid ${target.constructor.name}.${key}: ${newVal} is not enum`;
|
||||
}
|
||||
val = newVal;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +1,3 @@
|
||||
function assertUInt8(target: any, key: string) {
|
||||
let val = this[key];
|
||||
if (delete this[key]) {
|
||||
Object.defineProperty(target, key, {
|
||||
get: function () {
|
||||
return val;
|
||||
},
|
||||
set: function (newVal) {
|
||||
if (newVal < 0 || newVal > 255) {
|
||||
throw `Invalid ${target.constructor.name}.${key}: ${newVal} is not uint8`;
|
||||
}
|
||||
val = newVal;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function assertEnum<E>(enumerated: E) {
|
||||
return function(target: any, key: string) {
|
||||
let val = this[key];
|
||||
if (delete this[key]) {
|
||||
Object.defineProperty(target, key, {
|
||||
get: function () {
|
||||
return val;
|
||||
},
|
||||
set: function (newVal) {
|
||||
if (enumerated[newVal] === undefined) {
|
||||
throw `Invalid ${target.constructor.name}.${key}: ${newVal} is not enum`;
|
||||
}
|
||||
val = newVal;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum Layer {
|
||||
mod,
|
||||
fn,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/// <reference path="assert.ts" />
|
||||
/// <reference path="TypeChecker.ts" />
|
||||
/// <reference path="Serializable.ts" />
|
||||
/// <reference path="UhkBuffer.ts" />
|
||||
|
||||
Reference in New Issue
Block a user