Comparing version 0.0.1 to 0.0.2
{ | ||
"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); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
13025
1
5
308
2
1
143
2
1
- Removedtcomb-validation@^3.4.1
- Removedtcomb-validation@3.4.1(transitive)