MCPcopy Create free account
hub / github.com/breck7/scroll / fetchData

Function fetchData

external/.datatables.js:1577–1635  ·  view source on GitHub ↗
(data, type, src)

Source from the content-addressed store, hash-verified

1575 * be used if defined, rather than throwing an error
1576 */
1577 var fetchData = function (data, type, src) {
1578 var arrayNotation, funcNotation, out, innerSrc
1579
1580 if (src !== "") {
1581 var a = _fnSplitObjNotation(src)
1582
1583 for (var i = 0, iLen = a.length; i < iLen; i++) {
1584 // Check if we are dealing with special notation
1585 arrayNotation = a[i].match(__reArray)
1586 funcNotation = a[i].match(__reFn)
1587
1588 if (arrayNotation) {
1589 // Array notation
1590 a[i] = a[i].replace(__reArray, "")
1591
1592 // Condition allows simply [] to be passed in
1593 if (a[i] !== "") {
1594 data = data[a[i]]
1595 }
1596 out = []
1597
1598 // Get the remainder of the nested object to get
1599 a.splice(0, i + 1)
1600 innerSrc = a.join(".")
1601
1602 // Traverse each entry in the array getting the properties requested
1603 if (Array.isArray(data)) {
1604 for (var j = 0, jLen = data.length; j < jLen; j++) {
1605 out.push(fetchData(data[j], type, innerSrc))
1606 }
1607 }
1608
1609 // If a string is given in between the array notation indicators, that
1610 // is used to join the strings together, otherwise an array is returned
1611 var join = arrayNotation[0].substring(1, arrayNotation[0].length - 1)
1612 data = join === "" ? out : out.join(join)
1613
1614 // The inner call to fetchData has already traversed through the remainder
1615 // of the source requested, so we exit from the loop
1616 break
1617 } else if (funcNotation) {
1618 // Function call
1619 a[i] = a[i].replace(__reFn, "")
1620 data = data[a[i]]()
1621 continue
1622 }
1623
1624 if (data === null || data[a[i]] === null) {
1625 return null
1626 } else if (data === undefined || data[a[i]] === undefined) {
1627 return undefined
1628 }
1629
1630 data = data[a[i]]
1631 }
1632 }
1633
1634 return data

Callers 1

.datatables.jsFile · 0.85

Calls 3

_fnSplitObjNotationFunction · 0.85
replaceMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected