1.1.1 • Published 5 years ago

tdm-multicat v1.1.1

Weekly downloads
7
License
OpenBSD
Repository
github
Last release
5 years ago

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

Classification

Kind: global class

new Classification(level, value)

Returns: Classification - - An instance of Classifier

ParamTypeDefaultDescription
levelnumber-1Classification Level
valuestringClassification 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

classification.load(data) ⇒ boolean

Load data

Kind: instance method of Classification
Returns: boolean - - True if it succed, else return false

ParamTypeDescription
dataObjectData 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'

classification.save() ⇒ Object

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'}

classification.toString() ⇒ string

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'

Classification.check(data) ⇒ boolean

Check data before load

Kind: static method of Classification
Returns: boolean - - True if it succed, else return false

ParamTypeDescription
dataObjectData 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

Classification.isValid(data) ⇒ boolean

Validate data

Kind: static method of Classification
Returns: boolean - - True if it succed, else return false

ParamTypeDescription
dataObjectData 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

new Classifier(options)

Returns: Classifier - - An instance of Classifier

ParamTypeDescription
optionsObjectOptions of constructor
options.tablesListOfTableAn 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)

classifier.getClassifications(elementId) ⇒ Array

Return categories of all Tables with given elementId

Kind: instance method of Classifier
Returns: Array - - An array containing all classification associated with this elementId

ParamTypeDescription
elementIdstringIdentifier 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 : []

classifier.getClassificationsOf(tableId, elementId) ⇒ Array

Get categories of given Table

Kind: instance method of Classifier
Returns: Array - - An array containing all classification associated with this elementId of given classification

ParamTypeDescription
tableIdstringIdentifier of classification
elementIdstringIdentifier 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 : []

classifier.getElements(classification) ⇒ Array.<Element>

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

ParamTypeDescription
classificationClassificationClassification 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)

classifier.getElementsOf(tableId, classification) ⇒ Array.<Element>

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

ParamTypeDescription
tableIdstringIdentifier of classification
classificationClassificationClassification 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 : []

classifier.getRegisters() ⇒ Object

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, ...] }

classifier.getRegistersOf(tableId) ⇒ Object

Get register of given Table

Kind: instance method of Classifier
Returns: Object - - An Object containing register

ParamTypeDescription
tableIdstringIdentifier of classification

Example (Example usage of 'getRegistersOf' function)

// According there is at least one element in table 'myTable'
classifier.getRegistersOf(); // returns : { ... }

classifier.load(filePath, cb) ⇒ undefined

Load data of given file (that must be create by save function)

Kind: instance method of Classifier
Returns: undefined - - undefined

ParamTypeDescription
filePathstringPath of file containing saved data
cbcallbackFunction 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

classifier.save(filePath, cb) ⇒ undefined

Save data at given filePath (that will be loaded by load function)

Kind: instance method of Classifier
Returns: undefined - - undefined

ParamTypeDescription
filePathstringPath of file that will contain saved data
cbcallbackFunction 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

new Element(identifier, classifications)

Returns: Element - - An instance of Element

ParamTypeDescription
identifierstringIdentifier of Element
classificationsListOfClassificationClassifications 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)

element.load(data) ⇒ boolean

Load data

Kind: instance method of Element
Returns: boolean - - True if it succed, else return false

ParamTypeDescription
dataObjectData 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)

element.save() ⇒ Object

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': [{}, ...]}

Element.check(data) ⇒ boolean

Check data before load

Kind: static method of Element
Returns: boolean - - True if it succed, else return false

ParamTypeDescription
dataObjectData 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

Element.isValid(data) ⇒ boolean

Validate data

Kind: static method of Element
Returns: boolean - - True if it succed, else return false

ParamTypeDescription
dataObjectData 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

new List(options)

Returns: List - - An instance of List

ParamTypeDescription
optionsObjectOptions of constructor
options.indexObjectAn object containing indexes
options.blackListKeyObjectAn object containing blacklisted keys (it will no be indexed)
options.collectionArrayAn 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 : []

list.all() ⇒ Array

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}]

list.indexesOf(index, value) ⇒ Array

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

ParamTypeDescription
indexstringWhich index will be used to search for
valuestringWich 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

list.findBy(index, value) ⇒ Array

Find item of List with matching index 'index' with value 'value'

Kind: instance method of List
Returns: Array - - An array of items founded

ParamTypeDescription
indexstringWhich index will be used
valuestringWich 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 []

list.findItem(item) ⇒ Array

Return item of List matching with given item

Kind: instance method of List
Returns: Array - - An array of items found, or empty Array

ParamTypeDescription
itemstring | number | boolean | ObjectItem 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 []

list.addItem(item) ⇒ number

Add item

Kind: instance method of List
Returns: number - - Length of collection

ParamTypeDescription
itemObjectItem 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

list.removeItem(item, unique) ⇒ boolean

Remove item

Kind: instance method of List
Returns: boolean - - True if it succed, else return false

ParamTypeDefaultDescription
itemObjectItem you want to remove
uniquebooleanfalseWill 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

list.addIndex(index, value, collectionIndex) ⇒ number

Add index

Kind: instance method of List
Returns: number - - Length of Index collection

ParamTypeDescription
indexstringIndex name
valuestringIndex Value
collectionIndexstringIndex (in collection) of item

Example (Example usage of 'addIndex' function)

let list = new List();
list.addIndex('test', true, 0); // return 1

list.removeIndex(index, value, collectionIndex) ⇒ number

Remove index

Kind: instance method of List
Returns: number - - Length of Index collection, or null

