@smakss/search
Advanced tools
Comparing version 2.0.0-beta.0 to 2.0.0-beta.1
@@ -5,5 +5,5 @@ import { SearchItem } from './types'; | ||
*/ | ||
interface SearchOptions<T> { | ||
interface SearchOptions { | ||
searchText: string; | ||
searchItems: Array<SearchItem<T>>; | ||
searchItems: SearchItem[]; | ||
keys: string[]; | ||
@@ -37,3 +37,3 @@ include: boolean; | ||
*/ | ||
declare function search<T>({ searchText, searchItems, keys, include, exact }: Partial<SearchOptions<T>>): Array<SearchItem<T>>; | ||
declare function search({ searchText, searchItems, keys, include, exact }: Partial<SearchOptions>): SearchItem[]; | ||
export default search; |
@@ -39,3 +39,3 @@ 'use strict'; | ||
*/ | ||
function shouldIncludeKey(keys, key, include) { | ||
function shouldIncludeKey(key, keys, include) { | ||
return include ? keys.includes(key) : !keys.includes(key); | ||
@@ -83,13 +83,12 @@ } | ||
function searchInObject(obj, filtered, keys, include, regex) { | ||
Object.entries(obj).forEach(([key, value]) => { | ||
if (shouldIncludeKey(keys, key, include)) { | ||
if (matchesRegex(value, regex)) { | ||
for (const [key, value] of Object.entries(obj)) { | ||
if (shouldIncludeKey(key, keys, include)) { | ||
if (typeof value === 'string' && matchesRegex(value, regex)) { | ||
addIfUnique(filtered, obj); | ||
} | ||
else if (Array.isArray(value)) { | ||
// This function call was previously incorrect; it should be "value" instead of "obj". | ||
searchInArray(value, filtered, keys, include, regex); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
@@ -114,3 +113,3 @@ /** | ||
function searchInArray(arr, filtered, keys, include, regex) { | ||
arr.forEach((item) => { | ||
for (const item of arr) { | ||
if (typeof item === 'string' && matchesRegex(item, regex)) { | ||
@@ -125,3 +124,3 @@ addIfUnique(filtered, item); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -159,4 +158,6 @@ | ||
searchItems.forEach((item) => { | ||
if (matchesRegex(item, regex)) { | ||
addIfUnique(filtered, item); | ||
if (typeof item === 'string') { | ||
if (matchesRegex(item, regex)) { | ||
addIfUnique(filtered, item); | ||
} | ||
} | ||
@@ -163,0 +164,0 @@ else if (Array.isArray(item)) { |
@@ -19,3 +19,3 @@ import { SearchItem } from './types'; | ||
*/ | ||
export declare function searchInObject<T>(obj: SearchItem<T>, filtered: SearchItem<T>[], keys: string[], include: boolean, regex: RegExp): void; | ||
export declare function searchInObject(obj: SearchItem, filtered: SearchItem[], keys: string[], include: boolean, regex: RegExp): void; | ||
/** | ||
@@ -38,2 +38,2 @@ * Searches through an array of items, adding matches to a filtered list. | ||
*/ | ||
export declare function searchInArray<T>(arr: Array<SearchItem<T>>, filtered: SearchItem<T>[], keys: string[], include: boolean, regex: RegExp): void; | ||
export declare function searchInArray(arr: SearchItem[], filtered: SearchItem[], keys: string[], include: boolean, regex: RegExp): void; |
@@ -1,3 +0,1 @@ | ||
export type SearchItem<T> = T & { | ||
[key: string]: string | SearchItem<T> | Array<SearchItem<T>>; | ||
}; | ||
export type SearchItem = Record<string, unknown>; |
@@ -34,3 +34,3 @@ import { SearchItem } from './types'; | ||
*/ | ||
export declare function shouldIncludeKey(keys: string[], key: string, include: boolean): boolean; | ||
export declare function shouldIncludeKey(key: string, keys: string[], include: boolean): boolean; | ||
/** | ||
@@ -52,2 +52,2 @@ * Adds an item to the filtered list if it is not already present. | ||
*/ | ||
export declare function addIfUnique<T>(filtered: SearchItem<T>[], item: SearchItem<T>): void; | ||
export declare function addIfUnique(filtered: SearchItem[], item: SearchItem): void; |
@@ -5,5 +5,5 @@ import { SearchItem } from './types'; | ||
*/ | ||
interface SearchOptions<T> { | ||
interface SearchOptions { | ||
searchText: string; | ||
searchItems: Array<SearchItem<T>>; | ||
searchItems: SearchItem[]; | ||
keys: string[]; | ||
@@ -37,3 +37,3 @@ include: boolean; | ||
*/ | ||
declare function search<T>({ searchText, searchItems, keys, include, exact }: Partial<SearchOptions<T>>): Array<SearchItem<T>>; | ||
declare function search({ searchText, searchItems, keys, include, exact }: Partial<SearchOptions>): SearchItem[]; | ||
export default search; |
@@ -35,3 +35,3 @@ /** | ||
*/ | ||
function shouldIncludeKey(keys, key, include) { | ||
function shouldIncludeKey(key, keys, include) { | ||
return include ? keys.includes(key) : !keys.includes(key); | ||
@@ -79,13 +79,12 @@ } | ||
function searchInObject(obj, filtered, keys, include, regex) { | ||
Object.entries(obj).forEach(([key, value]) => { | ||
if (shouldIncludeKey(keys, key, include)) { | ||
if (matchesRegex(value, regex)) { | ||
for (const [key, value] of Object.entries(obj)) { | ||
if (shouldIncludeKey(key, keys, include)) { | ||
if (typeof value === 'string' && matchesRegex(value, regex)) { | ||
addIfUnique(filtered, obj); | ||
} | ||
else if (Array.isArray(value)) { | ||
// This function call was previously incorrect; it should be "value" instead of "obj". | ||
searchInArray(value, filtered, keys, include, regex); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
@@ -110,3 +109,3 @@ /** | ||
function searchInArray(arr, filtered, keys, include, regex) { | ||
arr.forEach((item) => { | ||
for (const item of arr) { | ||
if (typeof item === 'string' && matchesRegex(item, regex)) { | ||
@@ -121,3 +120,3 @@ addIfUnique(filtered, item); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -155,4 +154,6 @@ | ||
searchItems.forEach((item) => { | ||
if (matchesRegex(item, regex)) { | ||
addIfUnique(filtered, item); | ||
if (typeof item === 'string') { | ||
if (matchesRegex(item, regex)) { | ||
addIfUnique(filtered, item); | ||
} | ||
} | ||
@@ -159,0 +160,0 @@ else if (Array.isArray(item)) { |
@@ -19,3 +19,3 @@ import { SearchItem } from './types'; | ||
*/ | ||
export declare function searchInObject<T>(obj: SearchItem<T>, filtered: SearchItem<T>[], keys: string[], include: boolean, regex: RegExp): void; | ||
export declare function searchInObject(obj: SearchItem, filtered: SearchItem[], keys: string[], include: boolean, regex: RegExp): void; | ||
/** | ||
@@ -38,2 +38,2 @@ * Searches through an array of items, adding matches to a filtered list. | ||
*/ | ||
export declare function searchInArray<T>(arr: Array<SearchItem<T>>, filtered: SearchItem<T>[], keys: string[], include: boolean, regex: RegExp): void; | ||
export declare function searchInArray(arr: SearchItem[], filtered: SearchItem[], keys: string[], include: boolean, regex: RegExp): void; |
@@ -1,3 +0,1 @@ | ||
export type SearchItem<T> = T & { | ||
[key: string]: string | SearchItem<T> | Array<SearchItem<T>>; | ||
}; | ||
export type SearchItem = Record<string, unknown>; |
@@ -34,3 +34,3 @@ import { SearchItem } from './types'; | ||
*/ | ||
export declare function shouldIncludeKey(keys: string[], key: string, include: boolean): boolean; | ||
export declare function shouldIncludeKey(key: string, keys: string[], include: boolean): boolean; | ||
/** | ||
@@ -52,2 +52,2 @@ * Adds an item to the filtered list if it is not already present. | ||
*/ | ||
export declare function addIfUnique<T>(filtered: SearchItem<T>[], item: SearchItem<T>): void; | ||
export declare function addIfUnique(filtered: SearchItem[], item: SearchItem): void; |
@@ -53,3 +53,3 @@ { | ||
"types": "lib", | ||
"version": "2.0.0-beta.0" | ||
"version": "2.0.0-beta.1" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
50001
580