Giter Club home page Giter Club logo

filter-anything's Issues

dont work dynamic array

import { omit } from 'filter-anything'

const aaa = ['hasThumb', 'sizes']

const dd = omit({
      hasThumb: {
        type: Boolean,
        required: true,
      },
      sizes: {
        type: String
        required: true,
      },
    }, aaa)
CleanShot 2023-09-11 at 06 00 09@2x

omit ts bug - dont correct type automatically

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'])

image

ts dont omit see

how to dynamic omit

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` 
CleanShot 2023-09-11 at 05 42 09@2x

Feature Request: Ability to filter out fields in an array of objects.

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?

Key type safety

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

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.