ParamTypeDescription
indexstringIndex name
valuestringIndex Value
collectionIndexstringIndex (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

list.refreshIndexes() ⇒ undefined

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.load(data) ⇒ List

Load data

Kind: instance method of List
Returns: List - - this

ParamTypeDescription
dataObjectData that will be loaded

Example (Example usage of 'load' function)

let list = new List();
list.load({'collection': [{'test': true}, {'test': false}]}); // return [List]

List.check(data) ⇒ boolean

Check data before load

Kind: static method of List
Returns: boolean - - True if it succed, else return false

ParamTypeDescription
dataObjectData 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

List.isValid(data) ⇒ boolean

Validate data

Kind: static method of List
Returns: boolean - - True if it succed, else return false

ParamTypeDescription
dataObjectData 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

List.getKey(value) ⇒ string

Build key of a given value

Kind: static method of List
Returns: string - - Generated key

ParamTypeDescription
valueObject | number | stringGiven 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

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]

listOfClassification.findByLevel(level) ⇒ Object

Find items of ListOfClassification with matching level

Kind: instance method of ListOfClassification
Returns: Object - - Items with given level

ParamTypeDescription
levelnumberItem 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 []

listOfClassification.findByValue(value) ⇒ Object

Find item of ListOfClassification with matching value

Kind: instance method of ListOfClassification
Returns: Object - - Item with given value

ParamTypeDescription
valuestringItem 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 []

listOfClassification.addItem(item) ⇒ boolean

Add item to ListOfClassification

Kind: instance method of ListOfClassification
Returns: boolean - - True if it succed, else return false

ParamTypeDescription
itemClassificationItem 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)

listOfClassification.removeItem(item, unique) ⇒ boolean

Add item to ListOfClassification

Kind: instance method of ListOfClassification
Returns: boolean - - True if it succed, else return false

ParamTypeDefaultDescription
itemClassificationItem that will be removed
uniquebooleanfalseWill 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)

listOfClassification.load(data) ⇒ boolean

Load data

Kind: instance method of ListOfClassification
Returns: boolean - - True if it succed, else return false

ParamTypeDescription
dataArrayData 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

listOfClassification.save() ⇒ Array

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

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]

listOfElement.findByIdentifier(identifier) ⇒ Object

Find items of ListOfElement with matching identifier

Kind: instance method of ListOfElement
Returns: Object - - Items with given identifier

ParamTypeDescription
identifiernumberItem 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 []

listOfElement.addItem(item) ⇒ boolean

Add item to ListOfElement

Kind: instance method of ListOfElement
Returns: boolean - - True if it succed, else return false

ParamTypeDescription
itemElementItem 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)

listOfElement.removeItem(item, unique) ⇒ boolean

Add item to ListOfElement

Kind: instance method of ListOfElement
Returns: boolean - - True if it succed, else return false

ParamTypeDefaultDescription
itemElementItem that will be removed
uniquebooleanfalseWill 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)

listOfElement.load(data) ⇒ boolean

Load data

Kind: instance method of ListOfElement
Returns: boolean - - True if it succed, else return false

ParamTypeDescription
dataArrayData 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

listOfElement.save() ⇒ Array

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

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]

listOfTable.findByIdentifier(identifier) ⇒ Object

Find items of ListOfTable with matching identifier

Kind: instance method of ListOfTable
Returns: Object - - Items with given identifier

ParamTypeDescription
identifiernumberItem 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 []

listOfTable.addItem(item) ⇒ boolean

Add item to ListOfTable

Kind: instance method of ListOfTable
Returns: boolean - - True if it succed, else return false

ParamTypeDescription
itemTableItem 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)

listOfTable.removeItem(item, unique) ⇒ boolean

Remove item to ListOfTable

Kind: instance method of ListOfTable
Returns: boolean - - True if it succed, else return false

ParamTypeDefaultDescription
itemTableItem that will be removed
uniquebooleanfalseWill 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)

listOfTable.load(data) ⇒ boolean

Load data

Kind: instance method of ListOfTable
Returns: boolean - - True if it succed, else return false

ParamTypeDescription
dataArrayData 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

listOfTable.save() ⇒ Array

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

new Table(identifier, description)

Returns: Table - - An instance of Table

ParamTypeDescription
identifierstringIdentifier of Table
descriptionstringDescripton 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 : {}

table.addItem(item) ⇒ boolean

Add item to Table

Kind: instance method of Table
Returns: boolean - - True if it succed, else return false

ParamTypeDescription
itemElementItem 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)

table.removeItem(item, unique) ⇒ boolean

Remove item to Table

Kind: instance method of Table
Returns: boolean - - True if it succed, else return false

ParamTypeDefaultDescription
itemElementItem that will be removed
uniquebooleanfalseWill 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)

table.load(data) ⇒ boolean

Load data

Kind: instance method of Table
Returns: boolean - - True if it succed, else return false

ParamTypeDescription
dataObjectData 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)

table.save() ⇒ Object

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': {}, ...]}

Table.check(data) ⇒ boolean

Check data before load

Kind: static method of Table
Returns: boolean - - True if it succed, else return false

ParamTypeDescription
dataObjectData 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

Table.isValid(data) ⇒ boolean

Validate data

Kind: static method of Table
Returns: boolean - - True if it succed, else return false

ParamTypeDescription
dataObjectData 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

callback : function

Function called when procces end

Kind: global typedef

ParamTypeDescription
errErrorProcess erros
resstring | number | Object | ArrayResult data
1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago