formatting

This commit is contained in:
Florian Dold 2016-10-11 22:58:40 +02:00
parent 2d7a3853a9
commit e35455435e

View File

@ -26,7 +26,7 @@
export namespace Checkable { export namespace Checkable {
type Path = (number|string)[]; type Path = (number | string)[];
interface SchemaErrorConstructor { interface SchemaErrorConstructor {
new (err: string): SchemaError; new (err: string): SchemaError;
@ -101,8 +101,8 @@ export namespace Checkable {
function checkOptional(target: any, prop: Prop, path: Path): any { function checkOptional(target: any, prop: Prop, path: Path): any {
console.assert(prop.propertyKey); console.assert(prop.propertyKey);
prop.elementChecker(target, prop.elementChecker(target,
prop.elementProp, prop.elementProp,
path.concat([prop.propertyKey])); path.concat([prop.propertyKey]));
return target; return target;
} }
@ -132,13 +132,13 @@ export namespace Checkable {
} }
let propVal = v[prop.propertyKey]; let propVal = v[prop.propertyKey];
obj[prop.propertyKey] = prop.checker(propVal, obj[prop.propertyKey] = prop.checker(propVal,
prop, prop,
path.concat([prop.propertyKey])); path.concat([prop.propertyKey]));
} }
if (remainingPropNames.size != 0) { if (remainingPropNames.size != 0) {
throw new SchemaError("superfluous properties " + JSON.stringify(Array.from( throw new SchemaError("superfluous properties " + JSON.stringify(Array.from(
remainingPropNames.values()))); remainingPropNames.values())));
} }
return obj; return obj;
} }
@ -163,10 +163,10 @@ export namespace Checkable {
function deco(target: Object, propertyKey: string | symbol): void { function deco(target: Object, propertyKey: string | symbol): void {
let chk = mkChk(target); let chk = mkChk(target);
chk.props.push({ chk.props.push({
propertyKey: propertyKey, propertyKey: propertyKey,
checker: checkValue, checker: checkValue,
type: type type: type
}); });
} }
return deco; return deco;
@ -184,11 +184,11 @@ export namespace Checkable {
function deco(target: Object, propertyKey: string | symbol): void { function deco(target: Object, propertyKey: string | symbol): void {
let chk = mkChk(target); let chk = mkChk(target);
chk.props.push({ chk.props.push({
elementChecker, elementChecker,
elementProp, elementProp,
propertyKey: propertyKey, propertyKey: propertyKey,
checker: checkList, checker: checkList,
}); });
} }
return deco; return deco;
@ -206,12 +206,12 @@ export namespace Checkable {
function deco(target: Object, propertyKey: string | symbol): void { function deco(target: Object, propertyKey: string | symbol): void {
let chk = mkChk(target); let chk = mkChk(target);
chk.props.push({ chk.props.push({
elementChecker, elementChecker,
elementProp, elementProp,
propertyKey: propertyKey, propertyKey: propertyKey,
checker: checkOptional, checker: checkOptional,
optional: true, optional: true,
}); });
} }
return deco; return deco;
@ -220,41 +220,41 @@ export namespace Checkable {
export function Number(target: Object, propertyKey: string | symbol): void { export function Number(target: Object, propertyKey: string | symbol): void {
let chk = mkChk(target); let chk = mkChk(target);
chk.props.push({propertyKey: propertyKey, checker: checkNumber}); chk.props.push({ propertyKey: propertyKey, checker: checkNumber });
} }
export function AnyObject(target: Object, export function AnyObject(target: Object,
propertyKey: string | symbol): void { propertyKey: string | symbol): void {
let chk = mkChk(target); let chk = mkChk(target);
chk.props.push({ chk.props.push({
propertyKey: propertyKey, propertyKey: propertyKey,
checker: checkAnyObject checker: checkAnyObject
}); });
} }
export function Any(target: Object, export function Any(target: Object,
propertyKey: string | symbol): void { propertyKey: string | symbol): void {
let chk = mkChk(target); let chk = mkChk(target);
chk.props.push({ chk.props.push({
propertyKey: propertyKey, propertyKey: propertyKey,
checker: checkAny, checker: checkAny,
optional: true optional: true
}); });
} }
export function String(target: Object, propertyKey: string | symbol): void { export function String(target: Object, propertyKey: string | symbol): void {
let chk = mkChk(target); let chk = mkChk(target);
chk.props.push({propertyKey: propertyKey, checker: checkString}); chk.props.push({ propertyKey: propertyKey, checker: checkString });
} }
function mkChk(target: any) { function mkChk(target: any) {
let chk = target[chkSym]; let chk = target[chkSym];
if (!chk) { if (!chk) {
chk = {props: []}; chk = { props: [] };
target[chkSym] = chk; target[chkSym] = chk;
} }
return chk; return chk;