new List( GedCom , Caller )
List class contains items.
Parameters:
Name | Type | Description |
---|---|---|
GedCom |
GedCom | GedCom parser instance |
Caller |
mixed | Caller instance where the class is being called |
- Copyright:
-
- Dávid Imre 2016. See full of rights.
Extends
Members
-
(private) caller :mixed
-
Caller instance where the class has been called.
Type:
- mixed
-
(private) constructors :Array.<string>
-
Class chaining.
Type:
- Array.<string>
- Inherited From:
-
(private) gedcom :GedCom
-
GedCom parser instance.
Type:
-
(readonly) idPattern :string
-
Default item ID pattern. The List#create method will append the index before last @.
Type:
- string
-
(private) items :Object
-
Items.
Type:
- Object
-
(private) length :Number
-
Items length.
Type:
- Number
-
(private) pointer :Number
-
Items pointer.
Type:
- Number
Methods
-
add( …id [, item] ) → {List}
-
Adds an item.
Parameters:
Name Type Argument Description id
List|Data|Object|Number|string <repeatable>
Added items as List, or added item as Data, or added item ID as Number or string item
Data <optional>
Added item, required if argument 1 is an item ID Returns:
-
{List} - Self instance
Examples:
new List(<gedcom>, <instance>).add(new List(<gedcom>, <instance>));
new List(<gedcom>, <instance>).add(new Data(<gedcom>, <instance>));
new List(<gedcom>, <instance>).add(<id>, new Data(<gedcom>, <instance>));
-
-
copy( ) → {List}
-
Copies Self instance to a new list.
Returns:
-
{List} - Copied list
Example:
new List(<gedcom>, <instance>).copy();
-
-
create( type [, properties] ) → {Data}
-
Creates a new item in list.
Parameters:
Name Type Argument Description type
Data Type of new item that is a Data or extends of Data properties
Object <optional>
Object which will be imported Returns:
-
{Data} - The new item
-
-
each( func ) → {boolean}
-
Iterates items.
Parameters:
Name Type Description func
ListIterator The iterator that will be executed on every item. Returns:
-
{boolean} - When true, iteration is executed, false otherwise
Example:
new List(<gedcom>, <instance>).each(function(id, item, index){ document.write(id + ': ' + item.toString()); });
-
-
extend( opts ) → {boolean}
-
Merge the contents of passed Object into the Self instance.
Parameters:
Name Type Description opts
Object Extended options - Inherited From:
Returns:
-
{boolean} - True if extending is succeeded, false otherwise
Example:
new Base().extend({ <property>: <value>, <method>: function(){ } });
-
filter( …list1 [, value] ) → {List}
-
Reduces the set of matched items to those that match the passed items.
Parameters:
Name Type Argument Description list1
List|Data|Number|string|Array <repeatable>
Filtered items as List, or filtered item as Data, or filtered item ID as Number or string, or key of a filtered property as Array value
mixed <optional>
Filtered item value, required if Argument 1 is key of a property Returns:
-
{List} - Reduced list
Examples:
new List(<gedcom>, <instance>).filter(new List(<gedcom>, <instance>), new List(<gedcom>, <instance>));
new List(<gedcom>, <instance>).filter(new Data(<gedcom>, <instance>), new Data(<gedcom>, <instance>));
new List(<gedcom>, <instance>).filter(<id1>, <id2>);
new List(<gedcom>, <instance>).filter(['NAME', 'FIRST'], <value>);
-
-
(private) filterByKeyAndValue( key , value ) → {List}
-
Reduces the set of matched items to whose property value match the passed property value.
Parameters:
Name Type Description key
Array Key of a filtered property value
mixed Filtered item value Returns:
-
{List} - Reduced list
Example:
new List(<gedcom>, <instance>).filterByKeyAndValue(['NAME', 'FIRST'], <value>);
-
-
first( ) → {Data}
-
Get the first item.
Returns:
-
{Data} - First item
Example:
new List(<gedcom>, <instance>).first();
-
-
fromObject( object , deep ) → {List}
-
Imports items from a specific primitive Object.
Parameters:
Name Type Description object
Object Object which will be imported deep
boolean When true, the import will run recursively Returns:
-
{List} - Self instance
Examples:
new List(<gedcom>, <instance>).from(new Object({ type: 'List', items: new Object({ <id1>: new Object({ props: { 'NAME': new Object({ props: { //RECURSIVELY }, value: <value>, type: 'Data' } }, value: <value>, type: 'Data' }, <id2>: new Object({ props: { 'NAME': new Object({ props: { //RECURSIVELY }, value: <value>, type: 'Data' } }, value: <value>, type: 'Data' }, <id3>: new Object({ props: { 'NAME': new Object({ props: { //RECURSIVELY }, value: <value>, type: 'Data' } }, value: <value>, type: 'Data' } }) }));
new List(<gedcom>, <instance>).from(new Object({ type: 'List', items: new Object({ <id1>: new Object({ props: { 'NAME': new Object({ props: { //RECURSIVELY }, value: <value>, type: 'Data' } }, value: <value>, type: 'Data' }, <id2>: new Object({ props: { 'NAME': new Object({ props: { //RECURSIVELY }, value: <value>, type: 'Data' } }, value: <value>, type: 'Data' }, <id3>: new Object({ props: { 'NAME': new Object({ props: { //RECURSIVELY }, value: <value>, type: 'Data' } }, value: <value>, type: 'Data' } }) }), true);
-
-
get( key ) → {Data}
-
Get an item
Parameters:
Name Type Description key
string|Number Pointer or an item ID Returns:
-
{Data} - Selected item
Example:
new List(<gedcom>, <instance>).get(<id>);
-
-
(private) getCaller( ) → {mixed}
-
Get the List caller instance.
Returns:
-
{mixed} - List caller instance or Self instance
Example:
new List(<gedcom>, <instance>).getCaller();
-
-
getHighestKey( ) → {string|Number}
-
Get the highest key of items.
Returns:
-
{string|Number} - Highest key of item
Example:
new List(<gedcom>, <instance>).getHighestKey();
-
-
getIdPattern( [id] ) → {string}
-
Get the default item ID pattern. The List#create method will append the index before last @.
Parameters:
Name Type Argument Description id
string|Number <optional>
ID that will be parsed Returns:
-
{string} - ID pattern
-
-
getIds( ) → {Array}
-
Get all items IDs
Returns:
-
{Array} - all items IDs
Example:
new List(<gedcom>, <instance>).getIds();
-
-
(private) getList( ) → {Object}
-
Get all items
Returns:
-
{Object} - Items set
Example:
new List(<gedcom>, <instance>).getList();
-
-
(private) getMethodName( [instance] , method [, method [, indexInStack]] ) → {string}
-
Get the method name.
Parameters:
Name Type Argument Description instance
mixed <optional>
A class instance method
function The method method
string <optional>
Calling stack, only used in strict mode indexInStack
number <optional>
Caller method index in stack, only used in strict mode - Inherited From:
Returns:
-
{string} - The method name
-
(private) getMethodParams( [instance] , method ) → {Array.<string>}
-
Get the method params.
Parameters:
Name Type Argument Description instance
mixed <optional>
A class instance method
string The method name - Inherited From:
Returns:
-
{Array.<string>} - The method params
-
getNextKey( ) → {string|Number}
-
Get the next key of items.
Returns:
-
{string|Number} - Next key of item
Example:
new List(<gedcom>, <instance>).getNextKey();
-
-
getProperties( property [, property] ) → {Array}
-
Get all items selected properties
Parameters:
Name Type Argument Description property
string|Array|boolean Key of selected property or when true, the property value will be converted to string property
string <optional>
Key of selected property, required if Argument 1 is a boolean Returns:
-
{Array} - Selected properties
Examples:
new List(<gedcom>, <instance>).getProperties('NAME');
new List(<gedcom>, <instance>).getProperties(true, 'NAME');
-
-
getType( ) → {string}
-
Get the type of a class.
- Inherited From:
Returns:
-
{string} - The type of a class
Examples:
new Properties(<gedcom>, <instance>).getType();
new List(<gedcom>, <instance>).getType();
new Data(<gedcom>, <instance>).getType();
-
(private) init( instance )
-
Creates a class.
Parameters:
Name Type Description instance
function Self class - Inherited From:
-
inList( id ) → {boolean}
-
Checks for a specified ID within items.
Parameters:
Name Type Description id
string|Number Checked item ID Returns:
-
{boolean} - True if item is found in items, false otherwise
Example:
new List(<gedcom>, <instance>).inList(<id>);
-
-
keys( [index] ) → {Array|string|Number}
-
Get all keys of items.
Parameters:
Name Type Argument Description index
Number <optional>
Index of selected key Returns:
-
{Array|string|Number} - All keys of items or selected key
Examples:
new List(<gedcom>, <instance>).key();
new List(<gedcom>, <instance>).key(10);
-
-
last( ) → {Data}
-
Get the last item
Returns:
-
{Data} - Last item
Example:
new List(<gedcom>, <instance>).last();
-
-
merge( …list ) → {List}
-
Merges any Lists into Self instance.
Parameters:
Name Type Argument Description list
List <repeatable>
Merged lists Returns:
-
{List} - Self instance
Example:
new List(<gedcom>, <instance>).merge( new List(<gedcom>, <instance>), new List(<gedcom>, <instance>) );
-
-
not( …list1 [, value] ) → {List}
-
Removes elements from the set of matched items.
Parameters:
Name Type Argument Description list1
List|Data|Number|string|Array <repeatable>
Not removed items as List, or not removed item as Data, or not removed item ID as Number or string, or key of not filtered property as Array value
mixed <optional>
Not removed item value, required if Argument 1 is key of a property Returns:
-
{List} - Reduced list
Examples:
new List(<gedcom>, <instance>).not(new List(<gedcom>, <instance>), new List(<gedcom>, <instance>));
new List(<gedcom>, <instance>).not(new Data(<gedcom>, <instance>), new Data(<gedcom>, <instance>));
new List(<gedcom>, <instance>).not(<id1>, <id2>);
new List(<gedcom>, <instance>).not(['NAME', 'FIRST'], <value>);
-
-
orderBy( …key [, …sort] ) → {List}
-
Orders items by property
Parameters:
Name Type Argument Default Description key
string|Array <repeatable>
Key of selected property sort
Types.Order <optional>
<repeatable>
Types.Order.Asc Order type Returns:
-
{List} - Ordered list
Examples:
new List(<gedcom>, <instance>).orderBy('NAME', Types.Order.Asc);
new List(<gedcom>, <instance>).orderBy(['NAME', 'FIRST'], Types.Order.Asc, 'BIRTHDAY', Types.Order.Desc);
-
-
remove( id ) → {List}
-
Removes an item.
Parameters:
Name Type Description id
Number|string Removed item ID Returns:
-
{List} - Self instance
Example:
new List(<gedcom>, <instance>).remove(<id>);
-
-
set( key , value )
-
Set an item
Parameters:
Name Type Description key
string|Number Pointer or an item ID value
Data Item value Example:
new List(<gedcom>, <instance>).set(<id>, new Data(<gedcom>, <instance>);
-
(private) setCaller( instance ) → {mixed}
-
Set the Data caller instance.
Parameters:
Name Type Description instance
mixed The List caller instance Returns:
-
{mixed} - Self instance
Example:
new List(<gedcom>, <instance>).setCaller(<instance>);
-
-
setList( list ) → {Object}
-
Set all items
Parameters:
Name Type Description list
Object New items set Returns:
-
{Object} - Items set
Example:
new List(<gedcom>, <instance>).setList(new Object({ <id1> : new Data(<gedcom>, <instance>), <id2> : new Data(<gedcom>, <instance>), <id3> : new Data(<gedcom>, <instance>) }));
-
-
toArray( [deep] ) → {Array}
-
Converts items to Array.
Parameters:
Name Type Argument Default Description deep
boolean <optional>
false When true, the convert will run recursively Returns:
-
{Array} - Converted items
Example:
new List(<gedcom>, <instance>).toArray();
-
-
toGedCom( ) → {string}
-
Converts items to GEDCOM structure string.
Returns:
-
{string} - GEDCOM structure string
Example:
new List(<gedcom>, <instance>).toGedCom();
-
-
toObject( [deep] ) → {Object}
-
Converts items to a specific pritimive Object.
Parameters:
Name Type Argument Default Description deep
boolean <optional>
false When true, the convert will run recursively Returns:
-
{Object} - Converted items
Example:
new List(<gedcom>, <instance>).toObject();
-
-
toString( [returnMethod] ) → {string}
-
Converts items to string.
Parameters:
Name Type Argument Description returnMethod
string <optional>
Custom convert method to get every item value as string Returns:
-
{string} - List item IDs or type of list if IDs getter is undefined
Examples:
new List(<gedcom>, <instance>).toString();
new List(<gedcom>, <instance>).toString('getIds');
-
-
(private) validateKey( key ) → {string|Number}
-
Validates key of an item. If Argument 1 is an item as Data, item ID will be returned.
Parameters:
Name Type Description key
string|Number|Data Key of an item or item as Data Returns:
-
{string|Number} - Key of an item
Examples:
new List(<gedcom>, <instance>).validateKey(<id>);
new List(<gedcom>, <instance>).validateKey(new Data(<gedcom>, <instance>);
-