mesqueeb / filter-anything Goto Github PK
View Code? Open in Web Editor NEWA simple (TypeScript) integration of "pick" and "omit" to filter props of an object
Home Page: https://npmjs.com/filter-anything
License: MIT License
A simple (TypeScript) integration of "pick" and "omit" to filter props of an object
Home Page: https://npmjs.com/filter-anything
License: MIT License
ok, I have a minimal (I think) reproduction of this, with a test https://github.com/xenoterracide/merge-anything-compilation-issue,
before you can work with this, you'll have to fix the compilation issue mentioned in mesqueeb/merge-anything#13. You can just edit the .yarnrc.yml
file, and uncomment the merge-anything
lines, and then run yarn && yarn test
.
import { omit } from 'filter-anything'
const togglePropsa = {
props: {
modelValue: String,
},
emits: {
'update:modelValue': (pressed: boolean) => String,
'pressedChange': (pressed: boolean) => String,
'click': (event: MouseEvent) => String,
},
}
const test = omit(togglePropsa.emits, ['update:modelValue', 'pressedChange'])
ts dont omit see
import { omit } from 'filter-anything'
const obj1 = {
a: 1,
b: 2,
c: 3,
}
const obj2 = {
a: 2,
c: 3,
d: 4,
}
type CommonKeys = Extract<keyof typeof obj1, keyof typeof obj2> // 'a' | 'c'
const commonKeyss = Object.keys(obj1).filter(key => obj2.hasOwnProperty(key)) as CommonKeys[] // ['a', 'c']
const aa = omit(obj1, commonKeyss)
aa. // dont working dont a see only `b`
Ability to filter out fields in an array of objects.
var ash = {
name: 'Ash Catch Em',
badges: [
{name: 'Otoshi', year: 2001}
{name: 'Mismagius', year: 2003}
{name: 'Nando', year: 1999}
]
}
const filter = require('filter-anything');
console.log(filter.omit(ash, ['badges.year']));
/*
name: 'Ash Catch Em',
badges: [
{name: 'Otoshi'}
{name: 'Mismagius'}
{name: 'Nando'}
]
}
*/
I guess syntax would have to be different, since omitting 'badges.year'
would remove {badges: {year: ___}
in addition to {badges: [{year: ___}, ... ] }
. Maybe ['badges].year'
to specify that badges is an array of objects you want to omit the field year
from?
Why is there a check for plain object? Any class with public properties should work as well.
@mesqueeb I noticed that omit allows keys that aren't preset in the original record.
if you swap the key and record definition, it'll enforce the record's types
export declare function omit<K extends string, T extends Record<K, any>>(obj: T, keys: F.AutoPath<T, K>[]): U.Merge<O.P.Omit<T, S.Split<K, '.'>>>;
export declare const guard: typeof omit;
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.