Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.
Andrew Redican edited this page Dec 17, 2017 · 14 revisions

Read about all methods here

Examples

Dummy object used in examples:

const bicycles = [
  { 
    unique_id: 299,
    factory_id: 'alpha',
    model: 'br-chrome',
    maker: 'breez TM',
    year: '2017', type: 'racing',
    status: { hasOwner: false, price: 345.99 },
    specs : {
      dimensions: { length: '1.68m', width: '13cm', height: '1.02m' },
      usability: { grip : 5, speed : 4, accelaration : 8, weight: '', durability: 10 },
      color: 'silver',
      components: [ 'basket', 'chain', 'handle', 'seat' ]
    },
    sales: {
      date_arrived: 'Nov 30, 2017', date_showcased: 'Dec 4, 2017', date_sold: false,
      sale_opportunities: [
        { name: 'Donn Reddick',  contact_info: '1-987-652-8775', date: 'Dec 19, 2017'},
        { name: 'Susan Boyle',   contact_info: '1-555-101-9875', date: 'Dec 4, 2017'}
      ]
    }
  },

  { 
    unique_id: 300,
    factory_id: 'beta',
    model: 'XV17',
    maker: 'hyperwheel',
    year: '2017', type: 'city',
    status: { hasOwner: true, price: 1100 },
    specs : {
      dimensions: { length: '1.65m', width: '13cm', height: '1.03m' },
      usability: { grip : 5.5, speed : 3, accelaration : 5, weight: '', durability: 6 },
      color: 'red',
      components: [ 'basket', 'chain', 'handle', 'seat' ]
    },
    sales: {
      date_arrived: 'Nov 13, 2017',
      date_showcased: 'Nov 16, 2017',
      date_sold: false,
      sale_opportunities: [
        { name: 'Tom Stark', contact_info: 'N/A', date: ''},
        { name: "Jane O'Neil", contact_info: 'N/A', date: ''}
      ]
    }
  },

  { 
    unique_id: 301,
    factory_id: 'gamma',
    model: 'XV15',
    maker: 'hyperwheel',
    year: '2017',
    type: 'sport',
    status: { hasOwner: true, price: 1800 },
    specs : {
      dimensions: { length: '1.68m', width: '13cm', height: '1.02m' },
      usability: { grip : 5, speed : 4, accelaration : 8, weight: '', durability: 10 },
      color: 'red',
      components: [ 'basket', 'chain', 'handle', 'seat', 'kinetic lights' ]
    },
    sales: {
      date_arrived: 'Nov 28, 2017',
      date_showcased: 'Nov 29, 2017',
      date_sold: 'Nov 29, 2017',
      sale_opportunities: []
    }
  },

  { 
    unique_id: 302, factory_id: 'gamma',
    model: '2019 pro', maker: 'hyperwheel', year: '2018', type: 'racing',
    status: { hasOwner: false, price: 1499 },
    specs : {
      dimensions: { length: '1.69m', width: '11cm', height: '0.95m' },
      usability: { grip : 5, speed : 4, accelaration : 8, weight: '', durability: 10 },
      color: 'pink',
      components: [
          'basket',
          'chain',
          'handle',
          'seat',
          'reflector lights',
          'usb charger'
      ]
    },
    sales: {
      date_arrived: false, date_showcased: false, date_sold: false,
      sale_opportunities: []
    }
  }

];

countMatches( collection, identity, [optional=nthDepth], [optional=maxDepth] )

Performs deep search for identity on collection and returns the total number of matches. nthDepth parameter can be set to get the count of matches to specific to a particular depth. bicycles

    countMatches(bicycles,false)
    //returns: 7

    countMatches(bicycles,{ color : 'red'})
    //returns: 2

    countMatches(bicycles,'hyperwheel')
    //returns: 3

    countMatches(bicycles,{durability: 10})
    //returns: 3
     

maxDepth( identity , [optional=maxLayer] )

Walks through the entire object tree to return the maximum number of layers it contains. *Please note that maxLayer is the same as parameter maxDepth. To avoid confusion between the parameter and the function of the same, the paramenter's name has been changed to something different.

    maxDepth('Hello World')
    //returns: 0

    maxDepth({ A : 'Nested World' })
    //returns: 1

    maxDepth(['Foo','Bar'])
    //returns: 1

    maxDepth({ A: [1,2,3], B : { _b : [1,2,[3]] }})
    //returns: 4
     

matchDepth( collection , identity , [optional=maxDepth] )

Performs deep search for identity on collection to return the location's depth of the first match. If no match found, it returns false. bicycles

    matchDepth(bicycles,"Jane O'Neil")
    //returns: 5

    matchDepth(bicycles,{name: "Jane O'Neil"})
    //returns: 4

    matchDepth(bicycles,302)
    //returns: 2

locate_Key( collection , keyName , [optional=maxDepth] )

Performs deep search on collection to find a match to the key name, will return the path of the first instance matched. If no match found, it returns false. *Note: If you want to use something other than a key to find an identity use locate() instead. bicycles


    locate_Key(bicycles,'date_sold')
    //returns: '0.sales'

    locate_Key(bicycles,'date')
    //returns: '0.sales.sale_opportunities.0'

    locate_Key(bicycles,'silver')
    //returns: false

    locate_Key(bicycles,{name: "Jane O'Neil"})
    //returns: undefined

deepGet_Key( collection , keyName , [optional=maxDepth] )

Performs deep search on collection to find a match to the key name, and returns the first identity containing the match. If no match found, it returns undefined. *Note: If you want to use something other than a key to find an identity use deepGet() instead. bicycles


    deepGet_Key(bicycles,'date')
    //returns: 'Dec 19, 2017'

    deepGet_Key(bicycles,'silver')
    //returns: undefined

    deepGet_Key(bicycles,{name: "Jane O'Neil"})
    //returns: undefined

    deepGet_Key(bicycles,'type')
    //returns: 'racing'

locateAll_Key( collection , keyName , [optional=maxDepth] )

Performs deep search on collection to find all matches to the key name, returns the location of each match in a string array. If no matches found, it returns false. *Note: If you want to use something other than a key to find an identity use locateAll() instead. bicycles


    locateAll_Key(bicycles,'date')
    //returns: [
                  '0.sales.sale_opportunities.0',
                  '0.sales.sale_opportunities.1',
                  '1.sales.sale_opportunities.0',
                  '1.sales.sale_opportunities.1'
               ]

    locateAll_Key(bicycles,'maker')
    //returns: ['0','1','2','3']

deepFilter_Key( collection , keyName , [optional=maxDepth] )

Performs deep search on collection to find all matches to the key name, and returns a list of identities containing the matched instances. If no matches found, it returns undefined. *Note: If you want to use something other than a key to find an identity use deepFilter() instead. bicycles


    deepFilter_Key(bicycles,'date')
    //returns: ['Dec 19, 2017','Dec 4, 2017','',''] 

    deepFilter_Key(bicycles,'maker')
    //returns: ['breez TM','hyperwheel','hyperwheel','hyperwheel']