Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move isCustomFieldDescription guard into the customField directory #936

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
// License: LGPL-3.0-or-later
import { parseCustomField } from "./legacy";
import has from 'lodash/has';
import get from 'lodash/get';

export interface CustomFieldDescription {
name: NonNullable<string>;
label: NonNullable<string>;
type: 'supporter';
}

export function isCustomFieldDescription(item:unknown) : item is CustomFieldDescription {
return typeof item == 'object' &&
has(item, 'name') &&
has(item, 'label') &&
['supporter'].includes(get(item, 'type'));
}


export default parseCustomField;
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
// License: LGPL-3.0-or-later
import has from 'lodash/has';
import get from 'lodash/get';
import { parse } from 'json5';
import { CustomFieldDescription } from '../customField';
import { CustomFieldDescription, isCustomFieldDescription } from '../customField';

function isCustomFieldDesc(item:unknown) : item is CustomFieldDescription {
return typeof item == 'object' &&
has(item, 'name') &&
has(item, 'label') &&
['supporter'].includes(get(item, 'type'));
}
export default class JsonStringParser {
public errors:SyntaxError[] = [];
public readonly results: CustomFieldDescription[] = [];
Expand All @@ -27,7 +19,7 @@ export default class JsonStringParser {
const result = parse(this.fieldsString)
if (result instanceof Array) {
result.forEach((i) => {
if (isCustomFieldDesc(i)) {
if (isCustomFieldDescription(i)) {
this.results.push({ ...i});
}

Expand Down
Loading