All Projects → mesqueeb → filter-anything

mesqueeb / filter-anything

Licence: MIT license
A simple (TypeScript) integration of "pick" and "omit" to filter props of an object

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to filter-anything

obj-filter
JavaScript Object Filter. Deep filtering key/content recursively. Support wildcard, nested, and filter function in template.
Stars: ✭ 13 (-31.58%)
Mutual labels:  filter, wildcard
object.omit
Return a copy of an object without the given keys.
Stars: ✭ 79 (+315.79%)
Mutual labels:  filter, omit
regXwild
⏱ Superfast ^Advanced wildcards++? | Unique algorithms that was implemented on native unmanaged C++ but easily accessible in .NET via Conari (with caching of 0x29 opcodes +optimizations) etc.
Stars: ✭ 20 (+5.26%)
Mutual labels:  filter, wildcard
php-simple-request
php-simple-request is a request parser library designed to simplify requests validation and filtering using annotations, generating at the same time an object representation from the request data.
Stars: ✭ 15 (-21.05%)
Mutual labels:  filter
mvbasic
MultiValue Basic extension for Visual Studio Code
Stars: ✭ 19 (+0%)
Mutual labels:  pick
imageman
Image manipulation library. Use Pixie instead.
Stars: ✭ 58 (+205.26%)
Mutual labels:  filter
FFmpeg-CRT-transform
CRT simulation without shaders... the slow way
Stars: ✭ 142 (+647.37%)
Mutual labels:  filter
romans
A Simple PHP Roman Numerals Library
Stars: ✭ 40 (+110.53%)
Mutual labels:  filter
wildmatch
Simple string matching with questionmark- and star-wildcard operator
Stars: ✭ 37 (+94.74%)
Mutual labels:  wildcard
lut
color lookup tables (LUTs) for color grading
Stars: ✭ 84 (+342.11%)
Mutual labels:  filter
ImageDownloader
A program for downloading and filtering images based on their resolution.
Stars: ✭ 60 (+215.79%)
Mutual labels:  filter
loadkit
Java 资源加载器,充分拓展ClassLoader#getResources(name)的能力,实现递归加载,支持普通风格 / 包名风格 / ANT风格 / 正则风格路径的资源加载同时支持自定义过滤器,通常作为框架的基础类库。
Stars: ✭ 39 (+105.26%)
Mutual labels:  filter
laravel-grid
A grid view for laravel, inspired by the yii2 grid widget
Stars: ✭ 86 (+352.63%)
Mutual labels:  filter
Qt OpenCV
Qt/QtQuick apps using OpenCV
Stars: ✭ 19 (+0%)
Mutual labels:  filter
paq8pxd
No description or website provided.
Stars: ✭ 55 (+189.47%)
Mutual labels:  filter
deep-state-observer
State library for high performance applications.
Stars: ✭ 25 (+31.58%)
Mutual labels:  wildcard
NanoSpace
Erela.js & Discord.js@v14 (Prefix Commands!)
Stars: ✭ 59 (+210.53%)
Mutual labels:  filter
photo-magician
🎨 provide some common image process apis with canvas
Stars: ✭ 12 (-36.84%)
Mutual labels:  filter
elastic-composer
Client-side Elasticsearch query generator and executor. Filter fields, find search suggestions, and paginate query results for your indicies using a simple, reactive, and high-level API
Stars: ✭ 14 (-26.32%)
Mutual labels:  filter
imu ekf
6-axis(3-axis acceleration sensor+3-axis gyro sensor) IMU fusion with Extended Kalman Filter.
Stars: ✭ 56 (+194.74%)
Mutual labels:  filter

Filter anything ⚔️

Total Downloads Latest Stable Version

npm i filter-anything

An implementation that filters out object props like the TypeScript "pick" and "omit". In the Laravel world, this is also called "fillables" and "guard".

Motivation

I created this package because I needed:

  • be able to filter out object props based on just what we need - aka "pick" props
  • be able to filter out object props based on what we don't need - aka "omit" props
  • supports for nested properties
  • supports wildcards * for nested properties
  • the return type must be TypeScript supported! (see screenshots below)

Meet the family

Usage

Pick

With pick you pass an object and an array of keys of an object - the props which may stay.

import { pick } from 'filter-anything'

const squirtle = { id: '007', name: 'Squirtle', type: 'water' }

const newObject = pick(squirtle, ['name', 'type'])
// returns { name: 'Squirtle', type: 'water' }

Omit

With omit you pass an object and an array of keys of an object - the props which should be removed.

import { omit } from 'filter-anything'

const squirtle = { id: '007', name: 'Squirtle', type: 'water' }

const withoutId = omit(squirtle, ['id'])
// returns { name: 'Squirtle', type: 'water' }

Aliases

pick() and omit() can also be imported with the names fillable() and guard(). This pays homage to my history with Laravel. 😉

TypeScript

TypeScript users will love this, because, as you can see, the result has the correct type automatically!

typescript example pick typescript example omit

Nested props

In the example below we want to get rid of the nested property called "discard".

const doc = { items: { keep: '📌', discard: '✂️' } }

pick(doc, ['items.keep'])
// returns {items: {keep: '📌'}}

omit(doc, ['items.discard'])
// returns {items: {keep: '📌'}}

Please note that TypeScript users will need to cast the result when using nested props.

Wildcards

Yes! You can also work with wildcards by using * in the path.

const doc = {
  123: { keep: '📌', discard: '✂️' },
  456: { keep: '📌', discard: '✂️' },
}
// use wildcard *
omit(doc, ['*.discard'])
// returns {
//   '123': {keep: '📌'},
//   '456': {keep: '📌'}
// }

Please note that TypeScript users will need to cast the result when using wildcards props.

Feel free to open issues for any requests, questions or bugs!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].