nicescript
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -20,2 +20,3 @@ const fs = require('fs'); | ||
'core/simple_types', | ||
'core/logic', | ||
'core/value', | ||
@@ -30,5 +31,5 @@ 'types/object', | ||
'types/boolean', | ||
'core/interface', | ||
// 'core/interface', | ||
'types/range', | ||
'html/tag', | ||
'html/html', | ||
'html/tags', | ||
@@ -54,1 +55,4 @@ 'html/inputs' | ||
); | ||
const nice = require('./index.js')(); | ||
fs.writeFileSync('./doc/doc.json', JSON.stringify(nice.doc())); |
@@ -72,3 +72,3 @@ nice = (...a) => { | ||
} else { | ||
type.defaultValue && item.setResult(type.defaultValue()); | ||
type.defaultValue && item.setResult(type.defaultValue(item)); | ||
type.constructor && type.constructor(item, ...a); | ||
@@ -135,3 +135,3 @@ } | ||
defineGetter: (o, n, get) => Object.defineProperty(o, n, { get }), | ||
defineGetter: (o, n, get) => Object.defineProperty(o, n, { get, enumerable: true }), | ||
@@ -153,5 +153,4 @@ with: (o, f) => o === nice | ||
nice.types[title] = type; | ||
def(nice, title, type); | ||
nice.emitAndSave('Type', type); | ||
def(nice, title, type); | ||
}, | ||
@@ -181,5 +180,7 @@ | ||
isEnvBrowser: typeof window !== 'undefined' | ||
isEnvBrowser: typeof window !== 'undefined', | ||
unwrap: v => is.nice(v) ? v() : v | ||
}); | ||
defGet = nice.defineGetter; | ||
_each = nice._each; |
@@ -9,5 +9,8 @@ const configProto = { | ||
c.returnValue = o.returnValue || this.returnValue; | ||
c.description = o.description || this.description; | ||
return c; | ||
} | ||
}, | ||
about: function(s) { return this.next({ description: s}); } | ||
}; | ||
@@ -32,2 +35,6 @@ | ||
return (...a) => this(...a.splice(0, n)); | ||
}, | ||
about: function(s) { | ||
return configurator({ description: s }); | ||
} | ||
@@ -54,6 +61,6 @@ }; | ||
function transform(s){ | ||
s.source = s.action; | ||
if(s.signature.length === 0) | ||
return s; | ||
const action = s.action; | ||
const types = s.signature; | ||
@@ -74,6 +81,6 @@ | ||
} | ||
return action(...a); | ||
return s.source(...a); | ||
}; | ||
def(s.action, 'length', action.length); | ||
def(s.action, 'length', s.source.length); | ||
@@ -88,2 +95,3 @@ return s; | ||
const res = createFunction(transform({ | ||
description: z.description, | ||
type: z.functionType, | ||
@@ -112,4 +120,10 @@ existing: z.existing, | ||
//optimization: create function that don't check fist argument for type.proto | ||
function createFunction({ existing, name, action, signature, type }){ | ||
function createFunction({ existing, name, action, source, signature, type, description }){ | ||
const target = type === 'Check' ? nice.checkFunctions : nice; | ||
if(type !== 'Check' && name && typeof name === 'string' | ||
&& name[0] !== name[0].toLowerCase()) | ||
throw "Function name should start with lowercase letter. " | ||
+ `"${nice._deCapitalize(name)}" not "${name}"`; | ||
existing = existing || (name && target[name]); | ||
@@ -137,3 +151,4 @@ const f = existing || createFunctionBody(type); | ||
} | ||
action && nice.emitAndSave('signature', {name, action, signature, type}); | ||
action && nice.emitAndSave('signature', | ||
{name, action, signature, type, description, source }); | ||
} | ||
@@ -140,0 +155,0 @@ |
@@ -9,5 +9,6 @@ const isProto = def(nice, 'isProto', {}), { Check } = nice; | ||
Check.about('Checks if two values are equal.') | ||
('equal', (a, b) => a === b || (a && a.getResult ? a.getResult() : a) === (b && b.getResult ? b.getResult() : b)) | ||
const basicChecks = { | ||
equal: (a, b) => a === b || (a && a.getResult ? a.getResult() : a) === (b && b.getResult ? b.getResult() : b), | ||
true: v => v === true, | ||
@@ -26,13 +27,13 @@ false: v => v === false, | ||
}, | ||
empty: item => { | ||
if(!item) | ||
empty: v => { | ||
if(!v) | ||
return true; | ||
if(Array.isArray(item)) | ||
return !item.length; | ||
if(Array.isArray(v)) | ||
return !v.length; | ||
if(typeof item === 'object') | ||
return !Object.keys(item).length; | ||
if(typeof v === 'object') | ||
return !Object.keys(v).length; | ||
return !item; | ||
return !v; | ||
}, | ||
@@ -59,9 +60,4 @@ subType: (a, b) => { | ||
nice._on('Type', function defineReducer(type) { | ||
type.title && Check(type.title, v => { | ||
if(v && v._type) | ||
return type.proto.isPrototypeOf(v); | ||
if(!v) | ||
return type.proto.isPrototypeOf(nice(v)); | ||
return false; | ||
}); | ||
type.title && Check(type.title, v => | ||
v && v._type ? type.proto.isPrototypeOf(v) : false); | ||
}); | ||
@@ -94,7 +90,15 @@ | ||
const actionProto = {}; | ||
nice._on('function', f => { | ||
if(f.functionType !== 'Check'){ | ||
actionProto[f.name] = function(...a){ return this.use(v => f(v, ...a)); }; | ||
} | ||
}); | ||
const delayedProto = create(nice.checkers, { | ||
check: function (f) { | ||
this._check = f; | ||
const res = delayedResult.bind(this); | ||
const res = create(actionProto, delayedResult.bind(this)); | ||
res.use = delayedUse.bind(this); | ||
@@ -105,3 +109,3 @@ return res; | ||
this._check = (...a) => a[0] === f; | ||
const res = delayedResult.bind(this); | ||
const res = create(actionProto, delayedResult.bind(this)); | ||
res.use = delayedUse.bind(this); | ||
@@ -168,3 +172,3 @@ return res; | ||
f._check = preCheck ? (...a) => preCheck(check(...a)) : check; | ||
const res = switchResult.bind(f); | ||
const res = create(actionProto, switchResult.bind(f)); | ||
res.use = switchUse.bind(f); | ||
@@ -251,3 +255,3 @@ return res; | ||
const res = delayedResult.bind(f); | ||
const res = create(actionProto, delayedResult.bind(f)); | ||
res.use = delayedUse.bind(f); | ||
@@ -254,0 +258,0 @@ return res; |
@@ -1,2 +0,2 @@ | ||
function s(title, itemTitle, parent){ | ||
function s(title, itemTitle, parent, description){ | ||
nice.Type({ | ||
@@ -6,2 +6,3 @@ title: title, | ||
creator: () => nice[itemTitle], | ||
description, | ||
proto: { | ||
@@ -14,13 +15,13 @@ _isSingleton: true, | ||
s('Nothing', 'NOTHING', 'Anything'); | ||
s('Undefined', 'UNDEFINED', 'Nothing'); | ||
s('Null', 'NULL', 'Nothing'); | ||
s('NotFound', 'NOT_FOUND', 'Nothing'); | ||
s('Fail', 'FAIL', 'Nothing'); | ||
s('NeedComputing', 'NEED_COMPUTING', 'Nothing'); | ||
s('Pending', 'PENDING', 'Nothing'); | ||
s('Stop', 'STOP', 'Nothing'); | ||
s('Nothing', 'NOTHING', 'Anything', 'Parent type for all falsy values.'); | ||
s('Undefined', 'UNDEFINED', 'Nothing', 'Wrapper for JS undefined.'); | ||
s('Null', 'NULL', 'Nothing', 'Wrapper for JS null.'); | ||
s('NotFound', 'NOT_FOUND', 'Nothing', 'Value returned by lookup functions in case nothing is found.'); | ||
s('Fail', 'FAIL', 'Nothing', 'Empty negative signal.'); | ||
s('NeedComputing', 'NEED_COMPUTING', 'Nothing', 'State of the Box in case it need some computing.'); | ||
s('Pending', 'PENDING', 'Nothing', 'State of the Box when it awaits input.'); | ||
s('Stop', 'STOP', 'Nothing', 'Value used to stop iterationin .each() and similar functions.'); | ||
s('Something', 'SOMETHING', 'Anything'); | ||
s('Ok', 'OK', 'Something'); | ||
s('Something', 'SOMETHING', 'Anything', 'Parent type for all non falsy values.'); | ||
s('Ok', 'OK', 'Something', 'Empty positive signal.'); | ||
@@ -1,6 +0,9 @@ | ||
function extend(a, b){ | ||
create(b, a); | ||
create(b.proto, a.proto); | ||
create(b.configProto, a.configProto); | ||
a.super = b; | ||
function extend(child, parent){ | ||
create(parent, child); | ||
create(parent.proto, child.proto); | ||
create(parent.configProto, child.configProto); | ||
create(parent.types, child.types); | ||
parent.defaultResult && create(parent.defaultResult, child.defaultResult); | ||
nice.emitAndSave('Extension', { child, parent }); | ||
child.super = parent; | ||
} | ||
@@ -12,2 +15,4 @@ | ||
description: 'Parent type for all types.', | ||
extend: function (...a){ | ||
@@ -34,3 +39,9 @@ return nice.Type(...a).extends(this); | ||
}, | ||
} | ||
about: function (...a) { | ||
this.target.description = nice.format(...a); | ||
return this; | ||
} | ||
}, | ||
types: {} | ||
}); | ||
@@ -77,4 +88,6 @@ | ||
config.types = {}; | ||
config.proto = config.proto || {}; | ||
config.configProto = config.configProto || {}; | ||
config.defaultResult = config.defaultResult || {}; | ||
@@ -88,5 +101,5 @@ const type = (...a) => nice.createItem({ type }, ...a); | ||
const cfg = create(config.configProto, nice.Configurator(type, '')); | ||
config.title && nice.registerType(type); | ||
return create(config.configProto, nice.Configurator(type, '')); | ||
return cfg; | ||
}, | ||
@@ -93,0 +106,0 @@ }); |
@@ -218,2 +218,25 @@ const formatRe = /(%([jds%]))/g; | ||
_deCapitalize: s => s[0].toLowerCase() + s.substr(1), | ||
doc: () => { | ||
const res = { types: {}, functions: [] }; | ||
nice._on('signature', s => { | ||
const o = {}; | ||
_each(s, (v, k) => nice.Switch(k) | ||
.equal('action')() | ||
.equal('source').use(() => o.source = v.toString()) | ||
.equal('signature').use(() => o[k] = v.map(t => t.type.title)) | ||
.default.use(() => o[k] = v)); | ||
res.functions.push(o); | ||
}); | ||
nice._on('Type', t => { | ||
const o = { title: t.title }; | ||
t.hasOwnProperty('description') && (o.description = t.description); | ||
t.extends && (o.extends = t.super.title); | ||
res.types[t.title] = o; | ||
}); | ||
return res; | ||
} | ||
}); | ||
@@ -220,0 +243,0 @@ |
@@ -75,3 +75,3 @@ nice.Type({ | ||
}, | ||
}); | ||
}).about('Parent type for all values.'); | ||
@@ -78,0 +78,0 @@ |
let autoId = 0; | ||
const Html = nice.Html; | ||
@@ -30,8 +31,9 @@ function defaultSetValue(t, v){ | ||
nice.Block('Input') | ||
Html.extend('Input') | ||
.about('Represents HTML <input> element.') | ||
.by((z, type) => attachValue(z.tag('input').attributes('type', type || 'text'))); | ||
nice.Block('Button') | ||
Html.extend('Button') | ||
.about('Represents HTML <input type="button"> element.') | ||
.by((z, text, action) => { | ||
@@ -42,3 +44,4 @@ z.tag('input').attributes({type: 'button', value: text}).on('click', action); | ||
nice.Block('Textarea') | ||
Html.extend('Textarea') | ||
.about('Represents HTML <textarea> element.') | ||
.by((z, value) => { | ||
@@ -51,7 +54,9 @@ z.tag('textarea'); | ||
nice.Block('Submit', (z, text) => | ||
z.tag('input').attributes({type: 'submit', value: text})); | ||
Html.extend('Submit') | ||
.about('Represents HTML <input type="submit"> element.') | ||
.by((z, text) => z.tag('input').attributes({type: 'submit', value: text})); | ||
nice.Block('Checkbox') | ||
Html.extend('Checkbox') | ||
.about('Represents HTML <input type="checkbox"> element.') | ||
.by((z, status) => { | ||
@@ -58,0 +63,0 @@ let node; |
@@ -1,5 +0,8 @@ | ||
'Div,I,B,Span,H1,H2,H3,H4,H5,H6,P,LI,UL,OL'.split(',').forEach(t => | ||
nice.Block(t, (z, ...cs) => z.tag(t.toLowerCase()).add(...cs))); | ||
const Html = nice.Html; | ||
nice.Block('A', (z, url, ...children) => { | ||
'Div,I,B,Span,H1,H2,H3,H4,H5,H6,P,Li,Ul,Ol,Pre'.split(',').forEach(t => | ||
Html.extend(t).by((z, ...cs) => z.tag(t.toLowerCase()).add(...cs)) | ||
.about('Represents HTML <%s> element.', t.toLowerCase())); | ||
Html.extend('A').by((z, url, ...children) => { | ||
z.tag('a'); | ||
@@ -10,5 +13,6 @@ z.add(...children); | ||
: z.href(url || '#'); | ||
}); | ||
}).about('Represents HTML <a> element.'); | ||
nice.Block('Img', (z, src) => z.tag('img').src(src)); | ||
Html.extend('Img').by((z, src) => z.tag('img').src(src)) | ||
.about('Represents HTML <img> element.'); |
{ | ||
"name": "nicescript", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"keywords": [ | ||
@@ -26,3 +26,8 @@ "util", | ||
"mocha": "latest" | ||
} | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/nicescript/nicescript" | ||
}, | ||
"homepage": "http://nicescript.org" | ||
} |
NiceScript | ||
========= | ||
[![Build Status](https://travis-ci.org/nicescript/nicescript.svg?branch=master)](https://travis-ci.org/nicescript/nicescript) | ||
A naive attempt to simplify life of a fellow JavaScript programmer. | ||
A naive attempt to simplify life of a fellow JavaScript programmer. | ||
[NiceScript.org](http://nicescript.org) | ||
[Twitter](https://twitter.com/NiceScriptJS) | ||
Example ( [JS Bin](https://jsbin.com/kenedihasi/edit?html,output) ) | ||
@@ -65,3 +67,3 @@ | ||
* [Boxes](#boxes) - to handle state changes. | ||
* [Tag](#tag) - use all above to to create html UI. | ||
* [Html](#html) - use all above to to create html UI. | ||
@@ -104,3 +106,3 @@ ### Nice values | ||
+ Array | ||
+ [Tag](#tag) | ||
+ [Html](#html) | ||
+ Single | ||
@@ -295,3 +297,3 @@ + String | ||
### Tag | ||
### Html | ||
```javascript | ||
@@ -298,0 +300,0 @@ const div = nice.Div('Normal ', 'text ') |
@@ -159,2 +159,6 @@ let nice = require('../index.js')(); | ||
it("intersperse", () => { | ||
expect(nice(1, 2).intersperse('-')()).to.deep.equal([1, '-', 2]); | ||
}); | ||
}); |
@@ -11,3 +11,3 @@ const nice = require('../index.js')(); | ||
expect(is.subType(nice.Boolean, nice.Single)).to.equal(true); | ||
var n = nice.Boolean(); | ||
const n = nice.Boolean(); | ||
expect(n._type.title).to.equal('Boolean'); | ||
@@ -18,3 +18,3 @@ }); | ||
it("empty constructor", function(){ | ||
var s = nice.Boolean(); | ||
const s = nice.Boolean(); | ||
expect(s()).to.equal(false); | ||
@@ -25,3 +25,3 @@ }); | ||
it("constructor", function(){ | ||
var b = nice.Boolean(1); | ||
const b = nice.Boolean(1); | ||
expect(b()).to.equal(true); | ||
@@ -32,94 +32,6 @@ }); | ||
it("set", function(){ | ||
var b = nice.Boolean(); | ||
const b = nice.Boolean(); | ||
b(2); | ||
expect(b()).to.equal(true); | ||
}); | ||
// it("switch", function(){ | ||
// var b = nice.Boolean(); | ||
// expect(b()).to.equal(false); | ||
// b.switch(); | ||
// expect(b()).to.equal(true); | ||
// expect(b.turnOff()()).to.equal(false); | ||
// expect(b.turnOn()()).to.equal(true); | ||
// }); | ||
it("and", function(){ | ||
let on = nice.Boolean(true); | ||
let off = nice.Boolean(false); | ||
expect(on.and(true)()).to.equal(true); | ||
expect(on.and(false)()).to.equal(false); | ||
expect(off.and(true)()).to.equal(false); | ||
expect(off.and(false)()).to.equal(false); | ||
}); | ||
it("or", function(){ | ||
let on = nice.Boolean(true); | ||
let off = nice.Boolean(false); | ||
expect(on.or(true)()).to.equal(true); | ||
expect(on.or(false)()).to.equal(true); | ||
expect(off.or(true)()).to.equal(true); | ||
expect(off.or(false)()).to.equal(false); | ||
}); | ||
it("nor", function(){ | ||
let on = nice.Boolean(true); | ||
let off = nice.Boolean(false); | ||
expect(on.nor(true)()).to.equal(false); | ||
expect(on.nor(false)()).to.equal(false); | ||
expect(off.nor(true)()).to.equal(false); | ||
expect(off.nor(false)()).to.equal(true); | ||
}); | ||
it("xor", function(){ | ||
let on = nice.Boolean(true); | ||
let off = nice.Boolean(false); | ||
expect(on.xor(true)()).to.equal(false); | ||
expect(on.xor(false)()).to.equal(true); | ||
expect(off.xor(true)()).to.equal(true); | ||
expect(off.xor(false)()).to.equal(false); | ||
}); | ||
}); | ||
// it("bind", function(){ | ||
// let a = Box(5); | ||
// let b = Box(); | ||
// | ||
// a.bind(b); | ||
// | ||
// expect(b()).to.equal(5); | ||
// | ||
// a(6); | ||
// expect(a()).to.equal(6); | ||
// expect(b()).to.equal(6); | ||
// | ||
// b(44); | ||
// expect(a()).to.equal(44); | ||
// expect(b()).to.equal(44); | ||
// }); | ||
// | ||
// | ||
// it("unbind", function(){ | ||
// let a = Box(5); | ||
// let b = Box; | ||
// | ||
// a.bind(b); | ||
// | ||
// expect(b()).to.equal(5); | ||
// | ||
// a.unbind(b); | ||
// | ||
// a(6); | ||
// expect(a()).to.equal(6); | ||
// expect(b()).to.equal(5); | ||
// | ||
// b(44); | ||
// expect(a()).to.equal(6); | ||
// expect(b()).to.equal(44); | ||
// }); |
@@ -125,9 +125,2 @@ let nice = require('../index.js')(); | ||
// it("error", function(){ | ||
// let a = Box().error('Qwe'); | ||
// expect(is.Error(a())).to.equal(true); | ||
// expect(a().message).to.equal('Qwe'); | ||
// }); | ||
it("transaction", function(){ | ||
@@ -252,2 +245,10 @@ let a = Box(); | ||
it("resolve children 3", function(done){ | ||
nice.resolveChildren({}, function (v) { | ||
expect(v).to.deep.equal({}); | ||
done(); | ||
}); | ||
}); | ||
it("values's transformation", function(){ | ||
@@ -254,0 +255,0 @@ let a = Box(2); |
@@ -1,13 +0,13 @@ | ||
var nice = require('../index.js')(); | ||
var chai = require('chai'); | ||
const nice = require('../index.js')(); | ||
const chai = require('chai'); | ||
chai.use(require('chai-spies')); | ||
var expect = require('chai').expect; | ||
const expect = require('chai').expect; | ||
describe("Events", function() { | ||
var newEmmiter = () => nice.eventEmitter({}); | ||
const newEmmiter = () => nice.eventEmitter({}); | ||
it("add listener", function() { | ||
var f = () => {}; | ||
var spy = chai.spy(); | ||
var item = newEmmiter()._on('newListener', spy)._on('fiesta', f); | ||
const f = () => {}; | ||
const spy = chai.spy(); | ||
const item = newEmmiter()._on('newListener', spy)._on('fiesta', f); | ||
expect(item.listeners('fiesta')).to.deep.equal([f]); | ||
@@ -19,5 +19,5 @@ expect(spy).to.have.been.called.with('fiesta', f); | ||
it("remove listener", function() { | ||
var f = () => {}; | ||
var spy = chai.spy(); | ||
var item = newEmmiter()._on('removeListener', spy)._on('fiesta', f); | ||
const f = () => {}; | ||
const spy = chai.spy(); | ||
const item = newEmmiter()._on('removeListener', spy)._on('fiesta', f); | ||
@@ -35,5 +35,5 @@ expect(item.listeners('fiesta')).to.deep.equal([f]); | ||
it("removeAll listener", function() { | ||
var f = () => {}; | ||
var spy = chai.spy(); | ||
var item = newEmmiter()._on('removeListener', spy)._on('fiesta', f); | ||
const f = () => {}; | ||
const spy = chai.spy(); | ||
const item = newEmmiter()._on('removeListener', spy)._on('fiesta', f); | ||
@@ -49,4 +49,4 @@ expect(item.listeners('fiesta')).to.deep.equal([f]); | ||
it("double add listener", function() { | ||
var f = () => {}; | ||
var item = newEmmiter()._on('fiesta', f)._on('fiesta', f); | ||
const f = () => {}; | ||
const item = newEmmiter()._on('fiesta', f)._on('fiesta', f); | ||
expect(item.listeners('fiesta')).to.deep.equal([f]); | ||
@@ -57,4 +57,4 @@ }); | ||
it("emit", function() { | ||
var spy = chai.spy(); | ||
var item = newEmmiter()._on('fiesta', spy); | ||
const spy = chai.spy(); | ||
const item = newEmmiter()._on('fiesta', spy); | ||
item.emit('fiesta', 'today'); | ||
@@ -67,4 +67,4 @@ | ||
it("emitAndSave", function() { | ||
var spy = chai.spy(); | ||
var item = newEmmiter(); | ||
const spy = chai.spy(); | ||
const item = newEmmiter(); | ||
item.emitAndSave('fiesta', 'today'); | ||
@@ -78,6 +78,6 @@ item._on('fiesta', spy); | ||
it("inheritance", function() { | ||
var spy1 = chai.spy(); | ||
var spy2 = chai.spy(); | ||
var a = nice.eventEmitter({}); | ||
var b = Object.setPrototypeOf({}, a); | ||
const spy1 = chai.spy(); | ||
const spy2 = chai.spy(); | ||
const a = nice.eventEmitter({}); | ||
const b = Object.setPrototypeOf({}, a); | ||
@@ -84,0 +84,0 @@ a._on('fiesta', function(e) { spy1(this, e); } ); |
@@ -1,5 +0,5 @@ | ||
var nice = require('../index.js')(); | ||
var chai = require('chai'); | ||
const nice = require('../index.js')(); | ||
const chai = require('chai'); | ||
chai.use(require('chai-spies')); | ||
var expect = chai.expect; | ||
const expect = chai.expect; | ||
@@ -30,4 +30,4 @@ describe("expect", function() { | ||
var cat = nice.Cat().name('Ball'); | ||
var dog = nice.Dog(); | ||
const cat = nice.Cat().name('Ball'); | ||
const dog = nice.Dog(); | ||
expect(() => nice.expect(cat).Car()).to.throw(); | ||
@@ -34,0 +34,0 @@ expect(() => nice.expect(cat).Cat()).not.to.throw(); |
@@ -1,12 +0,12 @@ | ||
var nice = require('../index.js')(); | ||
var chai = require('chai'); | ||
const nice = require('../index.js')(); | ||
const chai = require('chai'); | ||
chai.use(require('chai-spies')); | ||
var expect = chai.expect; | ||
const expect = chai.expect; | ||
describe("Function", function() { | ||
var a = nice.Type('AAA')(); | ||
var b = nice.Type('BBB').extends('AAA')(); | ||
const a = nice.Type('AAA')(); | ||
const b = nice.Type('BBB').extends('AAA')(); | ||
it("type", () => { | ||
var f = nice.Function(() => 2); | ||
const f = nice.Function(() => 2); | ||
expect(nice.is(f).Something()).to.equal(true); | ||
@@ -17,5 +17,5 @@ expect(nice.is(f).Value()).to.equal(false); | ||
it("simple", () => { | ||
var f = nice.Function(() => 2); | ||
const f = nice.Function(() => 2); | ||
var res = f(); | ||
const res = f(); | ||
expect(res).to.equal(2); | ||
@@ -37,3 +37,3 @@ }); | ||
it("deafault", () => { | ||
var f = nice.Function(function qwedsd(){return 1;}); | ||
const f = nice.Function(function qwedsd(){return 1;}); | ||
expect(f()).to.equal(1); | ||
@@ -45,3 +45,3 @@ expect(nice.qwedsd()).to.equal(1); | ||
it("overload", () => { | ||
var f = nice.Function() | ||
const f = nice.Function() | ||
.string(s => s + s) | ||
@@ -55,5 +55,5 @@ .number(n => n * 2); | ||
it("first parameter's type method", () => { | ||
var qwe = nice.Type('Qwe456'); | ||
const qwe = nice.Type('Qwe456'); | ||
nice.Function.Qwe456(function zzzz(){return 1;}); | ||
var s = nice.Qwe456(); | ||
const s = nice.Qwe456(); | ||
expect(s.zzzz()).to.equal(1); | ||
@@ -65,3 +65,3 @@ }); | ||
nice.Function.AAA(function hhhh(){return 1;}); | ||
var s = nice.BBB(); | ||
const s = nice.BBB(); | ||
expect(s.hhhh()).to.equal(1); | ||
@@ -72,4 +72,4 @@ }); | ||
it("second parameter", () => { | ||
var f = nice.Function.string.object('qqqqqqq', () => 1); | ||
var f2 = nice.Function.string.array('qqqqqqq', () => 2); | ||
const f = nice.Function.string.object('qqqqqqq', () => 1); | ||
const f2 = nice.Function.string.array('qqqqqqq', () => 2); | ||
@@ -89,6 +89,6 @@ expect(f).to.equal(f2); | ||
it("second parameter 2", () => { | ||
var f = nice.Function | ||
const f = nice.Function | ||
.String.object('qqqqzzz', () => 11) | ||
.String.array('qqqqzzz', () => 22); | ||
var s = nice.String(); | ||
const s = nice.String(); | ||
@@ -126,3 +126,3 @@ expect(f(s, {})).to.equal(11); | ||
it("skip", () => { | ||
var f = nice.Function((a, b) => a / b); | ||
const f = nice.Function((a, b) => a / b); | ||
expect(f(6, 2)).to.equal(3); | ||
@@ -136,5 +136,5 @@ expect(f(6, nice)(3)).to.equal(2); | ||
it("skip queue", () => { | ||
var f = nice.Function((a, b) => nice.Number(a / b)); | ||
const f = nice.Function((a, b) => nice.Number(a / b)); | ||
nice.Function.Number('qwe', (v, n) => nice.Number(v() + n)); | ||
var f2 = f(10, nice); | ||
const f2 = f(10, nice); | ||
@@ -149,3 +149,3 @@ expect(f2.qwe(2)(5)()).to.equal(4); | ||
it("ary", () => { | ||
var f = nice.Function((a = 1, b = 2, c = 3) => '' + a + b + c); | ||
const f = nice.Function((a = 1, b = 2, c = 3) => '' + a + b + c); | ||
@@ -160,3 +160,3 @@ expect(f.ary(0)(4, 4, 4)).to.equal('123'); | ||
it("curry", () => { | ||
var f = nice.curry((a, b, c) => { | ||
const f = nice.curry((a, b, c) => { | ||
return a + b + c; | ||
@@ -163,0 +163,0 @@ }); |
@@ -1,5 +0,5 @@ | ||
var nice = require('../index.js')(); | ||
var chai = require('chai'); | ||
const nice = require('../index.js')(); | ||
const chai = require('chai'); | ||
chai.use(require('chai-spies')); | ||
var expect = chai.expect; | ||
const expect = chai.expect; | ||
@@ -52,9 +52,2 @@ describe("is", function() { | ||
// it("or", function(){ | ||
// expect(is.Number.or.String('5')).to.equal(true); | ||
// expect(is.Number.or.String(5)).to.equal(true); | ||
// expect(is.Number.or.String({})).to.equal(false); | ||
// }); | ||
it("isEmpty", function() { | ||
@@ -72,17 +65,17 @@ expect(is.empty('')).to.equal(true); | ||
it("primitive Nothing", function() { | ||
expect(nice.is.Null(null)).to.equal(true); | ||
expect(nice.is.Nothing(null)).to.equal(true); | ||
expect(nice.is.Nothing(0)).to.equal(false); | ||
expect(is.null(null)).to.equal(true); | ||
expect(is.Null(null)).to.equal(false); | ||
expect(is.Nothing(null)).to.equal(false); | ||
expect(is.Nothing(0)).to.equal(false); | ||
}); | ||
it("nice", function() { | ||
expect(nice.is.nice(1)).to.equal(false); | ||
expect(nice.is.nice(nice.Number())).to.equal(true); | ||
expect(is.nice(1)).to.equal(false); | ||
expect(is.nice(nice.Number())).to.equal(true); | ||
}); | ||
it("js types", function() { | ||
expect(nice.is.regExp(/.*/)).to.equal(true); | ||
expect(nice.is.arrayBuffer(/.*/)).to.equal(false); | ||
expect(is.regExp(/.*/)).to.equal(true); | ||
expect(is.arrayBuffer(/.*/)).to.equal(false); | ||
}); | ||
}); |
@@ -9,27 +9,27 @@ const nice = require('../index.js')(); | ||
it("name uniqe", () => { | ||
expect(() => nice.Interface('Array')).to.throw(); | ||
}); | ||
// it("name uniqe", () => { | ||
// expect(() => nice.Interface('Array')).to.throw(); | ||
// }); | ||
// | ||
// | ||
// it("existing type", () => { | ||
// nice.Interface('Usable', 'use'); | ||
// expect(nice.is(nice.Box).Usable()).to.equal(true); | ||
// }); | ||
// | ||
// | ||
// it("new type", () => { | ||
// nice.Type('Dog'); | ||
// const i = nice.Interface('Walkable', 'walk'); | ||
// const dog = nice.Dog(); | ||
// | ||
// expect(is(nice.Dog).Walkable()).to.equal(false); | ||
// expect(is(dog).Walkable()).to.equal(false); | ||
// | ||
// nice.Function.Dog('walk', () => 1); | ||
// | ||
// expect(is(nice.Dog).Walkable()).to.equal(true); | ||
// expect(is(dog).Walkable()).to.equal(true); | ||
// }); | ||
it("existing type", () => { | ||
nice.Interface('Usable', 'use'); | ||
expect(nice.is(nice.Box).Usable()).to.equal(true); | ||
}); | ||
it("new type", () => { | ||
nice.Type('Dog'); | ||
const i = nice.Interface('Walkable', 'walk'); | ||
const dog = nice.Dog(); | ||
expect(is(nice.Dog).Walkable()).to.equal(false); | ||
expect(is(dog).Walkable()).to.equal(false); | ||
nice.Function.Dog('walk', () => 1); | ||
expect(is(nice.Dog).Walkable()).to.equal(true); | ||
expect(is(dog).Walkable()).to.equal(true); | ||
}); | ||
}); |
@@ -1,5 +0,5 @@ | ||
var nice = require('../index.js')(); | ||
var chai = require('chai'); | ||
const nice = require('../index.js')(); | ||
const chai = require('chai'); | ||
chai.use(require('chai-spies')); | ||
var expect = chai.expect; | ||
const expect = chai.expect; | ||
@@ -10,3 +10,3 @@ describe("Number", function() { | ||
expect(nice.Number.isSubType(nice.Single)).to.equal(true); | ||
var n = nice.Number(); | ||
const n = nice.Number(); | ||
expect(n._type.title).to.equal('Number'); | ||
@@ -18,3 +18,3 @@ expect(n.is.Number()).to.equal(true); | ||
it("empty constructor", function(){ | ||
var s = nice.Number(); | ||
const s = nice.Number(); | ||
expect(s()).to.equal(0); | ||
@@ -25,3 +25,3 @@ }); | ||
it("constructor", function(){ | ||
var n = nice.Number("7"); | ||
const n = nice.Number("7"); | ||
expect(n()).to.equal(7); | ||
@@ -32,3 +32,3 @@ }); | ||
it("setter", function(){ | ||
var n = nice.Number(); | ||
const n = nice.Number(); | ||
n("7"); | ||
@@ -41,3 +41,3 @@ | ||
it("negate", function(){ | ||
var n = nice.Number(7); | ||
const n = nice.Number(7); | ||
n.negate(); | ||
@@ -48,9 +48,9 @@ expect(n()).to.equal(-7); | ||
// it("basic operations", function(){ | ||
// expect(nice.Number(7).product(-1)()).to.equal(-7); | ||
// }); | ||
it("basic operations", function(){ | ||
expect(nice.Number(7).product(-1)()).to.equal(-7); | ||
}); | ||
it("Math", function(){ | ||
var n = nice.Number(); | ||
const n = nice.Number(); | ||
n("7"); | ||
@@ -57,0 +57,0 @@ |
@@ -1,5 +0,5 @@ | ||
var nice = require('../index.js')(); | ||
var chai = require('chai'); | ||
const nice = require('../index.js')(); | ||
const chai = require('chai'); | ||
chai.use(require('chai-spies')); | ||
var expect = chai.expect; | ||
const expect = chai.expect; | ||
@@ -9,3 +9,3 @@ describe("Object", function() { | ||
it("constructor", function() { | ||
var a = nice({asd: 3}); | ||
const a = nice({asd: 3}); | ||
expect(nice.fromItem(a)).to.deep.equal({asd:3}); | ||
@@ -16,3 +16,3 @@ }); | ||
it("set / get primitive", function() { | ||
var a = nice(); | ||
const a = nice(); | ||
a.set('qwe', 1); | ||
@@ -24,4 +24,12 @@ expect(a('qwe')()).to.equal(1); | ||
it("set / get with nice.String as key", function() { | ||
const a = nice(); | ||
a.set('qwe', 1); | ||
expect(a(nice('qwe'))()).to.equal(1); | ||
expect(a.get(nice('qwe'))()).to.equal(1); | ||
}); | ||
it("set deep", function() { | ||
var a = nice(); | ||
const a = nice(); | ||
a.set(['qwe', 'asd'], 1); | ||
@@ -34,3 +42,3 @@ expect(a('qwe')()).to.deep.equal({asd:1}); | ||
it("has", function() { | ||
var a = nice(); | ||
const a = nice(); | ||
a.set('qwe', 0).set('zxc', 1); | ||
@@ -44,3 +52,3 @@ expect(a.has('qwe')()).to.equal(true); | ||
it("has", function() { | ||
var a = nice(); | ||
const a = nice(); | ||
a.set(['qwe', 'asd'], 1); | ||
@@ -55,6 +63,6 @@ expect(a.has(['qwe', 'asd'])()).to.equal(true); | ||
o('qwe', {'': 1}); | ||
// expect(o.get('qwe')()).to.deep.equal({'':1}); | ||
// expect(o.get(['qwe', ''])()).to.deep.equal(1); | ||
// o('asd', {'zxc': {'': 2}}); | ||
// expect(o.get(['asd', 'zxc'])()).to.deep.equal({'':2}); | ||
expect(o.get('qwe')()).to.deep.equal({'':1}); | ||
expect(o.get(['qwe', ''])()).to.deep.equal(1); | ||
o('asd', {'zxc': {'': 2}}); | ||
expect(o.get(['asd', 'zxc'])()).to.deep.equal({'':2}); | ||
}); | ||
@@ -64,4 +72,4 @@ | ||
it("set / get container", function() { | ||
var a = nice(); | ||
var b = nice(); | ||
const a = nice(); | ||
const b = nice(); | ||
b.set('asd', 2); | ||
@@ -75,3 +83,3 @@ a.set('qwe', b); | ||
it("remove", function() { | ||
var a = nice({qwe: 1, asd: 3}); | ||
const a = nice({qwe: 1, asd: 3}); | ||
a.remove('qwe'); | ||
@@ -84,3 +92,3 @@ expect(a()).to.deep.equal({asd:3}); | ||
it("removeAll", () => { | ||
var a = nice({qwe: 1, asd: 3}); | ||
const a = nice({qwe: 1, asd: 3}); | ||
a.removeAll(); | ||
@@ -92,5 +100,5 @@ expect(a.getResult()).to.deep.equal({}); | ||
it("Standalone class", function() { | ||
var Cat = nice.Type().String('name')(); | ||
const Cat = nice.Type().String('name')(); | ||
var ball = Cat().name('Ball'); | ||
const ball = Cat().name('Ball'); | ||
expect(ball.name()).to.equal('Ball'); | ||
@@ -103,4 +111,4 @@ expect(ball.name.is('Ball')).to.equal(true); | ||
it("Setting all data", function() { | ||
var type = nice.Type().String('name')(); | ||
var cat = type({name: 'Ball'}); | ||
const type = nice.Type().String('name')(); | ||
const cat = type({name: 'Ball'}); | ||
expect(cat.name()).to.equal('Ball'); | ||
@@ -113,3 +121,3 @@ }); | ||
var cat = nice.Cat().name('Ball'); | ||
const cat = nice.Cat().name('Ball'); | ||
expect(cat._type.title).to.equal('Cat'); | ||
@@ -121,4 +129,4 @@ expect(cat.name()).to.equal('Ball'); | ||
it("Value", function() { | ||
var City = nice.Type().Single('price')(); | ||
var city = City(); | ||
const City = nice.Type().Single('price')(); | ||
const city = City(); | ||
city({price: "50$"}); | ||
@@ -132,7 +140,7 @@ expect(city.price()).to.equal('50$'); | ||
it("by", function() { | ||
var Cat = nice.Type() | ||
const Cat = nice.Type() | ||
.String('name') | ||
.by((z, name) => z.name(name))(); | ||
var cat = Cat('Ball'); | ||
const cat = Cat('Ball'); | ||
expect(cat.name()).to.equal('Ball'); | ||
@@ -152,11 +160,13 @@ }); | ||
it("Inheritance", function() { | ||
var A = nice.Type().Number('x')(); | ||
const A = nice.Type().Number('x')(); | ||
var B = nice.Type() | ||
const B = nice.Type() | ||
.Number('y') | ||
.extends(A)(); | ||
var b = B().x(5).y(10); | ||
const b = B().x(5).y(10); | ||
expect(b.y()).to.equal(10); | ||
expect(b.get('y')()).to.equal(10); | ||
expect(b.x()).to.equal(5); | ||
expect(b.get('x')()).to.equal(5); | ||
}); | ||
@@ -179,3 +189,3 @@ | ||
var dog = nice.Dog('Ball').weight(10); | ||
const dog = nice.Dog('Ball').weight(10); | ||
expect(dog.name()).to.equal('Ball'); | ||
@@ -193,4 +203,4 @@ expect(dog.weight()).to.equal(10); | ||
var g1 = nice.Gate().items(2); | ||
var g2 = nice.Gate(); | ||
const g1 = nice.Gate().items(2); | ||
const g2 = nice.Gate(); | ||
@@ -204,6 +214,6 @@ expect(g1.items === g2.items).to.equal(false); | ||
it("itemBy", function() { | ||
var City = nice.Type() | ||
const City = nice.Type() | ||
.Number('height') | ||
.by(z => z.height(20))(); | ||
var city = City(); | ||
const city = City(); | ||
expect(city()).to.deep.equal({ height: 20 }); | ||
@@ -214,5 +224,5 @@ }); | ||
it("Object property", function() { | ||
var City = nice.Type() | ||
const City = nice.Type() | ||
.Object('streets')(); | ||
var city = City(); | ||
const city = City(); | ||
city.streets('Main', 1); | ||
@@ -224,3 +234,3 @@ expect(city.streets('Main')()).to.equal(1); | ||
it("values", function() { | ||
var a = nice(); | ||
const a = nice(); | ||
a.set('qwe', 3); | ||
@@ -234,3 +244,3 @@ a.set('ad', 2); | ||
it("reduce", function(){ | ||
var c = nice.Object({qwe: 1, ads: 3}); | ||
const c = nice.Object({qwe: 1, ads: 3}); | ||
expect(c.reduce((sum, n) => sum + n, 3)()).to.equal(7); | ||
@@ -241,4 +251,4 @@ }); | ||
it("reduceTo", function() { | ||
var c = nice.Object({qwe: 1, ads: 3}); | ||
var a = nice.Number(); | ||
const c = nice.Object({qwe: 1, ads: 3}); | ||
const a = nice.Number(); | ||
@@ -251,4 +261,4 @@ expect(c.reduceTo(a, (z, v) => z.inc(v))).to.equal(a); | ||
it("reduceTo.Type", function() { | ||
var c = nice.Object({qwe: 1, ads: 3}); | ||
var a = c.reduceTo.Number((z, v) => z.inc(v)); | ||
const c = nice.Object({qwe: 1, ads: 3}); | ||
const a = c.reduceTo.Number((z, v) => z.inc(v)); | ||
expect(a.is.Number()).to.equal(true); | ||
@@ -260,3 +270,3 @@ expect(a()).to.equal(4); | ||
it("sum", function() { | ||
var a = nice.Object({qwe: 1, ads: 3}); | ||
const a = nice.Object({qwe: 1, ads: 3}); | ||
expect(a.sum()()).to.equal(4); | ||
@@ -267,3 +277,3 @@ }); | ||
it("some", function() { | ||
var o = nice.Object({qwe: 1, ads: 3}); | ||
const o = nice.Object({qwe: 1, ads: 3}); | ||
expect(o.is.some(n => n > 5)).to.equal(false); | ||
@@ -275,3 +285,3 @@ expect(o.is.some(n => n > 2)).to.equal(true); | ||
it("find", () => { | ||
var c = nice.Object({qwe: 1, ads: 4}); | ||
const c = nice.Object({qwe: 1, ads: 4}); | ||
expect(c.find(n => n % 2 === 0)()).to.equal(4); | ||
@@ -282,3 +292,3 @@ }); | ||
it("findKey", () => { | ||
var c = nice.Object({qwe: 1, ads: 4}); | ||
const c = nice.Object({qwe: 1, ads: 4}); | ||
expect(c.findKey(n => n % 2 === 0)()).to.equal('ads'); | ||
@@ -289,3 +299,3 @@ }); | ||
it("every", function() { | ||
var a = nice.Object({qwe: 1, ads: 3}); | ||
const a = nice.Object({qwe: 1, ads: 3}); | ||
expect(a.is.every(n => n > 2)).to.equal(false); | ||
@@ -303,3 +313,3 @@ expect(a.is.every(n => n > 0)).to.equal(true); | ||
it("map", function() { | ||
var a = nice(); | ||
const a = nice(); | ||
a.set('qwe', 3); | ||
@@ -314,3 +324,3 @@ a.set('ad', 2); | ||
it("itemsType", function() { | ||
var a = nice().itemsType(nice.Number); | ||
const a = nice().itemsType(nice.Number); | ||
a.set('qwe', 3); | ||
@@ -325,3 +335,3 @@ a.set('ad', '2'); | ||
it("count", () => { | ||
var a = nice.Array(1, 2, 3, 4, 5); | ||
const a = nice.Array(1, 2, 3, 4, 5); | ||
expect(a.count(n => n() % 2)()).to.equal(3); | ||
@@ -342,3 +352,3 @@ }); | ||
it("filter", () => { | ||
var a = nice.Object({qwe: 1, asd: 2}); | ||
const a = nice.Object({qwe: 1, asd: 2}); | ||
expect(a.filter(n => n() % 2)()).to.deep.equal({qwe:1}); | ||
@@ -348,9 +358,17 @@ }); | ||
it("default object values for property", () => { | ||
const t = nice.Type('Site') | ||
.Object('urls', {qwe:1}) | ||
.Array('pages', ['qwe']) | ||
(); | ||
expect(t().urls('qwe')()).to.equal(1); | ||
expect(t().pages.get(0)()).to.equal('qwe'); | ||
}); | ||
// it("includes", function() { | ||
// var a = nice.Object({qwe: 1, ads: 3}); | ||
// expect(a.includes(7)).to.equal(false); | ||
// expect(a.includes(1)).to.equal(true); | ||
// const a = nice.Object({qwe: 1, ads: 3}); | ||
// expect(a.is.includes(7)).to.equal(false); | ||
// expect(a.is.includes(1)).to.equal(true); | ||
// }); | ||
}); |
@@ -1,9 +0,9 @@ | ||
var nice = require('../index.js')(); | ||
var chai = require('chai'); | ||
const nice = require('../index.js')(); | ||
const chai = require('chai'); | ||
chai.use(require('chai-spies')); | ||
var expect = chai.expect; | ||
const expect = chai.expect; | ||
describe("Array", function() { | ||
it("includes", function() { | ||
var r = nice.Range(1, 6); | ||
const r = nice.Range(1, 6); | ||
@@ -16,3 +16,3 @@ expect(r.is.includes(5)).to.equal(true); | ||
it("within", function() { | ||
var r = nice.Range(1, 5); | ||
const r = nice.Range(1, 5); | ||
expect(nice.Number(5).within(r)).to.equal(true); | ||
@@ -19,0 +19,0 @@ expect(nice.Number(15).within(r)).to.equal(false); |
@@ -1,5 +0,5 @@ | ||
var nice = require('../index.js')(); | ||
var chai = require('chai'); | ||
const nice = require('../index.js')(); | ||
const chai = require('chai'); | ||
chai.use(require('chai-spies')); | ||
var expect = chai.expect; | ||
const expect = chai.expect; | ||
@@ -83,3 +83,3 @@ describe("Simple types", function() { | ||
it("is", function(){ | ||
var a = nice.Single(0); | ||
const a = nice.Single(0); | ||
// expect(a.is()).to.equal(false); | ||
@@ -86,0 +86,0 @@ a(1); |
@@ -1,5 +0,5 @@ | ||
var nice = require('../index.js')(); | ||
var chai = require('chai'); | ||
const nice = require('../index.js')(); | ||
const chai = require('chai'); | ||
chai.use(require('chai-spies')); | ||
var expect = chai.expect; | ||
const expect = chai.expect; | ||
@@ -9,3 +9,3 @@ describe("Single", function() { | ||
it("constructor", function(){ | ||
var s = nice.Single(2); | ||
const s = nice.Single(2); | ||
expect(s()).to.equal(2); | ||
@@ -23,4 +23,4 @@ }); | ||
}); | ||
it("does not have objects methods", function(){ | ||
@@ -31,12 +31,2 @@ let s = nice.Single(); | ||
}); | ||
// it("_set", function(){ | ||
// var s = nice.Single.by((a, b) => a * b); | ||
// s(2, 3); | ||
// expect(s()).to.equal(6); | ||
// }); | ||
}); |
@@ -1,5 +0,5 @@ | ||
var nice = require('../index.js')(); | ||
var chai = require('chai'); | ||
const nice = require('../index.js')(); | ||
const chai = require('chai'); | ||
chai.use(require('chai-spies')); | ||
var expect = chai.expect; | ||
const expect = chai.expect; | ||
@@ -10,3 +10,3 @@ describe("String", function() { | ||
expect(nice.String.isSubType(nice.Single)).to.equal(true); | ||
var s = nice.String(); | ||
const s = nice.String(); | ||
expect(s._type.title).to.equal('String'); | ||
@@ -16,3 +16,3 @@ }); | ||
it("empty constructor", function(){ | ||
var s = nice.String(); | ||
const s = nice.String(); | ||
expect(s()).to.equal(''); | ||
@@ -23,3 +23,3 @@ }); | ||
it("constructor", function(){ | ||
var s = nice.String(2); | ||
const s = nice.String(2); | ||
expect(s()).to.equal('2'); | ||
@@ -30,3 +30,3 @@ }); | ||
it("set", function(){ | ||
var s = nice.String(); | ||
const s = nice.String(); | ||
@@ -42,3 +42,3 @@ s(2); | ||
it("format", function(){ | ||
var s = nice.String('Hello %s', 'world'); | ||
const s = nice.String('Hello %s', 'world'); | ||
expect(s()).to.equal('Hello world'); | ||
@@ -45,0 +45,0 @@ }); |
@@ -10,7 +10,7 @@ const nice = require('../index.js')(); | ||
it("switch", function() { | ||
var spy1 = chai.spy(); | ||
var spy2 = chai.spy(); | ||
var spy3 = chai.spy(); | ||
const spy1 = chai.spy(); | ||
const spy2 = chai.spy(); | ||
const spy3 = chai.spy(); | ||
var s = Switch('qwe') | ||
const s = Switch('qwe') | ||
.number.use(spy1) | ||
@@ -32,6 +32,6 @@ .string.use((...a) => { | ||
it("switch equal", function() { | ||
var spy1 = chai.spy(); | ||
var spy3 = chai.spy(); | ||
const spy1 = chai.spy(); | ||
const spy3 = chai.spy(); | ||
var s = Switch('qwe') | ||
const s = Switch('qwe') | ||
.number.use(spy1) | ||
@@ -48,3 +48,3 @@ .equal('qwe')(4) | ||
it("delayed equal", function() { | ||
var s = Switch | ||
const s = Switch | ||
.equal('qwe')(4) | ||
@@ -63,3 +63,3 @@ | ||
expect(s(true)).to.equal(2); | ||
// expect(s('asd')).to.equal(nice.NOTHING); | ||
expect(s('asd')).to.equal(nice.NOTHING); | ||
}); | ||
@@ -70,6 +70,6 @@ | ||
it("switch check", function() { | ||
var spy1 = chai.spy(); | ||
var spy3 = chai.spy(); | ||
const spy1 = chai.spy(); | ||
const spy3 = chai.spy(); | ||
var s = Switch('qwe') | ||
const s = Switch('qwe') | ||
.number.use(spy1) | ||
@@ -86,3 +86,3 @@ .check(s => s === 'qwe')(15) | ||
it("delayed check", function() { | ||
var s = Switch | ||
const s = Switch | ||
.check(s => s === 'qwe')(4); | ||
@@ -96,3 +96,3 @@ | ||
it("not", function() { | ||
var s = Switch(5) | ||
const s = Switch(5) | ||
.string(1) | ||
@@ -107,3 +107,3 @@ .not.string(2) | ||
it("not delayed", function() { | ||
var s = Switch | ||
const s = Switch | ||
.not.string(1) | ||
@@ -118,3 +118,3 @@ .default(2); | ||
it("not delayed 2", function() { | ||
var s = Switch | ||
const s = Switch | ||
.string(1) | ||
@@ -130,3 +130,3 @@ .not.string(2) | ||
it("delayed default", function() { | ||
var s = Switch.string(1); | ||
const s = Switch.string(1); | ||
@@ -139,3 +139,3 @@ expect(s('qwe')).to.equal(1); | ||
it("default", function() { | ||
var s = Switch(5).string(1)(); | ||
const s = Switch(5).string(1)(); | ||
@@ -147,3 +147,3 @@ expect(s).to.equal(5); | ||
it("between", function() { | ||
var s = Switch(4) | ||
const s = Switch(4) | ||
.string(1) | ||
@@ -158,3 +158,3 @@ .between(3, 6)('ok') | ||
it("between delayed", function() { | ||
var s = Switch | ||
const s = Switch | ||
.string(1) | ||
@@ -170,3 +170,3 @@ .between(3, 6)('ok') | ||
it("between delayed 2", function() { | ||
var s = Switch | ||
const s = Switch | ||
.between(3, 6)('ok') | ||
@@ -181,7 +181,7 @@ .default('nok'); | ||
it("switch default", function() { | ||
var spy1 = chai.spy(); | ||
var spy2 = chai.spy(); | ||
var spy3 = chai.spy(); | ||
const spy1 = chai.spy(); | ||
const spy2 = chai.spy(); | ||
const spy3 = chai.spy(); | ||
var s = Switch([]) | ||
const s = Switch([]) | ||
.number.use(spy1) | ||
@@ -198,3 +198,3 @@ .string.use(spy2) | ||
it("switch value", function() { | ||
var s = Switch(5) | ||
const s = Switch(5) | ||
.number.use(n => n + 1) | ||
@@ -208,3 +208,3 @@ .string.use(s => s + '!'); | ||
it("lt", function() { | ||
var s = Switch(5) | ||
const s = Switch(5) | ||
.lt(10)('OK') | ||
@@ -218,3 +218,3 @@ .default(''); | ||
it("switch delayed", function() { | ||
var s = Switch | ||
const s = Switch | ||
.equal(7).use(() => 77) | ||
@@ -235,2 +235,18 @@ .number.use(n => n + 1) | ||
it("switch action & mapping", function() { | ||
expect(Switch(5).number.sum(5).array.map(x => x * 2)()()).equal(10); | ||
expect(Switch([1]).number.sum(5).array.map(x => x * 2)()()).deep.equal([2]); | ||
expect(Switch('qwe').number.sum(5).array.map(x => x * 2)()).equal('qwe'); | ||
}); | ||
it("delayed switch action & mapping", function() { | ||
const f = nice.Switch.number.sum(5).array.map(x => x * 2); | ||
expect(f(5)()).equal(10); | ||
expect(f([1])()).deep.equal([2]); | ||
expect(f('qwe')).equal('qwe'); | ||
}); | ||
}); |
@@ -1,4 +0,4 @@ | ||
var nice = require('../index.js')(); | ||
var Div = nice.Div; | ||
var expect = require('chai').expect; | ||
const nice = require('../index.js')(); | ||
const Div = nice.Div; | ||
const expect = require('chai').expect; | ||
@@ -8,3 +8,3 @@ describe("Tags", function() { | ||
it("Div Span", function() { | ||
var div = nice.Span('qwe'); | ||
const div = nice.Span('qwe'); | ||
expect(div.html).to.equal('<span>qwe</span>'); | ||
@@ -14,3 +14,3 @@ }); | ||
it("Div B", function() { | ||
var div = nice.B('qwe'); | ||
const div = nice.B('qwe'); | ||
expect(div.html).to.equal('<b>qwe</b>'); | ||
@@ -20,3 +20,3 @@ }); | ||
it("Div I", function() { | ||
var div = nice.I('qwe'); | ||
const div = nice.I('qwe'); | ||
expect(div.html).to.equal('<i>qwe</i>'); | ||
@@ -26,3 +26,3 @@ }); | ||
it("Div A", function() { | ||
var div = nice.A('/qwe').add('click'); | ||
const div = nice.A('/qwe').add('click'); | ||
expect(div.html).to.equal('<a href="/qwe">click</a>'); | ||
@@ -32,3 +32,3 @@ }); | ||
it("Div Img", function() { | ||
var div = nice.Img('qwe.jpg'); | ||
const div = nice.Img('qwe.jpg'); | ||
expect(div.html).to.equal('<img src="qwe.jpg"></img>'); | ||
@@ -38,3 +38,3 @@ }); | ||
it("Div Img", function() { | ||
var div = nice.Img('qwe.jpg'); | ||
const div = nice.Img('qwe.jpg'); | ||
expect(div.html).to.equal('<img src="qwe.jpg"></img>'); | ||
@@ -44,4 +44,3 @@ }); | ||
it("Checkbox", function() { | ||
var c = nice.Checkbox(true); | ||
// var c = nice.Input('checkbox').checked(true); | ||
const c = nice.Checkbox(true); | ||
expect(c.html).to.equal('<input type="checkbox" checked="true"></input>'); | ||
@@ -52,3 +51,3 @@ expect(c.checked()).to.equal(true); | ||
it("Textarea", function() { | ||
var t = nice.Textarea('qwe'); | ||
const t = nice.Textarea('qwe'); | ||
expect(t.html).to.equal('<textarea>qwe</textarea>'); | ||
@@ -55,0 +54,0 @@ t.value('asd'); |
@@ -1,5 +0,5 @@ | ||
var nice = require('../index.js')(); | ||
var chai = require('chai'); | ||
const nice = require('../index.js')(); | ||
const chai = require('chai'); | ||
chai.use(require('chai-spies')); | ||
var expect = chai.expect; | ||
const expect = chai.expect; | ||
const is = nice.is; | ||
@@ -11,5 +11,5 @@ | ||
it("create", function() { | ||
var type = nice.Type({})(); | ||
const type = nice.Type({})(); | ||
expect(nice.type(type)).to.equal(type); | ||
var item = type(); | ||
const item = type(); | ||
expect(is.function(item)).to.equal(true); | ||
@@ -21,3 +21,3 @@ expect(item._type).to.equal(type); | ||
it("extends", function() { | ||
var a = nice.Type({ | ||
const a = nice.Type({ | ||
title: 'T1', | ||
@@ -33,3 +33,3 @@ | ||
var b = nice.Type('T2').extends('T1'); | ||
const b = nice.Type('T2').extends('T1'); | ||
@@ -43,29 +43,28 @@ expect(nice.T1.creator).not.to.equal(undefined); | ||
// it("super", function() { | ||
// var A = nice.Type({ | ||
// proto: { | ||
// 'qwe': function(){ return this.getResult() + 3 } | ||
// } | ||
// }).extends('Number'); | ||
it("super", function() { | ||
const A = nice.Type({ | ||
proto: { | ||
'qwe': function(){ return this.getResult() + 3 } | ||
} | ||
}).extends('Number')(); | ||
const B = nice.Type({ | ||
proto: { | ||
'qwe': function(){ return this.getResult() + 5 } | ||
} | ||
}).extends(A)(); | ||
const a = A(1); | ||
const b = B(1); | ||
expect(B.super).to.equal(A); | ||
// | ||
// var B = nice.Type({ | ||
// proto: { | ||
// 'qwe': function(){ return this.getResult() + 5 } | ||
// } | ||
// }).extends(A); | ||
// | ||
// var a = A(1); | ||
// var b = B(1); | ||
// | ||
// expect(B.super).to.equal(A); | ||
// | ||
// expect(b.super.qwe()).to.equal(4); | ||
// expect(b.qwe()).to.equal(6); | ||
// | ||
// }); | ||
}); | ||
it("isSubType", function() { | ||
var a = nice.Type()(); | ||
var b = nice.Type().extends(a)(); | ||
const a = nice.Type()(); | ||
const b = nice.Type().extends(a)(); | ||
@@ -77,6 +76,18 @@ expect(b.isSubType(b)).to.equal(true); | ||
it("default", function() { | ||
const A = nice.Type().String('qwe', 'asd')(); | ||
const B = nice.Type().extends(A).String('zxc', '123').String('asd')(); | ||
expect(A().qwe()).to.equal('asd'); | ||
expect(B().get('qwe')()).to.equal('asd'); | ||
expect(B().qwe()).to.equal('asd'); | ||
expect(B().get('zxc')()).to.equal('123'); | ||
expect(B().get('asd')()).to.equal(''); | ||
}); | ||
it("Method", function() { | ||
var spy = chai.spy(); | ||
var City = nice.Type().Method('go', function(z, a){spy(a, z);})(); | ||
var city = City(); | ||
const spy = chai.spy(); | ||
const City = nice.Type().Method('go', function(z, a){spy(a, z);})(); | ||
const city = City(); | ||
city.go(3); | ||
@@ -83,0 +94,0 @@ expect(spy).to.have.been.called.once().with(3, city); |
@@ -1,4 +0,4 @@ | ||
var nice = require('../index.js')(); | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
const nice = require('../index.js')(); | ||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
@@ -37,3 +37,3 @@ | ||
// it("objDiggMin", function() { | ||
// var o = {a: 1, b:{ bb:2 } }; | ||
// const o = {a: 1, b:{ bb:2 } }; | ||
// nice.objDiggMin(o, 'b', 'bb', 1); | ||
@@ -47,3 +47,3 @@ // nice.objDiggMin(o, 'c', 'cc', 3); | ||
// it("objDiggMax", function() { | ||
// var o = {a: 1, b:{ bb:2 } }; | ||
// const o = {a: 1, b:{ bb:2 } }; | ||
// nice.objDiggMax(o, 'b', 'bb', 1); | ||
@@ -57,5 +57,5 @@ // nice.objDiggMax(o, 'c', 'cc', 3); | ||
// it("objMax", function() { | ||
// var a = {a: 1, b:3 }; | ||
// var b = {a: 2, b:1, c:4}; | ||
// var o = nice.objMax(a, b); | ||
// const a = {a: 1, b:3 }; | ||
// const b = {a: 2, b:1, c:4}; | ||
// const o = nice.objMax(a, b); | ||
// expect(o.a).to.equal(2); | ||
@@ -68,5 +68,5 @@ // expect(o.b).to.equal(3); | ||
// it("findKey", function() { | ||
// var a = ['a', 'b']; | ||
// var o = {qwe: 'a', asd: 'b'}; | ||
// var f = l => l === 'b'; | ||
// const a = ['a', 'b']; | ||
// const o = {qwe: 'a', asd: 'b'}; | ||
// const f = l => l === 'b'; | ||
// expect(nice.findKey(f, a)).to.equal(1); | ||
@@ -78,4 +78,4 @@ // expect(nice.findKey(f, o)).to.equal('asd'); | ||
it("_eachEach", function() { | ||
var o = {qwe: [0], asd: {zxc:1}}; | ||
var spy = chai.spy(); | ||
const o = {qwe: [0], asd: {zxc:1}}; | ||
const spy = chai.spy(); | ||
nice._eachEach(o, spy); | ||
@@ -96,5 +96,5 @@ | ||
it("super", () => { | ||
var a = {qwe: 1, asd:1}; | ||
var b = {qwe: 2}; | ||
var c = {qwe: 3, asd: 3}; | ||
const a = {qwe: 1, asd:1}; | ||
const b = {qwe: 2}; | ||
const c = {qwe: 3, asd: 3}; | ||
Object.setPrototypeOf(b, a); | ||
@@ -107,14 +107,2 @@ Object.setPrototypeOf(c, b); | ||
// it('calmp', () => { | ||
// expect(nice.clamp(-5, -2, 5)).to.equal(-2); | ||
// expect(nice.clamp(4, -2, 5)).to.equal(4); | ||
// expect(nice.clamp(6, -2, 5)).to.equal(5); | ||
// | ||
// expect(nice.clamp(-5, 5)).to.equal(0); | ||
// expect(nice.clamp(4, 5)).to.equal(4); | ||
// expect(nice.clamp(6, 5)).to.equal(5); | ||
// }); | ||
// | ||
it("_set", () => { | ||
@@ -121,0 +109,0 @@ expect(nice._set({}, 'a', 1)).to.deep.equal({a:1}); |
@@ -44,3 +44,3 @@ nice.Object.extend({ | ||
} | ||
}) | ||
}).about('Ordered list of elements.') | ||
.ReadOnly(function size() { | ||
@@ -204,2 +204,11 @@ return this.getResult().length; | ||
M.about('Creates new array with separator between elments.') | ||
(function intersperse(a, separator) { | ||
const res = nice.Array(); | ||
const last = a.size - 1; | ||
a.each((v, k) => res.push(v) && (k < last && res.push(separator))); | ||
return res; | ||
}); | ||
typeof Symbol === 'function' && F(Symbol.iterator, z => { | ||
@@ -206,0 +215,0 @@ let i = 0; |
@@ -7,9 +7,5 @@ nice.Single.extend({ | ||
loadValue: v => v | ||
}); | ||
}).about('Wrapper for JS boolean.'); | ||
const B = nice.Boolean, M = Mapping.Boolean; | ||
M('and', (z, v) => B(z() && v)); | ||
M('or', (z, v) => B(z() || v)); | ||
M('nor', (z, v) => B(!(z() || v))); | ||
M('xor', (z, v) => B(z() ^ !!v)); | ||
@@ -16,0 +12,0 @@ const A = Action.Boolean; |
@@ -254,3 +254,3 @@ nice.Type({ | ||
} | ||
}); | ||
}).about('Observable component for declarative style programming.'); | ||
Box = nice.Box; | ||
@@ -265,5 +265,3 @@ const F = Func.Box; | ||
function diffConverter(v){ | ||
if(is.nice(v) && is.Value(v)) | ||
return nice.fromItem(v); | ||
return v; | ||
return is.Value(v)? nice.fromItem(v) : v; | ||
} | ||
@@ -342,18 +340,48 @@ | ||
def(nice, 'resolveChildren', (v, f) => { | ||
if(!v) | ||
return f(v); | ||
if(is.Box(v)) | ||
return v.listenOnce(f); | ||
return v.listenOnce(_v => nice.resolveChildren(_v, f)); | ||
if(is.Object(v)){ | ||
const res = v._type(); | ||
let n = v.size; | ||
if(!n) | ||
return f(res); | ||
v.each((c, k) => nice.resolveChildren(c, _v => { | ||
nice.resolveChildren(_v, __v => { | ||
res.set(k, __v); | ||
--n || f(res); | ||
if(v._result){ | ||
if(is.object(v._result)){ | ||
let count = 0; | ||
const next = () => { | ||
count--; | ||
count === 0 && f(v); | ||
}; | ||
_each(v._result, () => count++); | ||
!count ? f(v) : _each(v._result, (vv, kk) => { | ||
nice.resolveChildren(vv, _v => { | ||
if(_v && _v._type){ | ||
_v = _v._type.saveValue(_v._result); | ||
} | ||
v._result[kk] = _v; | ||
next(); | ||
}); | ||
}); | ||
})); | ||
} else { | ||
f(v); | ||
} | ||
} else { | ||
f(v); | ||
if(is.object(v)){ | ||
let count = 0; | ||
const next = () => { | ||
count--; | ||
count === 0 && f(v); | ||
}; | ||
_each(v, () => count++); | ||
!count ? f(v) : _each(v, (vv, kk) => { | ||
nice.resolveChildren(vv, _v => { | ||
if(_v && _v._type){ | ||
_v = _v._type.saveValue(_v._result); | ||
} | ||
v[kk] = _v; | ||
next(); | ||
}); | ||
}); | ||
} else { | ||
f(v); | ||
} | ||
} | ||
@@ -360,0 +388,0 @@ }); |
nice.Type({ | ||
title: 'Error', | ||
extends: 'Nothing', | ||
@@ -19,2 +19,2 @@ | ||
} | ||
}); | ||
}).about('Represents error.'); |
@@ -11,3 +11,3 @@ nice.Single.extend({ | ||
loadValue: v => v | ||
}); | ||
}).about('Wrapper for JS number.'); | ||
@@ -68,3 +68,4 @@ _each({ | ||
log2 | ||
log1pexpm1`.split('\n').forEach(k => M(k, (n, ...a) => Math[k](n, ...a))); | ||
log1pexpm1`.split('\n').forEach(k => | ||
M.about('Delegates to Math.' + k)(k, (n, ...a) => Math[k](n, ...a))); | ||
@@ -71,0 +72,0 @@ |
@@ -5,2 +5,3 @@ | ||
extends: nice.Value, | ||
defaultValue: function() { return nice.create(this.defaultResult); }, | ||
creator: () => { | ||
@@ -11,8 +12,13 @@ const f = (...a) => { | ||
if(a.length === 1 && a[0] === undefined) | ||
let k = a[0]; | ||
if(a.length === 1 && k === undefined) | ||
return f._parent || f; | ||
if(a.length === 1 && a[0] !== undefined && !is.object(a[0])) | ||
return f.get(a[0]); | ||
if(is.String(k)) | ||
k = k(); | ||
if(a.length === 1 && k !== undefined && !is.object(k)) | ||
return f.get(k); | ||
f.setValue(...a); | ||
@@ -24,2 +30,3 @@ return f._parent || f; | ||
}) | ||
.about('Parent type for all composite types.') | ||
.ReadOnly(function values(){ | ||
@@ -96,5 +103,20 @@ let a = nice.Array(); | ||
if(!vs.hasOwnProperty(i)) | ||
return nice.NOT_FOUND; | ||
if(is.String(i)) | ||
i = i(); | ||
if(!vs.hasOwnProperty(i)){ | ||
const types = z._type.types; | ||
if(i in vs === false){ | ||
if(types && types[i]) | ||
vs[i] = types[i].defaultValue(); | ||
else | ||
return nice.NOT_FOUND; | ||
} else { | ||
if(typeof vs[i] === 'object') | ||
// vs[i] = (types && types[i] && types[i].defaultValue()) || {}; | ||
vs[i] = create(vs[i], (types && types[i] && types[i].defaultValue()) || {}); | ||
} | ||
} | ||
const res = nice.toItem(vs[i]); | ||
@@ -114,3 +136,3 @@ res._parent = z; | ||
while(path.length > 1){ | ||
k = path.shift(); | ||
k = nice.unwrap(path.shift()); | ||
if(!data.hasOwnProperty(k)){ | ||
@@ -132,2 +154,3 @@ data[k] = {}; | ||
} | ||
k = nice.unwrap(k); | ||
const type = z._itemsType; | ||
@@ -317,28 +340,24 @@ | ||
M(function getProperties(z){ | ||
const res = []; | ||
for(let i in z) z[i]._isProperty && res.push(z[i]); | ||
return res; | ||
}); | ||
nice._on('Type', type => { | ||
def(nice.Object.configProto, type.title, function (name, by) { | ||
const cfg = { type }, targetType = this.target; | ||
def(nice.Object.configProto, type.title, function (name, value = type.defaultValue()) { | ||
const targetType = this.target; | ||
if(is.function(name) && name.name){ | ||
cfg.by = name; | ||
cfg.key = name.name; | ||
} else { | ||
cfg.key = name; | ||
if(by && (is.Anything(by) || !is.function(by))){ | ||
cfg.value = by; | ||
} else { | ||
cfg.by = by; | ||
} | ||
} | ||
if(name[0] !== name[0].toLowerCase()) | ||
throw "Property name should start with lowercase letter. " | ||
+ `"${nice._deCapitalize(name)}" not "${name}"`; | ||
targetType.types = this.types || {}; | ||
targetType.types[cfg.key] = type; | ||
targetType.types[name] = type; | ||
defGet(targetType.proto, cfg.key, function(){ | ||
if(this.getResult()[cfg.key] === undefined){ | ||
this.setByType(cfg.key, type, cfg.value); | ||
} | ||
const res = this.get(cfg.key); | ||
value && (targetType.defaultResult[name] = value); | ||
defGet(targetType.proto, name, function(){ | ||
const res = this.get(name); | ||
if(!is.subType(res._type, type)) | ||
@@ -345,0 +364,0 @@ throw `Can't create ${type.title} property. Value is ${res._type.title}`; |
nice.Type('Range') | ||
.about('Represent range of numbers.') | ||
.Number('start', 0) | ||
@@ -3,0 +4,0 @@ .Number('end', Infinity) |
@@ -30,3 +30,3 @@ nice.Type({ | ||
} | ||
}); | ||
}).about('Parent type for all non composite types.'); | ||
@@ -33,0 +33,0 @@ |
@@ -14,2 +14,3 @@ const whiteSpaces = ' \f\n\r\t\v\u00A0\u2028\u2029'; | ||
}) | ||
.about('Wrapper for JS string.') | ||
.ReadOnly(function length(){ | ||
@@ -16,0 +17,0 @@ return this.getResult().length; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
332523
58
9211
333
1