1.0.2 • Published 3 years ago
object-line-finder v1.0.2
object-line-finder
Search for line number using an object's key. Object's keys must be strings and not numbers.
Table of Contents:
Getting Started
How To Install
Run:
npm i --save object-line-finder
Then:
const objectLineFinder = require("object-line-finder");
const example =
{
"firstName": "user",
"lastName": "a",
"age": 50
}
console.log(objectLineFinder(example, "age")); // [4]
Additional information
This Stackoverflow link talks about how elements of an object are looped in the order they are declared if all the keys are strings. However, keys that are numbers are always first.
Jest somehow adds an additional default
key that maps to the entire object. This causes the code to break. A temporary fix is to exclude the default key when doing the checks.
if (key === 'default') { break; }
Contributing
We welcome community contributions and pull requests.
The repo uses TypeScript. To compile, run:
npm run start