Skip to content

A friendly human-legible filter library. A couple exported functions, 🎢 just two: get, by 🎢.

Notifications You must be signed in to change notification settings

burge-is/just_two

Folders and files

NameName
Last commit message
Last commit date

Latest commit

a6ab9d3 Β· Jun 2, 2019

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

what?

I woke up with a haunting pun stuck in my head. And thus just_two npm version was born.

The original idea was that I was going to make a human readable array filter by chaining just two functions: get and by

.
└── get( Array || Object )
    └── by( String )
// ie
.
└── get( swallows )
    └── by( "plummage" )
this is the array we are searching
// i.e.
const arr = [
  {
    test: 1,
    color: "blue",
    nest: {
      birds: 4
    }
  },
  {
    test: 1,
    color: "red"
  },
  {
    test: 2,
    color: "red"
  },
  {
    test: 1,
    color: "red",
    nest: {
      birds: 3
    }
  }
];
const getByColor = get(array).by("color");
getByColor("blue");
get(array).by("color")("blue");
get(array).by("color", "blue");
get(array).by("nest.birds", 4);
/* all return
[
  {
    test: 1,
    color: "blue",
    nest: {
      birds: 4
    }
  }
]
*/

When I stopped typing and looked up there were a couple more functions than the original two. This update allows for chaining more expressions using language like and, or, equals, notEquals, greaterThan, and lessThan. The result is a human-readable array filter that isn't so anonymous-function-heavy.

.
└── get( Array || Object )
    └── by
        └── ...

( Array || Object ).
└── by
    β”œβ”€β”€ and
    β”œβ”€β”€ or
    β”œβ”€β”€ equals
    β”œβ”€β”€ notEquals
    β”œβ”€β”€ greaterThan
    β”œβ”€β”€ lessThan
get(array).by("color")("red").and('test', 1).or('test').equals(2).and('nest.birds').greaterThan(2);
/* returns
[
  {
    test: 1,
    color: "red",
    nest: {
      birds: 3
    }
  }
]
*/

About

A friendly human-legible filter library. A couple exported functions, 🎢 just two: get, by 🎢.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published