* add @angular/cli to the project * increase nodejs version -> 8.2.1 * add lerna * merge web and shared module * move electron module into packages as uhk-agent Electron agent functionality is not working * delete symlinker * convert private properties to public of component if used in html * revert uhk-message.component * fix component path * fix the correct name of the uhk-message.component.scss * building web and electron module * delete uhk-renderer package * handle device connect disconnect state * add privilege detection * fix set privilege functionality * turn back download keymap functionality * add bootstrap, select2 js and fix null pointer exception * turn back upload data to keyboard * fix send keymap * fix test-serializer * add missing package.json * merging * fix appveyor build * fix linting * turn back electron storage service * commit the missing electron-datastorage-repository * update node to 8.3.0 in .nvmrc and log node version in appveyor build * set exact version number in appveyor build * vertical align privilege and missing device components * set back node version to 8 in appveyor * move node-usb dependency from usb dir to root maybe it is fix the appveyor build * revert usb to root * fix electron builder script * fix electron builder script * turn off electron devtools * remove CTRL+U functionality * fix CTRL+o * fix lint error * turnoff store freeze * start process when got `Error: EPERM: operation not permitted` error * move files from root usb dir -> packages/usb
79 lines
2.1 KiB
TypeScript
79 lines
2.1 KiB
TypeScript
export function assertUInt8(target: any, key: string) {
|
|
return assertInteger(target, key, 0, 0xFF);
|
|
}
|
|
|
|
export function assertInt8(target: any, key: string) {
|
|
return assertInteger(target, key, -0x80, 0x7F);
|
|
}
|
|
|
|
export function assertUInt16(target: any, key: string) {
|
|
return assertInteger(target, key, 0, 0xFFFF);
|
|
}
|
|
|
|
export function assertInt16(target: any, key: string) {
|
|
return assertInteger(target, key, -0x8000, 0x7FFF);
|
|
}
|
|
|
|
export function assertUInt32(target: any, key: string) {
|
|
return assertInteger(target, key, 0, 0xFFFFFFFF);
|
|
}
|
|
|
|
export function assertInt32(target: any, key: string) {
|
|
return assertInteger(target, key, -0x80000000, 0x7FFFFFFF);
|
|
}
|
|
|
|
export function assertCompactLength(target: any, key: string) {
|
|
return assertUInt16(target, key);
|
|
}
|
|
|
|
function assertInteger(target: any, key: string, min: number, max: number) {
|
|
const priv = '_' + key;
|
|
|
|
function getter() {
|
|
return this[priv];
|
|
}
|
|
|
|
function setter(newVal: any) {
|
|
if (this[priv] !== newVal) {
|
|
if (newVal < min || newVal > max) {
|
|
throw `${target.constructor.name}.${key}: ` +
|
|
`Integer ${newVal} is outside the valid [${min}, ${max}] interval`;
|
|
}
|
|
this[priv] = newVal;
|
|
}
|
|
}
|
|
|
|
Object.defineProperty(target, key, {
|
|
get: getter,
|
|
set: setter,
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
}
|
|
|
|
export function assertEnum<E>(enumerated: E) {
|
|
return function(target: any, key: string) {
|
|
const priv = '_' + key;
|
|
|
|
function getter() {
|
|
return this[priv];
|
|
}
|
|
|
|
function setter(newVal: any) {
|
|
if (this[priv] !== newVal) {
|
|
if (enumerated[newVal] === undefined) {
|
|
throw `${target.constructor.name}.${key}: ${newVal} is not enum`;
|
|
}
|
|
this[priv] = newVal;
|
|
}
|
|
}
|
|
|
|
Object.defineProperty(target, key, {
|
|
get: getter,
|
|
set: setter,
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
};
|
|
}
|