Comparing version 0.1.2 to 0.1.3
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("reflect-metadata"); | ||
exports.string = 'string'; | ||
exports.number = 'number'; | ||
exports.boolean = 'boolean'; | ||
exports.ATTRS_META_KEY = 'attributes'; | ||
/** | ||
* Store the type of each attribute to the metadata | ||
* @param type Basic Javascript type (number, string, boolean) | ||
*/ | ||
function attr(type) { | ||
return (target, key) => { | ||
let attrs = Object.assign({}, Reflect.getMetadata(exports.ATTRS_META_KEY, target)); | ||
attrs[key] = type; | ||
Reflect.defineMetadata(exports.ATTRS_META_KEY, attrs, target); | ||
}; | ||
} | ||
exports.attr = attr; | ||
/** | ||
* Base class allowing for data to be passed when an instance of the | ||
* class is initialized. | ||
*/ | ||
class Model { | ||
constructor(data) { | ||
Object.assign(this, data); | ||
} | ||
} | ||
exports.Model = Model; | ||
/** Model basic type validator function */ | ||
function validate(model) { | ||
return new Promise((resolve, reject) => { | ||
let data = Reflect.getMetadata(exports.ATTRS_META_KEY, model); | ||
for (let key in model) { | ||
if (typeof model[key] !== data[key]) | ||
reject('Invalid data type'); | ||
} | ||
resolve(true); | ||
}); | ||
} | ||
__export(require("./model")); | ||
__export(require("./validate")); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "classpass", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "description": "A light-weight minimal typescript class validator for basic types (string, number and boolean)", |
@@ -1,42 +0,2 @@ | ||
import 'reflect-metadata'; | ||
export const string = 'string'; | ||
export const number = 'number'; | ||
export const boolean = 'boolean'; | ||
export const ATTRS_META_KEY = 'attributes'; | ||
/** | ||
* Store the type of each attribute to the metadata | ||
* @param type Basic Javascript type (number, string, boolean) | ||
*/ | ||
export function attr(type: string) { | ||
return (target: Object, key: string) => { | ||
let attrs = { ... Reflect.getMetadata(ATTRS_META_KEY, target) }; | ||
attrs[key] = type; | ||
Reflect.defineMetadata(ATTRS_META_KEY, attrs, target); | ||
} | ||
} | ||
/** | ||
* Base class allowing for data to be passed when an instance of the | ||
* class is initialized. | ||
*/ | ||
export abstract class Model { | ||
constructor(data?: any) { | ||
Object.assign(this, data); | ||
} | ||
} | ||
/** Model basic type validator function */ | ||
function validate(model: Object) { | ||
return new Promise((resolve, reject) => { | ||
let data = Reflect.getMetadata(ATTRS_META_KEY, model); | ||
for (let key in model) { | ||
if (typeof model[key] !== data[key]) reject('Invalid data type'); | ||
} | ||
resolve(true); | ||
}); | ||
} | ||
export * from './model'; | ||
export * from './validate'; |
@@ -11,9 +11,8 @@ { | ||
"suppressImplicitAnyIndexErrors": true, | ||
"allowSyntheticDefaultImports": true, | ||
"skipLibCheck": true | ||
"declaration": true | ||
}, | ||
"files": [ | ||
"src/index.ts" | ||
"exclude": [ | ||
"dist", | ||
"node_modules" | ||
] | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7639
20
164