Skip to content

Commit

Permalink
Add support for boolean meta fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Jun 15, 2022
1 parent 89cc257 commit 69549b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/sites/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ function parseSearchVal(value: string, meta: MetaField): any | null {
}
} else if (meta.type === "input") {
return meta.parser ? meta.parser(value) : value;
} else if (meta.type === "bool") {
if (value === "true" || value === "yes" || value === "1") {
return true;
} else if (value === "false" || value === "no" || value === "0") {
return false;
}
return Boolean(value);
}
return null;
}
Expand Down
6 changes: 5 additions & 1 deletion src/sites/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ interface ISearchFormatType {
prefix?: string;
}

type MetaField = IMetaFieldOptions | IMetaTypeInput;
type MetaField = IMetaFieldOptions | IMetaTypeInput | IMetaTypeBoolean;
interface IMetaFieldBase {
label?: string;
default?: any;
Expand All @@ -585,6 +585,10 @@ interface IMetaTypeInput extends IMetaFieldBase {
type: "input";
parser?: (value: string) => any;
}
interface IMetaTypeBoolean extends IMetaFieldBase {
type: "bool";
default?: boolean;
}

type IParsedSearchQuery = ITag | IParsedSearchOperator;
interface IParsedSearchOperator {
Expand Down

0 comments on commit 69549b8

Please sign in to comment.