tdm-multicat
tdm-multicat is a tdm module for classification by matching identifier. It can be used to store classifications of documents.
Installation
Using npm :
$ npm i -g tdm-multicat
$ npm i --save tdm-multicat
Uses
Using Node :
/* require of Multicat module */
const Multicat = require('tdm-multicat');
/* Build new Instance of Classifier */
let classifier = new Multicat.Classifier();
/* Build new Instance of List */
let list = new Multicat.List();
/* Build new Instance of Classification */
let classification = new Multicat.Classification();
/* Build new Instance of ListOfClassification */
let listOfClassification = new Multicat.ListOfClassification();
/* Build new Instance of Element */
let element = new Multicat.Element();
/* Build new Instance of ListOfElement */
let listOfElement = new Multicat.ListOfElement();
/* Build new Instance of Table */
let table = new Multicat.Table();
/* Build new Instance of ListOfTable */
let listOfTable = new Multicat.ListOfTable();
Launch tests
$ npm run test
Build documentation
$ npm run docs
API Documentation
Following classes are packaged into 'Multicat' variable.
You must access it adding 'Multicat.' prefix in your code (see Uses section for more details)
Classes
Typedefs
-
callback :
function
-
Function called when procces end
Classification
Kind: global class
-
Classification
- new Classification([level], [value])
-
instance
-
.load(data) ⇒
boolean
-
.save() ⇒
Object
-
.toString() ⇒
string
-
.load(data) ⇒
-
static
-
.check(data) ⇒
boolean
-
.isValid(data) ⇒
boolean
-
.check(data) ⇒
new Classification([level], [value])
Returns: Classification
- - An instance of Classifier
Param | Type | Default | Description |
---|---|---|---|
[level] | number |
-1 |
Classification Level |
[value] | string |
Classification Value |
Example (Example usage of 'contructor' (with paramters))
let classification = new Classification(1, 'geology');
// returns an instance of Classification with properties :
// - level : 1
// - value : geology
Example (Example usage of 'contructor' (with default values))
let classification = new Classification();
// returns an instance of Classification with properties :
// - level : -1
// - value : undefined
boolean
classification.load(data) ⇒ Load data
Kind: instance method of Classification
Returns: boolean
- - True if it succed, else return false
Param | Type | Description |
---|---|---|
data | Object |
Data that will be loaded (call save function to generate this data) |
Example (Example usage of 'load' function (success))
let data = new Classification(1, 'geology').save(),
classification = new Classification();
classification.load(data); // returns true
console.log(classification.toString()); // outuput : '1 - geology'
Example (Example usage of 'load' function (fail))
let data = {'1' :'geology'}, // invalid data, only use .save() function to build correct data structure that can be loaded
classification = new Classification();
classification.load(data); // returns false
console.log(classification.toString()); // outuput : '-1 - undefined'
Object
classification.save() ⇒ Save data
Kind: instance method of Classification
Returns: Object
- - An object representation of save
Example (Example usage of 'save' function)
let classification = new Classification(1, 'geology');
classification.save(); // returns {'level': 1, 'value': 'geology'}
string
classification.toString() ⇒ Return String representation of this
Kind: instance method of Classification
Returns: string
- - String representation of this
Example (Example usage of 'toString' function)
let classification = new Classification(1, 'geology');
classification.toString(); // returns '1 - geology'
boolean
Classification.check(data) ⇒ Check data before load
Kind: static method of Classification
Returns: boolean
- - True if it succed, else return false
Param | Type | Description |
---|---|---|
data | Object |
Data that will be checked (call save function to generate this data) |
Example (Example usage of 'check' function (success))
let classification = new Classification(1, 'geology').save();
Classification.check(classification); // returns true
Example (Example usage of 'check' function (fail))
let classification = {'1', 'geology'}; // invalid data, only use .save() function to build correct data structure that can be loaded
Classification.check(classification); // returns false
boolean
Classification.isValid(data) ⇒ Validate data
Kind: static method of Classification
Returns: boolean
- - True if it succed, else return false
Param | Type | Description |
---|---|---|
data | Object |
Data that will be validated (call Classification constructor to generate this data) |
Example (Example usage of 'isValid' function (success))
let classification = new Classification(1, 'geology');
Classification.isValid(classification); // returns true
Example (Example usage of 'isValid' function (fail))
let classification = {'level' : 1, 'value' : 'geology'}; // invalid data, only use new Classification() to build valid data
Classification.isValid(classification); // returns false
Classifier
Kind: global class
-
Classifier
- new Classifier([options])
-
.getClassifications(elementId) ⇒
Array
-
.getClassificationsOf(tableId, elementId) ⇒
Array
-
.getElements(classification) ⇒
Array.<Element>
-
.getElementsOf(tableId, classification) ⇒
Array.<Element>
-
.getRegisters() ⇒
Object
-
.getRegistersOf(tableId) ⇒
Object
-
.load(filePath, cb) ⇒
undefined
-
.save(filePath, cb) ⇒
undefined
new Classifier([options])
Returns: Classifier
- - An instance of Classifier
Param | Type | Description |
---|---|---|
[options] | Object |
Options of constructor |
[options.tables] | ListOfTable |
An instance of listOfTable |
Example (Example usage of 'contructor' (with paramters))
let options = { 'tables': myTables }, // According myTables (instance of ListOfTable) contain your data
classifier = new Classifier(options);
// returns an instance of Classifier with properties :
// - tables : [ListOfTable]
Example (Example usage of 'contructor' (with default values))
let classifier = new Classifier();
// returns an instance of Classifier with properties :
// - tables : new ListOfTable() (empty)
Array
classifier.getClassifications(elementId) ⇒ Return categories of all Tables with given elementId
Kind: instance method of Classifier
Returns: Array
- - An array containing all classification associated with this elementId
Param | Type | Description |
---|---|---|
elementId | string |
Identifier of given element |
Example (Example usage of 'getClassifications' function (success))
// According there is an element identified by 'xxx-xxx-xxx'
classifier.getClassifications('xxx-xxx-xxx'); // returns : [Object, Object, ...]
Example (Example usage of 'getClassifications' function (fail))
// According there is no element identified by 'xxx-xxx-xxx'
classifier.getClassifications('xxx-xxx-xxx'); // returns : []
Array
classifier.getClassificationsOf(tableId, elementId) ⇒ Get categories of given Table
Kind: instance method of Classifier
Returns: Array
- - An array containing all classification associated with this elementId of given classification
Param | Type | Description |
---|---|---|
tableId | string |
Identifier of classification |
elementId | string |
Identifier of given element |
Example (Example usage of 'getClassificationsOf' function (success))
// According there is an element identified by 'xxx-xxx-xxx' in table 'myTable'
classifier.getClassificationsOf('myTable', 'xxx-xxx-xxx'); // returns : [Object, Object, ...]
Example (Example usage of 'getClassificationsOf' function (fail))
// According there is no element identified by 'xxx-xxx-xxx' in table 'myTable'
classifier.getClassificationsOf('myTable', 'xxx-xxx-xxx'); // returns : []
Array.<Element>
classifier.getElements(classification) ⇒ Return Elements of all Tables with given classification
Kind: instance method of Classifier
Returns: Array.<Element>
- - An array containing all elements associated with this classification
Param | Type | Description |
---|---|---|
classification | Classification |
Classification of element |
Example (Example usage of 'getElements' function (success))
// According there is at least one element with this classification
classifier.getElements(new Classification(1, 'geology')); // returns : [Element, Element, ...]
Example (Example usage of 'getElements' function (fail))
// According there is no element identified with this classification
classifier.getElements(new Classification(1, 'geology')); // returns : [] (no record)
classifier.getElements({'1', 'geology'}); // returns : [] (bad parameter)
Array.<Element>
classifier.getElementsOf(tableId, classification) ⇒ Get Elements of given Table with given classification
Kind: instance method of Classifier
Returns: Array.<Element>
- - An array containing all elements associated with this classification
Param | Type | Description |
---|---|---|
tableId | string |
Identifier of classification |
classification | Classification |
Classification of element |
Example (Example usage of 'getElementsOf' function (success))
// According there is at least one element with this classification in table 'myTable'
classifier.getElementsOf('myTable', new Classification(1, 'geology')); // returns : [Element, Element, ...]
Example (Example usage of 'getElementsOf' function (fail))
// According there is no element identified with this classification in table 'myTable'
classifier.getElementsOf('myTable', new Classification(1, 'geology')); // returns : []
classifier.getElementsOf('myTable', {'1', 'geology'}); // returns : []
Object
classifier.getRegisters() ⇒ Get alls registers Get Elements of given Table with given classification
Kind: instance method of Classifier
Returns: Object
- - An Object containing all registers
Example (Example usage of 'getRegisters' function)
// According there is at least one element
classifier.getRegisters(); // returns : { '1 - geology': [Element, Element, ...] }
Object
classifier.getRegistersOf(tableId) ⇒ Get register of given Table
Kind: instance method of Classifier
Returns: Object
- - An Object containing register
Param | Type | Description |
---|---|---|
tableId | string |
Identifier of classification |
Example (Example usage of 'getRegistersOf' function)
// According there is at least one element in table 'myTable'
classifier.getRegistersOf(); // returns : { ... }
undefined
classifier.load(filePath, cb) ⇒ Load data of given file (that must be create by save function)
Kind: instance method of Classifier
Returns: undefined
- - undefined
Param | Type | Description |
---|---|---|
filePath | string |
Path of file containing saved data |
cb | callback |
Function called when procces end |
Example (Example usage of 'load' function)
classifier.load('./myData.json', function(err, res) {
if (err) return err; // will contain fs errors
console.log(res); // output : true if it succed, else false
}); // returns : undefined
undefined
classifier.save(filePath, cb) ⇒ Save data at given filePath (that will be loaded by load function)
Kind: instance method of Classifier
Returns: undefined
- - undefined
Param | Type | Description |
---|---|---|
filePath | string |
Path of file that will contain saved data |
cb | callback |
Function called when procces end |
Example (Example usage of 'save' function)
classifier.save('./myData.json', function(err, res) {
if (err) return err; // will contain fs errors
console.log(res); // output : true if it succed, else false
}); // returns : undefined
Element
Kind: global class
-
Element
- new Element([identifier], [classifications])
-
instance
-
.load(data) ⇒
boolean
-
.save() ⇒
Object
-
.load(data) ⇒
-
static
-
.check(data) ⇒
boolean
-
.isValid(data) ⇒
boolean
-
.check(data) ⇒
new Element([identifier], [classifications])
Returns: Element
- - An instance of Element
Param | Type | Description |
---|---|---|
[identifier] | string |
Identifier of Element |
[classifications] | ListOfClassification |
Classifications of elements |
Example (Example usage of 'contructor' (with paramters))
let element = new Element('xxx-xxx-xxx', myClassification); // According myClassification (instance of ListOfClassification) contain your data
// returns an instance of Element with properties :
// - identifier : 'xxx-xxx-xxx'
// - classifications : [ListOfClassification]
Example (Example usage of 'contructor' (with default values))
let element = new Element(); // According myClassification (instance of ListOfClassification) contain your data
// returns an instance of Element with properties :
// - identifier : null
// - classifications : new ListOfClassification() (empty)
boolean
element.load(data) ⇒ Load data
Kind: instance method of Element
Returns: boolean
- - True if it succed, else return false
Param | Type | Description |
---|---|---|
data | Object |
Data that will be loaded (call save function to generate this data) |
Example (Example usage of 'load' function (success))
let data = new Element('xxx-xxx-xxx', myClassification).save();
element = new Element();
element.load(data); // returns true
console.log(element); // outuput : [Element]
Example (Example usage of 'load' function (fail))
let data = {'xxx-xxx-xxx', myClassification}, // invalid data, only use .save() function to build correct data structure that can be loaded
element = new Classification();
element.load(data); // returns false
console.log(element); // outuput : [Element] (with default values)
Object
element.save() ⇒ Save data
Kind: instance method of Element
Returns: Object
- - An object representation of save
Example (Example usage of 'save' function)
let element = new Element('xxx-xxx-xxx', myClassification);
element.save(); // returns {'identifier': 'xxx-xxx-xxx', 'classifications': [{}, ...]}
boolean
Element.check(data) ⇒ Check data before load
Kind: static method of Element
Returns: boolean
- - True if it succed, else return false
Param | Type | Description |
---|---|---|
data | Object |
Data that will be checked (call save function to generate this data) |
Example (Example usage of 'check' function (success))
let element = new Element('xxx-xxx-xxx', myClassification).save();
Element.check(element); // returns true
Example (Example usage of 'check' function (fail))
let element = {'xxx-xxx-xxx', myClassification}; // invalid data, only use .save() function to build correct data structure that can be loaded
Element.check(element); // returns false
boolean
Element.isValid(data) ⇒ Validate data
Kind: static method of Element
Returns: boolean
- - True if it succed, else return false
Param | Type | Description |
---|---|---|
data | Object |
Data that will be validated |
Example (Example usage of 'isValid' function (success))
let element = new Element('xxx-xxx-xxx', myClassification).save();
Element.isValid(element); // returns true
Example (Example usage of 'isValid' function (fail))
let element = {'xxx-xxx-xxx', myClassification}; // invalid data, only use new Element() to build valid data
Element.isValid(element); // returns false
List
Kind: global class
-
List
- new List([options])
-
instance
-
.all() ⇒
Array
-
.indexesOf(index, value) ⇒
Array
-
.findBy(index, value) ⇒
Array
-
.findItem(item) ⇒
Array
-
.addItem(item) ⇒
number
-
.removeItem(item, [unique]) ⇒
boolean
-
.addIndex(index, value, collectionIndex) ⇒
number
-
.removeIndex(index, value, collectionIndex) ⇒
number
-
.refreshIndexes() ⇒
undefined
-
.load(data) ⇒
List
-
.all() ⇒
-
static
-
.check(data) ⇒
boolean
-
.isValid(data) ⇒
boolean
-
.getKey(value) ⇒
string
-
.check(data) ⇒
new List([options])
Returns: List
- - An instance of List
Param | Type | Description |
---|---|---|
[options] | Object |
Options of constructor |
[options.index] | Object |
An object containing indexes |
[options.blackListKey] | Object |
An object containing blacklisted keys (it will no be indexed) |
[options.collection] | Array |
An array containing items |
Example (Example usage of 'contructor' (with paramters))
let options = {
'index' : index, // Should be set only if you're sure
'blackListKey': blackListKey, // Setting a property (ex : {'example': true}) will desactivate indexation of 'example' property of all item to the List collection
'collection': collection // Should be set only if you're sure
},
list = new List(options);
// returns an instance of List with properties :
// - index : {}
// - blackListKey : {'example': true}
// - collection : []
Example (Example usage of 'contructor' (with default values))
let list = new List();
// returns an instance of List with properties :
// - index : {}
// - blackListKey : {}
// - collection : []
Array
list.all() ⇒ Get all items of List
Kind: instance method of List
Returns: Array
- - An array containing all items
Example (Example usage of 'all' function)
let list = new List();
list.addItem({'test': true});
list.all(); // returns [{'test': true}]
Array
list.indexesOf(index, value) ⇒ Return indexes of items with property 'index' having value 'value'
Kind: instance method of List
Returns: Array
- Return - An array of items indexes, or null if given index do not exist
Param | Type | Description |
---|---|---|
index | string |
Which index will be used to search for |
value | string |
Wich value of index will be used to search for |
Example (Example usage of 'indexesOf' function)
let list = new List();
list.addItem({'test': true});
list.indexesOf('test', true); // returns [0]
list.indexesOf(true, 'test'); // returns null
Array
list.findBy(index, value) ⇒ Find item of List with matching index 'index' with value 'value'
Kind: instance method of List
Returns: Array
- - An array of items founded
Param | Type | Description |
---|---|---|
index | string |
Which index will be used |
value | string |
Wich value of given index will be used |
Example (Example usage of 'findBy' function)
let list = new List();
list.addItem({'test': true});
list.findBy('test', true); // returns [{'test': true}]
list.findBy(true, 'test'); // returns []
Array
list.findItem(item) ⇒ Return item of List matching with given item
Kind: instance method of List
Returns: Array
- - An array of items found, or empty Array
Param | Type | Description |
---|---|---|
item |
string | number | boolean | Object
|
Item you search for |
Example (Example usage of 'findItem' function)
let list = new List();
list.addItem({'test': true});
list.findItem({'test': true}); // returns [{'item': {'test': true},'score': 1,'index': 0}]
// - item : item founded
// - score : matching score of item founded (number of properties matching / total number of properties)
// - index : index in collection (list.collection[index] will give you access to founded item)
list.findItem({true: 'test'}); // returns []
number
list.addItem(item) ⇒ Add item
Kind: instance method of List
Returns: number
- - Length of collection
Param | Type | Description |
---|---|---|
item | Object |
Item you want to add |
Example (Example usage of 'addItem' function)
let list = new List();
list.addItem({'test': true}); // return 1
list.addItem({'test': false}); // return 2
boolean
list.removeItem(item, [unique]) ⇒ Remove item
Kind: instance method of List
Returns: boolean
- - True if it succed, else return false
Param | Type | Default | Description |
---|---|---|---|
item | Object |
Item you want to remove | |
[unique] | boolean |
false |
Will delete all items found by default, set true to delete only fisrt item found |
Example (Example usage of 'removeItem' function)
let list = new List();
list.addItem({'test': true});
list.addItem({'test': true});
list.all().length // return 2
list.removeItem({'test': true}, true); // return true
list.removeItem({'test': true}); // return false
list.addItem({'test': true});
list.all().length // return 1
list.removeItem({'test': true}); // return true
list.removeItem({'test': true}); // return false
number
list.addIndex(index, value, collectionIndex) ⇒ Add index
Kind: instance method of List
Returns: number
- - Length of Index collection
Param | Type | Description |
---|---|---|
index | string |
Index name |
value | string |
Index Value |
collectionIndex | string |
Index (in collection) of item |
Example (Example usage of 'addIndex' function)
let list = new List();
list.addIndex('test', true, 0); // return 1
number
list.removeIndex(index, value, collectionIndex) ⇒ Remove index
Kind: instance method of List
Returns: number
- - Length of Index collection, or null
Param | Type | Description |
---|---|---|
index | string |
Index name |
value | string |
Index Value |
collectionIndex | string |
Index (in collection) of item |
Example (Example usage of 'removeIndex' function)
let list = new List();
list.addIndex('test', true, 0); // return 1
list.removeIndex('test', true, 0); // return 0
undefined
list.refreshIndexes() ⇒ Refresh all indexes (must use it indexes are 'broken')
Kind: instance method of List
Returns: undefined
- - undefined
Example (Example usage of 'refreshIndexes' function)
let list = new List();
list.refreshIndexes(); // return undefined
List
list.load(data) ⇒ Load data
Kind: instance method of List
Returns: List
- - this
Param | Type | Description |
---|---|---|
data | Object |
Data that will be loaded |
Example (Example usage of 'load' function)
let list = new List();
list.load({'collection': [{'test': true}, {'test': false}]}); // return [List]
boolean
List.check(data) ⇒ Check data before load
Kind: static method of List
Returns: boolean
- - True if it succed, else return false
Param | Type | Description |
---|---|---|
data | Object |
Data that will be checked (call save function to generate this data) |
Example (Example usage of 'check' function (success))
let list = new List(options).save();
List.check(list); // returns true
Example (Example usage of 'check' function (fail))
let list = {'index': {}, 'blackListKey':{}, 'collection': []}; // invalid data, only use .save() function to build correct data structure that can be loaded
List.check(list); // returns false
boolean
List.isValid(data) ⇒ Validate data
Kind: static method of List
Returns: boolean
- - True if it succed, else return false
Param | Type | Description |
---|---|---|
data | Object |
Data that will be validated |
Example (Example usage of 'isValid' function (success))
let list = new List().save();
List.isValid(list); // returns true
Example (Example usage of 'isValid' function (fail))
let list = {'index': {}, 'blackListKey':{}, 'collection': []}; // invalid data, only use new List() to build valid data
List.isValid(list); // returns false
string
List.getKey(value) ⇒ Build key of a given value
Kind: static method of List
Returns: string
- - Generated key
Param | Type | Description |
---|---|---|
value |
Object | number | string
|
Given value |
Example (Example usage of 'getKey' function)
List.getKey('test'); // returns 'string:test'
List.getKey(1); // returns 'number:1'
List.getKey({'test': true}); // returns 'object:57c343a1ed724af972e07b93ca203922'
ListOfClassification
Kind: global class
-
ListOfClassification
-
.all() ⇒
Array
-
.findByLevel(level) ⇒
Object
-
.findByValue(value) ⇒
Object
-
.addItem(item) ⇒
boolean
-
.removeItem(item, [unique]) ⇒
boolean
-
.load(data) ⇒
boolean
-
.save() ⇒
Array
-
.all() ⇒
Array
listOfClassification.all() ⇒ Get all items of ListOfClassification
Kind: instance method of ListOfClassification
Returns: Array
- - An array containing all items
Example (Example usage of 'all' function)
let item = new Classification(1, 'geology'),
listOfClassification = new ListOfClassification();
listOfClassification.addItem(item);
listOfClassification.all(); // returns [item]
Object
listOfClassification.findByLevel(level) ⇒ Find items of ListOfClassification with matching level
Kind: instance method of ListOfClassification
Returns: Object
- - Items with given level
Param | Type | Description |
---|---|---|
level | number |
Item level |
Example (Example usage of 'findByLevel' function)
let item = new Classification(1, 'geology'),
listOfClassification = new ListOfClassification();
listOfClassification.addItem(item);
listOfClassification.findByLevel(1); // returns [item]
listOfClassification.findByLevel(0); // returns []
Object
listOfClassification.findByValue(value) ⇒ Find item of ListOfClassification with matching value
Kind: instance method of ListOfClassification
Returns: Object
- - Item with given value
Param | Type | Description |
---|---|---|
value | string |
Item value |
Example (Example usage of 'findByValue' function)
let item = new Classification(1, 'geology'),
listOfClassification = new ListOfClassification();
listOfClassification.addItem(item);
listOfClassification.findByValue('geology'); // returns [item]
listOfClassification.findByValue('test'); // returns []
boolean
listOfClassification.addItem(item) ⇒ Add item to ListOfClassification
Kind: instance method of ListOfClassification
Returns: boolean
- - True if it succed, else return false
Param | Type | Description |
---|---|---|
item | Classification |
Item that will be added |
Example (Example usage of 'addItem' function)
let item = new Classification(1, 'geology'),
listOfClassification = new ListOfClassification();
listOfClassification.addItem(item); // returns true
listOfClassification.addItem({'level': 1, 'value': 'geology'}); // returns false (because you must use an instance of Classification to success)
boolean
listOfClassification.removeItem(item, [unique]) ⇒ Add item to ListOfClassification
Kind: instance method of ListOfClassification
Returns: boolean
- - True if it succed, else return false
Param | Type | Default | Description |
---|---|---|---|
item | Classification |
Item that will be removed | |
[unique] | boolean |
false |
Will delete all items found by default, set true to delete only fisrt item found |
Example (Example usage of 'removeItem' function)
let item = new Classification(1, 'geology'),
listOfClassification = new ListOfClassification();
listOfClassification.addItem(item);
listOfClassification.addItem(item);
listOfClassification.addItem(item); // will contain 3 copies of 'item'
listOfClassification.removeItem(item, true); // returns true (remove first copy of item)
listOfClassification.removeItem(item); // returns true (remove all copy of item)
listOfClassification.removeItem(item); // returns false (because there is not anymore copy of item)
boolean
listOfClassification.load(data) ⇒ Load data
Kind: instance method of ListOfClassification
Returns: boolean
- - True if it succed, else return false
Param | Type | Description |
---|---|---|
data | Array |
Data that will be loaded (call all function to generate this data) |
Example (Example usage of 'load' function (success))
let item = new Classification(1, 'geology'),
data = new ListOfClassification(),
listOfClassification = new ListOfClassification();
data.addItem(item);
listOfClassification.load(data.save()); // returns true
Example (Example usage of 'load' function (fail))
let data = [{'1' :'geology'}], // invalid data, only use .save() function to build correct data structure that can be loaded
listOfClassification = new Classification();
listOfClassification.load(data); // returns false
Array
listOfClassification.save() ⇒ Save data
Kind: instance method of ListOfClassification
Returns: Array
- - An array representation of save
Example (Example usage of 'save' function)
let item = new Classification(1, 'geology'),
listOfClassification = new ListOfClassification();
listOfClassification.addItem(item);
listOfClassification.save(); // returns {'level': 1, 'value': 'geology'}
ListOfElement
Kind: global class
-
ListOfElement
-
.all() ⇒
Array
-
.findByIdentifier(identifier) ⇒
Object
-
.addItem(item) ⇒
boolean
-
.removeItem(item, [unique]) ⇒
boolean
-
.load(data) ⇒
boolean
-
.save() ⇒
Array
-
.all() ⇒
Array
listOfElement.all() ⇒ Get all items of ListOfElement
Kind: instance method of ListOfElement
Returns: Array
- - An array containing all items
Example (Example usage of 'all' function)
let item = new Element('xxx-xxx-xxx', myClassification), // According myClassification (instance of ListOfClassification) contain your data
listOfElement = new ListOfElement();
listOfElement.addItem(item);
listOfElement.all(); // returns [item]
Object
listOfElement.findByIdentifier(identifier) ⇒ Find items of ListOfElement with matching identifier
Kind: instance method of ListOfElement
Returns: Object
- - Items with given identifier
Param | Type | Description |
---|---|---|
identifier | number |
Item identifier |
Example (Example usage of 'findByIdentifier' function)
let item = new Element('xxx-xxx-xxx', myClassification), // According myClassification (instance of ListOfClassification) contain your data
listOfElement = new ListOfElement();
listOfElement.addItem(item);
listOfElement.findByIdentifier('xxx-xxx-xxx'); // returns [item]
listOfElement.findByIdentifier('x'); // returns []
boolean
listOfElement.addItem(item) ⇒ Add item to ListOfElement
Kind: instance method of ListOfElement
Returns: boolean
- - True if it succed, else return false
Param | Type | Description |
---|---|---|
item | Element |
Item that will be added |
Example (Example usage of 'addItem' function)
let item = new Element('xxx-xxx-xxx', myClassification), // According myClassification (instance of ListOfClassification) contain your data
listOfElement = new ListOfElement();
listOfElement.addItem(item); // returns true
listOfElement.addItem({'identifier': 'xxx-xxx-xxx', 'classifications': myClassification}); // returns false (because you must use an instance of Element to success)
boolean
listOfElement.removeItem(item, [unique]) ⇒ Add item to ListOfElement
Kind: instance method of ListOfElement
Returns: boolean
- - True if it succed, else return false
Param | Type | Default | Description |
---|---|---|---|
item | Element |
Item that will be removed | |
[unique] | boolean |
false |
Will delete all items found by default, set true to delete only fisrt item found |
Example (Example usage of 'removeItem' function)
let item = new Element('xxx-xxx-xxx', myClassification), // According myClassification (instance of ListOfClassification) contain your data
listOfElement = new ListOfElement();
listOfElement.addItem(item);
listOfElement.addItem(item);
listOfElement.addItem(item); // will contain 3 copies of 'item'
listOfElement.removeItem(item, true); // returns true (remove first copy of item)
listOfElement.removeItem(item); // returns true (remove all copy of item)
listOfElement.removeItem(item); // returns false (because there is not anymore copy of item)
boolean
listOfElement.load(data) ⇒ Load data
Kind: instance method of ListOfElement
Returns: boolean
- - True if it succed, else return false
Param | Type | Description |
---|---|---|
data | Array |
Data that will be loaded (call all function to generate this data) |
Example (Example usage of 'load' function)
let item = new Element('xxx-xxx-xxx', myClassification), // According myClassification (instance of ListOfClassification) contain your data
data = new ListOfElement(),
listOfElement = new ListOfElement();
data.addItem(item);
listOfElement.load(data.save()); // returns true
Example (Example usage of 'load' function (fail))
let data = [{'identifier': 'xxx-xxx-xxx', 'classifications': myClassification}], // invalid data, only use .save() function to build correct data structure that can be loaded
listOfElement = new Classification();
listOfElement.load(data); // returns false
Array
listOfElement.save() ⇒ Save data
Kind: instance method of ListOfElement
Returns: Array
- - An array representation of save
Example (Example usage of 'save' function)
let item = new Element('xxx-xxx-xxx', myClassification), // According myClassification (instance of ListOfClassification) contain your data
listOfElement = new ListOfElement();
listOfElement.addItem(item);
listOfElement.save(); // returns [{"identifier": 1, "classifications": [Classification]]
ListOfTable
Kind: global class
-
ListOfTable
-
.all() ⇒
Array
-
.findByIdentifier(identifier) ⇒
Object
-
.addItem(item) ⇒
boolean
-
.removeItem(item, [unique]) ⇒
boolean
-
.load(data) ⇒
boolean
-
.save() ⇒
Array
-
.all() ⇒
Array
listOfTable.all() ⇒ Get all items of ListOfTable
Kind: instance method of ListOfTable
Returns: Array
- - An array containing all items
Example (Example usage of 'all' function)
let item = new Table(),
listOfTable = new ListOfTable();
// According item (instance of Table) has been fit with your data
listOfTable.addItem(item);
listOfTable.all(); // returns [item]
Object
listOfTable.findByIdentifier(identifier) ⇒ Find items of ListOfTable with matching identifier
Kind: instance method of ListOfTable
Returns: Object
- - Items with given identifier
Param | Type | Description |
---|---|---|
identifier | number |
Item identifier |
Example (Example usage of 'findByIdentifier' function)
let item = new Table('xxx-xxx-xxx', {'title': 'Description of this table'}),
listOfTable = new ListOfTable();
listOfTable.addItem(item);
listOfTable.findByIdentifier('xxx-xxx-xxx'); // returns [item]
listOfTable.findByIdentifier('x'); // returns []
boolean
listOfTable.addItem(item) ⇒ Add item to ListOfTable
Kind: instance method of ListOfTable
Returns: boolean
- - True if it succed, else return false
Param | Type | Description |
---|---|---|
item | Table |
Item that will be added |
Example (Example usage of 'addItem' function)
let item = new Table('xxx-xxx-xxx', {'title': 'Description of this table'}),
listOfTable = new ListOfTable();
listOfTable.addItem(item); // returns true
listOfTable.addItem({'xxx-xxx-xxx': {'title': 'Description of this table'}}); // returns false (because you must use an instance of Table to success)
boolean
listOfTable.removeItem(item, [unique]) ⇒ Remove item to ListOfTable
Kind: instance method of ListOfTable
Returns: boolean
- - True if it succed, else return false
Param | Type | Default | Description |
---|---|---|---|
item | Table |
Item that will be removed | |
[unique] | boolean |
false |
Will delete all items found by default, set true to delete only fisrt item found |
Example (Example usage of 'removeItem' function)
let item = new Table('xxx-xxx-xxx', {'title': 'Description of this table'}),
listOfTable = new ListOfTable();
listOfTable.addItem(item);
listOfTable.addItem(item);
listOfTable.addItem(item); // will contain 3 copies of 'item'
listOfTable.removeItem(item, true); // returns true (remove first copy of item)
listOfTable.removeItem(item); // returns true (remove all copy of item)
listOfTable.removeItem(item); // returns false (because there is not anymore copy of item)
boolean
listOfTable.load(data) ⇒ Load data
Kind: instance method of ListOfTable
Returns: boolean
- - True if it succed, else return false
Param | Type | Description |
---|---|---|
data | Array |
Data that will be loaded (call all function to generate this data) |
Example (Example usage of 'load' function)
let item = new Table('xxx-xxx-xxx', {'title': 'Description of this table'}).save(),
data = new ListOfTable(),
listOfTable = new ListOfTable();
data.addItem(item);
listOfTable.load(data.save()); // returns true
Example (Example usage of 'load' function (fail))
let data = [{'identifier': 'xxx-xxx-xxx', 'classifications': myClassification}], // invalid data, only use .save() function to build correct data structure that can be loaded
listOfTable = new Classification();
listOfTable.load(data); // returns false
Array
listOfTable.save() ⇒ Save data
Kind: instance method of ListOfTable
Returns: Array
- - An array representation of save
Example (Example usage of 'save' function)
let item = new Table('xxx-xxx-xxx', {'title': 'Description of this table'}),
listOfTable = new ListOfTable();
listOfTable.addItem(item);
listOfTable.save(); // returns [[Table]]
Table
Kind: global class
-
Table
- new Table([identifier], [description])
-
instance
-
.addItem(item) ⇒
boolean
-
.removeItem(item, [unique]) ⇒
boolean
-
.load(data) ⇒
boolean
-
.save() ⇒
Object
-
.addItem(item) ⇒
-
static
-
.check(data) ⇒
boolean
-
.isValid(data) ⇒
boolean
-
.check(data) ⇒
new Table([identifier], [description])
Returns: Table
- - An instance of Table
Param | Type | Description |
---|---|---|
[identifier] | string |
Identifier of Table |
[description] | string |
Descripton of Table |
Example (Example usage of 'contructor' (with paramters))
let table = new Table('xxx-xxx-xxx', {'title': 'Description of this table'});
// returns an instance of Table with properties :
// - identifier : 'xxx-xxx-xxx'
// - description : {'title': 'Description of this table'} // Store data desribing this table here (scheme, title, summary, etc); no specific keys
// - elements : [ListOfElement]
// - classifications : [List]
// - register : {}
Example (Example usage of 'contructor' (with default values))
let table = new Table(); // According myClassification (instance of ListOfClassification) contain your data
// returns an instance of Table with properties :
// - identifier : null
// - description : null
// - elements : [ListOfElement]
// - classifications : [List]
// - register : {}
boolean
table.addItem(item) ⇒ Add item to Table
Kind: instance method of Table
Returns: boolean
- - True if it succed, else return false
Param | Type | Description |
---|---|---|
item | Element |
Item that will be added |
Example (Example usage of 'addItem' function)
let item = new Element('xxx-xxx-xxx', myClassification), // According myClassification (instance of ListOfClassification) contain your data
table = new Table();
table.addItem(item); // returns true
table.addItem({'xxx-xxx-xxx', myClassification}); // returns false (because you must use an instance of Classification to success)
boolean
table.removeItem(item, [unique]) ⇒ Remove item to Table
Kind: instance method of Table
Returns: boolean
- - True if it succed, else return false
Param | Type | Default | Description |
---|---|---|---|
item | Element |
Item that will be removed | |
[unique] | boolean |
false |
Will delete all items found by default, set true to delete only fisrt item found |
Example (Example usage of 'removeItem' function)
let item = new Element('xxx-xxx-xxx', myClassification), // According myClassification (instance of ListOfClassification) contain your data
table = new Table();
table.addItem(item);
table.addItem(item);
table.addItem(item); // will contain 3 copies of 'item'
table.removeItem(item, true); // returns true (remove first copy of item)
table.removeItem(item); // returns true (remove all copy of item)
table.removeItem(item); // returns false (because there is not anymore copy of item)
boolean
table.load(data) ⇒ Load data
Kind: instance method of Table
Returns: boolean
- - True if it succed, else return false
Param | Type | Description |
---|---|---|
data | Object |
Data that will be loaded (call save function to generate this data) |
Example (Example usage of 'load' function (success))
let data = new Table('xxx-xxx-xxx', {'title': 'Description of this table'}).save();
table = new Table();
table.load(data); // returns true
console.log(table); // outuput : [Element]
Example (Example usage of 'load' function (fail))
let data = {'xxx-xxx-xxx': {'title': 'Description of this table'}}, // invalid data, only use .save() function to build correct data structure that can be loaded
table = new Table();
table.load(data); // returns false
console.log(table); // outuput : [Element] (with default values)
Object
table.save() ⇒ Save data
Kind: instance method of Table
Returns: Object
- - An object representation of save
Example (Example usage of 'save' function)
let table = new Table('xxx-xxx-xxx', {'title': 'Description of this table'});
table.save(); // returns {'identifier': 'xxx-xxx-xxx', 'description': {}, ...]}
boolean
Table.check(data) ⇒ Check data before load
Kind: static method of Table
Returns: boolean
- - True if it succed, else return false
Param | Type | Description |
---|---|---|
data | Object |
Data that will be checked (call save function to generate this data) |
Example (Example usage of 'check' function (success))
let table = new Table('xxx-xxx-xxx', {'title': 'Description of this table'}).save();
Table.check(table); // returns true
Example (Example usage of 'check' function (fail))
let table = {'xxx-xxx-xxx': {'title': 'Description of this table'}}; // invalid data, only use .save() function to build correct data structure that can be loaded
Table.check(table); // returns false
boolean
Table.isValid(data) ⇒ Validate data
Kind: static method of Table
Returns: boolean
- - True if it succed, else return false
Param | Type | Description |
---|---|---|
data | Object |
Data that will be check (call save function to generate this data) |
Example (Example usage of 'isValid' function (success))
let table = new Table('xxx-xxx-xxx', {'title': 'Description of this table'});
Table.isValid(table); // returns true
Example (Example usage of 'isValid' function (fail))
let table = {'xxx-xxx-xxx': {'title': 'Description of this table'}}; // invalid data, only use new Table() to build valid data
Table.isValid(table); // returns false
function
callback : Function called when procces end
Kind: global typedef
Param | Type | Description |
---|---|---|
err | Error |
Process erros |
res |
string | number | Object | Array
|
Result data |