firstkey
Returns the first key found on an object from a list of keys
Last updated 14 years ago by mattesch .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install firstkey 
SYNC missed versions from official npm registry.

firstKey Build Status

Returns the first key found on an object from a list of keys

Example

    var obj = {
        word1: 'The',
        word2: 'quick',
        word5: 'jumped',
        word8: 'lazy'
    },
    
    key = firstKey(obj, 'word3', 'word5', 'word7');  // First key found is 'word5'

Pull the first property from a dom node that exists and reuse that property

  • Choosing the text property to use

     var div = document.createElement('div'),
         text = firstKey(div, 'textContent', 'innerText', 'innerHTML');
         
     div[text] = 'Let\'s use the best property for setting the text';
    
  • Identifying the vendor-specific property to use, so that you don't set them all needlessly

     var divElement = document.createElement('div'),
     
     transformProperty = firstKey(
         divElement.style,
         'transform',
         'webkitTransform',
         'MozTransform',
         'oTransform',
         'msTransform');
    
     transformOriginProperty = firstKey(
         divElement.style,
         'transformOrigin',
         'webkitTransformOrigin',
         'MozTransformOrigin',
         'oTransformOrigin',
         'msTransformOrigin');
    

Installation

npm install firstkey

Contributors

  • Matt-Esch

MIT Licenced

Current Tags

  • 0.1.0                                ...           latest (14 years ago)

1 Versions

  • 0.1.0                                ...           14 years ago
Maintainers (1)
Downloads
Total 1
Today 0
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE