|
1 | 1 | # TOC
|
| 2 | + - [canonical-title-map.js](#canonical-title-mapjs) |
| 3 | + - [canonicalTitleMap](#canonical-title-mapjs-canonicaltitlemap) |
2 | 4 | - [merge.js](#mergejs)
|
3 | 5 | - [merge](#mergejs-merge)
|
| 6 | + - [select.js](#selectjs) |
| 7 | + - [select](#selectjs-select) |
4 | 8 | - [schema-defaults.js](#schema-defaultsjs)
|
5 | 9 | - [createDefaults](#schema-defaultsjs-createdefaults)
|
6 | 10 | - [defaultForm](#schema-defaultsjs-defaultform)
|
| 11 | + - [sf-path.js](#sf-pathjs) |
| 12 | + - [traverse.js](#traversejs) |
| 13 | + - [validate.js](#validatejs) |
| 14 | + - [validate](#validatejs-validate) |
| 15 | + - [module.js](#modulejs) |
7 | 16 | <a name=""></a>
|
8 | 17 |
|
| 18 | +<a name="canonical-title-mapjs"></a> |
| 19 | +# canonical-title-map.js |
| 20 | +should hold a normalisation function for enums and titleMaps to generate titleMaps. |
| 21 | + |
| 22 | +```js |
| 23 | +_canonicalTitleMap2.default.should.be.an('function'); |
| 24 | +``` |
| 25 | + |
| 26 | +<a name="canonical-title-mapjs-canonicaltitlemap"></a> |
| 27 | +## canonicalTitleMap |
| 28 | +should return a titleMap for a titleMap object with original enum. |
| 29 | + |
| 30 | +```js |
| 31 | +var result = (0, _canonicalTitleMap2.default)(titlemapObj, enumeration); |
| 32 | +result.should.be.deep.equal(titlemap); |
| 33 | +``` |
| 34 | + |
| 35 | +should return a titleMap for a titleMap list with original enum. |
| 36 | + |
| 37 | +```js |
| 38 | +var result = (0, _canonicalTitleMap2.default)(titlemap, enumeration); |
| 39 | +result.should.be.deep.equal(titlemap); |
| 40 | +``` |
| 41 | + |
| 42 | +should return a titleMap for a titleMap object without enum. |
| 43 | + |
| 44 | +```js |
| 45 | +var result = (0, _canonicalTitleMap2.default)(titlemapObj); |
| 46 | +result.should.be.deep.equal(titlemap); |
| 47 | +``` |
| 48 | + |
| 49 | +should return a titleMap for a titleMap list without enum. |
| 50 | + |
| 51 | +```js |
| 52 | +var result = (0, _canonicalTitleMap2.default)(titlemap); |
| 53 | +result.should.be.deep.equal(titlemap); |
| 54 | +``` |
| 55 | + |
| 56 | +should return a titleMap for a titleMap object with original enum, returning "undefined" name if the enum value is not found. |
| 57 | + |
| 58 | +```js |
| 59 | +enumeration.push('Mr Freeze'); |
| 60 | +var result = (0, _canonicalTitleMap2.default)(titlemapObj, enumeration); |
| 61 | +titlemap.push({ |
| 62 | + "name": undefined, |
| 63 | + "value": "Mr Freeze" |
| 64 | +}); |
| 65 | +result.should.be.deep.equal(titlemap); |
| 66 | +``` |
| 67 | + |
9 | 68 | <a name="mergejs"></a>
|
10 | 69 | # merge.js
|
11 | 70 | should contain a function for merging schema and form definitions.
|
@@ -130,6 +189,42 @@ merged[0].items[0].items[0].should.have.property('readonly');
|
130 | 189 | merged[0].items[0].items[0].readonly.should.eq(true);
|
131 | 190 | ```
|
132 | 191 |
|
| 192 | +<a name="selectjs"></a> |
| 193 | +# select.js |
| 194 | +should provide a function for getting and setting an object value. |
| 195 | + |
| 196 | +```js |
| 197 | +_select.select.should.be.an('function'); |
| 198 | +``` |
| 199 | + |
| 200 | +<a name="selectjs-select"></a> |
| 201 | +## select |
| 202 | +should get a value from an object. |
| 203 | + |
| 204 | +```js |
| 205 | +var value = (0, _select.select)('frienemies[1].weapon.boomstick.method[0]', data); |
| 206 | +value.should.eq('boom'); |
| 207 | +``` |
| 208 | + |
| 209 | +should set a value on an object. |
| 210 | + |
| 211 | +```js |
| 212 | +var value = (0, _select.select)('weapon.glove.method[1]', data, 'slice'); |
| 213 | +data.weapon.glove.method.should.be.deep.equal(['stab', 'slice']); |
| 214 | +``` |
| 215 | + |
| 216 | +should create any undefined objects or arrays in the path when setting a value. |
| 217 | + |
| 218 | +```js |
| 219 | +var data = {}; |
| 220 | +var value = (0, _select.select)('property.array[1].value', data, 'something'); |
| 221 | +data.should.be.deep.equal({ |
| 222 | + 'property': { |
| 223 | + 'array': [, { 'value': 'something' }] |
| 224 | + } |
| 225 | +}); |
| 226 | +``` |
| 227 | + |
133 | 228 | <a name="schema-defaultsjs"></a>
|
134 | 229 | # schema-defaults.js
|
135 | 230 | should hold functions for generating a default form schema from defaults it creates.
|
@@ -320,3 +415,64 @@ var f = (0, _schemaDefaults.defaultForm)(schema, (0, _schemaDefaults.createDefau
|
320 | 415 | f.form.should.be.deep.equal(form);
|
321 | 416 | ```
|
322 | 417 |
|
| 418 | +<a name="sf-pathjs"></a> |
| 419 | +# sf-path.js |
| 420 | +should hold functions for working with object paths and keys. |
| 421 | + |
| 422 | +```js |
| 423 | +_sfPath.parse.should.be.an('function'); |
| 424 | +_sfPath.stringify.should.be.an('function'); |
| 425 | +_sfPath.normalize.should.be.an('function'); |
| 426 | +_sfPath.name.should.be.an('function'); |
| 427 | +``` |
| 428 | + |
| 429 | +<a name="traversejs"></a> |
| 430 | +# traverse.js |
| 431 | +should hold functions for applying functions on branches of a json-schema or ui-schema. |
| 432 | + |
| 433 | +```js |
| 434 | +_traverse.traverseSchema.should.be.an('function'); |
| 435 | +_traverse.traverseForm.should.be.an('function'); |
| 436 | +``` |
| 437 | + |
| 438 | +<a name="validatejs"></a> |
| 439 | +# validate.js |
| 440 | +should hold a validation function for testing against tv4 until an option to pass in a validator is created. |
| 441 | + |
| 442 | +```js |
| 443 | +_validate.validate.should.be.an('function'); |
| 444 | +``` |
| 445 | + |
| 446 | +<a name="validatejs-validate"></a> |
| 447 | +## validate |
| 448 | +should return a result object {"error":null, "missing":[], "valid":true}, with valid set to true when the data is valid for the schema. |
| 449 | + |
| 450 | +```js |
| 451 | +var value = 'Batman'; |
| 452 | +var result = (0, _validate.validate)(form, value); |
| 453 | +result.should.be.deep.equal({ "error": null, "missing": [], "valid": true }); |
| 454 | +``` |
| 455 | + |
| 456 | +should return an error object with a message "Invalid type: array (expected string)" when the data is not valid. |
| 457 | + |
| 458 | +```js |
| 459 | +var value = [0]; |
| 460 | +var result = (0, _validate.validate)(form, value); |
| 461 | +result.error.message.should.eq("Invalid type: array (expected string)"); |
| 462 | +``` |
| 463 | + |
| 464 | +<a name="modulejs"></a> |
| 465 | +# module.js |
| 466 | +should hold all the public functions of the API. |
| 467 | + |
| 468 | +```js |
| 469 | +_module.merge.should.be.an('function'); |
| 470 | +_module.select.should.be.an('function'); |
| 471 | +_module.traverseSchema.should.be.an('function'); |
| 472 | +_module.traverseForm.should.be.an('function'); |
| 473 | +_module.validate.should.be.an('function'); |
| 474 | +_module.sfPath.should.be.an('object'); |
| 475 | +_module.schemaDefaults.should.be.an('object'); |
| 476 | +_module.canonicalTitleMap.should.be.an('function'); |
| 477 | +``` |
| 478 | + |
0 commit comments