Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-hooks-library

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hooks-library - npm Package Compare versions

Comparing version 0.0.13 to 0.0.14

7

dist/hooks/useFilter.d.ts
import { IStateKey, IStateStore, IStateSetter } from './useParams';
declare type IEqual = ((filterState: any, dataValue: any) => boolean) | undefined;
interface IFilters {
[key: string]: {
equals: ((filterState: any, dataValue: any) => boolean) | undefined;
equals: IEqual;
};
}
declare type Itreater = (data: any[], filterStore: IStateStore) => any[];
export declare function useFilter(data: any[], keys: IStateKey, filters: IFilters, treater?: Itreater): [any, IStateStore, IStateSetter];
declare type Itreater<P> = (data: P[], filterStore: IStateStore) => P[];
export declare function useFilter<P>(data: P[], keys?: IStateKey, filters?: IFilters, treater?: Itreater<P>): [P[], IStateStore, IStateSetter];
export {};

@@ -6,13 +6,16 @@ import { useParams } from './useParams';

export function useFilter(data, keys, filters, treater) {
if (keys === void 0) { keys = {}; }
if (treater === void 0) { treater = function (income) { return income; }; }
var _a = useParams(keys), filterStore = _a[0], setFilterStoreByKey = _a[1];
return [
treater(data.filter(function (item) {
return Object.keys(filters).every(function (key) {
var comparer = filters[key].equals
? filters[key].equals
: defaultComparer;
return comparer(filterStore[key], item[key]);
});
}), filterStore),
treater(filters
? data.filter(function (item) {
return Object.keys(filters).every(function (key) {
var comparer = filters[key].equals
? filters[key].equals
: defaultComparer;
return comparer(filterStore[key], item[key]);
});
})
: data, filterStore),
filterStore,

@@ -19,0 +22,0 @@ setFilterStoreByKey,

{
"name": "react-hooks-library",
"version": "0.0.13",
"version": "0.0.14",
"license": "MIT",

@@ -5,0 +5,0 @@ "scripts": {

import { IStateKey, IStateStore, IStateSetter, useParams } from './useParams'
type IEqual = ((filterState: any, dataValue: any) => boolean) | undefined
interface IFilters {
[key: string]: {
equals: ((filterState: any, dataValue: any) => boolean) | undefined
equals: IEqual
}
}
type Itreater = (data: any[], filterStore: IStateStore) => any[]
type Itreater<P> = (data: P[], filterStore: IStateStore) => P[]
const defaultComparer = (filterState: any, dataValue: any) =>
const defaultComparer: IEqual = (filterState, dataValue) =>
filterState === dataValue
export function useFilter(
data: any[],
keys: IStateKey,
filters: IFilters,
treater: Itreater = (income: any[]) => income
): [any, IStateStore, IStateSetter] {
export function useFilter<P>(
data: P[],
keys: IStateKey = {},
filters?: IFilters,
treater: Itreater<P> = (income: P[]) => income
): [P[], IStateStore, IStateSetter] {
const [filterStore, setFilterStoreByKey] = useParams(keys)

@@ -24,11 +26,13 @@

treater(
data.filter(item =>
Object.keys(filters).every(key => {
const comparer = filters[key].equals
? filters[key].equals!
: defaultComparer
filters
? data.filter(item =>
Object.keys(filters).every(key => {
const comparer = filters[key].equals
? filters[key].equals
: defaultComparer
return comparer(filterStore[key], item[key])
})
),
return comparer!(filterStore[key], item[key])
})
)
: data,
filterStore

@@ -35,0 +39,0 @@ ),

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc