Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

classpass

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

classpass - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

dist/index.d.ts

43

dist/index.js
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc