FCF 2.0 development in progress...
> > > >
[News] [Packages API] [Downloads] [Donate to the project] [Contacts]

fcf.parseObjectAddress() function

[string|object] fcf.parseObjectAddress(string|[string|object] a_path, boolean a_exMode = false)

Package: fcf-framework-core

File: fcf-framework-core:fcf.js

Available from version: 2.0.2

Converts a string with the path to the object into an array with information about the elements

A path can be specified using several types of constructs:

  • Using the delimiter "." to separate fields: "field1.field2.field3" == ["field1", "field2", "field3"]
  • Using square brackets ("[" and "]"): "[field1][field2].field3" == ["field1", "field2", "field3"]
  • Using square brackets with declared strings enclosed in single or double quotes (slashes can be used to apply " or ' characters within a string): "['field1']['field2 \\' '].field3" = = ["field1", "field2 ' ", "field3"]
  • A field declared as an array: this is done using the double square bracket construction ([[FIELD_NAME]]), then if the function is executed in extended mode, the array property of the field description object becomes true. Example: Source: `field1[[field2]]`; Result: [{part: "field1", array: false}, {part: "field2", array: true}]

Arguments

string|[string|object] a_path
- Path address to the object, which can be either a string or an array describing the path to the object.

boolean a_exMode = false
- Extended Mode Flag:
  • If the flag is false - the function returns an array containing strings, where each string is a field name
  • If the flag is true - the function returns an array containing objects with a description of the characteristics of the field

    Object properties:

    • string part - Field name
    • boolean array - If equal to true then the field is specified as an array (declaration using double brackets [[FIELD_NAME]] ), if equal to false, then the field is specified in the usual way
Result
[string|object]
- Array of descriptions of component parts of the address
  • If the a_exMode flag is false - the function returns an array containing strings, where each string is a field name
  • If the a_exMode flag is true - the function returns an array containing objects with a description of the characteristics of the field

    Object properties:

    • string part - Field name
    • boolean array - If equal to true then the field is specified as an array (declaration using double brackets [[FIELD_NAME]] ), if equal to false, then the field is set in the usual way

Example: Function application

{ let result = fcf.parseObjectAddress("field1.field2"); console.log(`"field1.field2": `, result); } { let result = fcf.parseObjectAddress("field1[field2]"); console.log(`"field1[field2]": `, result); } { let result = fcf.parseObjectAddress("field1['field2']"); console.log(`"field1['field2']": `, result); } { let result = fcf.parseObjectAddress("field1['field2']", true); console.log(`"field1['field2']": `, result); } { let result = fcf.parseObjectAddress("field1[['field2']]", true); console.log(`"field1[['field2']]":`, result); }

Output:

"field1.field2": [ 'field1', 'field2' ] "field1[field2]": [ 'field1', 'field2' ] "field1['field2']": [ 'field1', 'field2' ] "field1['field2']": [ { part: 'field1', array: false }, { part: 'field2', array: false } ] "field1[['field2']]": [ { part: 'field1', array: false }, { part: 'field2', array: true } ]