divyagnan / hnt Goto Github PK
View Code? Open in Web Editor NEW๐ฆ Small library to safely access (hunt for ๐) deeply nested array values
License: MIT License
๐ฆ Small library to safely access (hunt for ๐) deeply nested array values
License: MIT License
hnt is useful but sometimes you want to do things other than just access a value.
For example you may want to get a value and if that value is a certain number to greater than a certain number you may want to do something. In other words you might want to use hnt for equality checks:
import { eql } from "hnt";
// first two params are the same as hnt, last param is what value should be checked
// if deepArray[0][0][0] === 0 then eql will return true,
// otherwise (if it is undefined or equals something else) it will return false
eql(deepArray, "[0][0][0]", 0);
Consider this:
import hnt from 'hnt'
function getResult(): any[] | null {
...
}
const result = getResult()
console.log(htn(result, 'data[0]', {})
With the signature as it stands, the console
would fail. Rather than having to explicitly check if array
's null before passing it on to htn
, it would be desirable to do so implicitly:
export function hnt(array: any[] | null, path: string, fallback: any) {
if (array === null) return fallback
...
Right now way of writing the access path is a little weird (you need to write it 'relative' to the array you pass in). Maybe it would be easier you could pass in the full access path.
i.e.
now assuming you have this array:
let array = [{ name: "divy" }]
you have to do this:
let accessPath = "[0].name"
but it might be better to allow both that and this:
let accessPath = "array[0].name"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.