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

classiest

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

classiest - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

readme.md

14

package.json
{
"name": "classiest",
"version": "0.0.1",
"description": "🍸 Create classes with overloadable methods, getters, setters, and statics!",
"version": "0.0.2",
"description": "🍸 Create classier classes with overloadable methods, getters, setters, and statics!",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node test.js",
"test:coverage": "nyc npm run test"
},

@@ -12,5 +13,8 @@ "author": "Francis Stokes",

"dependencies": {
"tcomb": "^3.2.29",
"tcomb-validation": "^3.4.1"
"tcomb": "^3.2.29"
},
"devDependencies": {
"nyc": "^15.1.0",
"tape": "^5.2.2"
}
}
const t = require('tcomb');
const {validate} = require('tcomb-validation');
const D = {};
D.ValidClassName = t.refinement(t.String, x => x.length > 0 && /[A-Z][a-z0-9_]*/i.test(x));
D.ValidClassName = t.refinement(t.String, x => /^[a-z][a-z0-9_]*/i.test(x));

@@ -26,3 +25,3 @@ D.ArgArray = t.list(t.Type);

const Classiest = (name, descriptorFn) => {
if (!validate(name, D.ValidClassName).isValid()) {
if (!D.ValidClassName.is(name)) {
throw new Error(`Invalid class name: ${name}`);

@@ -39,16 +38,7 @@ }

const descriptor = descriptorFn(cstr, Instance(cstr));
const validityResult = validate(descriptor, D.Defintion);
const descriptor = D.Defintion(descriptorFn(cstr, Instance(cstr)));
if (!validityResult.isValid()) {
debugger;
throw new Error(validityResult.firstError());
}
const dynamicDispatch = function(methodName, methodImpls, ...methodArgs) {
for (let {args, fn} of methodImpls) {
const matches = args.every((typeArg, i) => (
validate(methodArgs[i], typeArg).isValid()
));
const matches = args.every((typeArg, i) => typeArg.is(methodArgs[i]));
if (matches) {

@@ -110,5 +100,9 @@ return fn.apply(this, methodArgs);

if (key in setters) {
propertyDefintion.set = function (value) {
return dynamicDispatch.call(this, key, setters[key], value);
};
if (typeof setters[key] === 'function') {
propertyDefintion.set = setters[key];
} else {
propertyDefintion.set = function (value) {
return dynamicDispatch.call(this, key, setters[key], value);
};
}
}

@@ -115,0 +109,0 @@ Object.defineProperty(cstr.prototype, key, propertyDefintion);

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