1.0.3 • Published 5 years ago
hash-fetch v1.0.3
Adds Ruby style fetch
to hashes in JavaScript.
###Usage:
let hash = {first: 'Mister', last: 'Singh'};
hash = addFetch(nameHash);
Normal Access
hash['first'] // works and gives 'Mister'
hash['i-dont-exist'] // does not throw an error and gives undefined
Access via fetch
hash.fetch('first') // works and gives 'Mister'
hash.fetch('i-dont-exist') // throws an error
How to prevent modification of the original hash
let hash = {first: 'Mister', last: 'Singh'};
let newHash = addFetch(Object.assign({}, nameHash));
console.log(hash.fetch); //undefined
console.log(newHash.fetch); // Function