index.d.ts 1015 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. Filter object keys and values into a new object.
  3. @param object - Source object to filter properties from.
  4. @param predicate - Predicate function that detemines whether a property should be assigned to the new object.
  5. @param includeKeys - Property names that should be assigned to the new object.
  6. @example
  7. ```
  8. import filterObject = require('filter-obj');
  9. const object = {
  10. foo: true,
  11. bar: false
  12. };
  13. const newObject = filterObject(object, (key, value) => value === true);
  14. //=> {foo: true}
  15. const newObject2 = filterObject(object, ['bar']);
  16. //=> {bar: false}
  17. ```
  18. */
  19. declare function filterObject<ObjectType extends {[key: string]: any}>(
  20. object: ObjectType,
  21. predicate: (
  22. key: keyof ObjectType,
  23. value: ObjectType[keyof ObjectType]
  24. ) => boolean
  25. ): Partial<ObjectType>;
  26. declare function filterObject<
  27. ObjectType extends {[key: string]: any},
  28. IncludedKeys extends keyof ObjectType
  29. >(
  30. object: ObjectType,
  31. includeKeys: ReadonlyArray<IncludedKeys>
  32. ): Pick<ObjectType, IncludedKeys>;
  33. export = filterObject;