Code Monkey home page Code Monkey logo

hnt's People

Contributors

divyagnan avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

tjkandala

hnt's Issues

Helper functions

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);

Default null check

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
  ...

Better accessPath ergonomics

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"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.