diff --git a/src/competencies/oNet.ts b/src/competencies/oNet.ts index 6d21e9b..eda4f8b 100644 --- a/src/competencies/oNet.ts +++ b/src/competencies/oNet.ts @@ -2,7 +2,7 @@ * A selection of abilities and skills from the O*NET 24.3 Database, sponsored * by the U.S. Department of Labor, Employment and Training Administration. * - * The database is licensed under a Creative Commons Attribution 4.0 + * The database is provided under a Creative Commons Attribution 4.0 * International License. * * {@link https://www.onetcenter.org/license_db.html} diff --git a/src/education/institutions/index.ts b/src/education/institutions/index.ts index 43c162d..eb9d313 100644 --- a/src/education/institutions/index.ts +++ b/src/education/institutions/index.ts @@ -21,7 +21,20 @@ export const all: EducationInstitution[] = [ ].flat(); interface FilterProps { + /** + * Limit institutions to those that operate in at least one of the specified + * countries. + * + * Omit this filter to return institutions from all countries. + */ country?: CountryCode | CountryCode[]; + + /** + * Limit institutions to those that offer an education programme that + * corresponds to at least one of the specified ISCED 2011 levels. + * + * Omit this filter to return institutions regardless of education level. + */ level?: EducationLevel | EducationLevel[]; } diff --git a/src/education/institutions/row.ts b/src/education/institutions/row.ts index a0a9a18..229661d 100644 --- a/src/education/institutions/row.ts +++ b/src/education/institutions/row.ts @@ -381,6 +381,6 @@ export const universities: EducationInstitution[] = ([ }, ] as const).map((props) => Object.assign(props, { - levels: [6, 7, 8] as const, - }), + levels: [6, 7, 8], + } as const), ); diff --git a/src/filter.test.ts b/src/filter.test.ts index 5a39fa5..6dbeebe 100644 --- a/src/filter.test.ts +++ b/src/filter.test.ts @@ -5,40 +5,48 @@ describe('createSubsetMatcher', () => { const match = createSubsetMatcher(); it.each([ - ['no elements', []], - ['undefined', [undefined]], - ['null', [null]], - ['empty string', ['']], - ['non-empty string', ['abc123']], - ])('allows array with %s', (_, value) => expect(match(value)).toBe(true)); + ['undefined', undefined], + ['null', null], + ['empty string', ''], + ['non-empty string', 'abc123'], + ['array with no elements', []], + ['array with undefined', [undefined]], + ['array with null', [null]], + ['array with empty string', ['']], + ['array with non-empty string', ['abc123']], + ])('allows %s', (_, value) => expect(match(value)).toBe(true)); }); describe('given one value', () => { const match = createSubsetMatcher(1); it.each([ - ['matching element only', [1]], - ['matching elements only', [1, 1]], - ['mix of matching and non-matching elements', [2, 1, 3]], - ])('allows array with %s', (_, value) => expect(match(value)).toBe(true)); + ['matching element', 1], + ['array with matching element only', [1]], + ['array with matching elements only', [1, 1]], + ['array with matching and non-matching elements', [2, 1, 3]], + ])('allows %s', (_, value) => expect(match(value)).toBe(true)); it.each([ - ['no elements', []], - ['non-matching elements only', [3, 2]], - ])('denies array with %s', (_, value) => expect(match(value)).toBe(false)); + ['non-matching element', 2], + ['array with no elements', []], + ['array with non-matching elements only', [3, 2]], + ])('denies %s', (_, value) => expect(match(value)).toBe(false)); }); describe('given two values', () => { const match = createSubsetMatcher(['a', 'b']); it.each([ - ['first matching element only', ['a']], - ['second matching element only', ['b']], - ['both matching elements', ['b', 'a']], - ['mix of matching and non-matching elements', ['c', 'a', 'd', 'b']], - ])('allows array with %s', (_, value) => expect(match(value)).toBe(true)); + ['matching element', 'a'], + ['array with first matching element only', ['a']], + ['array with second matching element only', ['b']], + ['array with both matching elements', ['b', 'a']], + ['array with matching and non-matching elements', ['c', 'a', 'd', 'b']], + ])('allows %s', (_, value) => expect(match(value)).toBe(true)); it.each([ + ['non-matching element', 'c'], ['no elements', []], ['non-matching elements only', ['d', 'c']], ])('denies array with %s', (_, value) => expect(match(value)).toBe(false)); diff --git a/src/filter.ts b/src/filter.ts index 85020c0..e43f22e 100644 --- a/src/filter.ts +++ b/src/filter.ts @@ -1,11 +1,15 @@ +const isArray = (input: T | ReadonlyArray): input is ReadonlyArray => + Array.isArray(input); + export const createSubsetMatcher = ( - value?: T | T[], -): ((inputs: ReadonlyArray) => boolean) => { + value?: T | ReadonlyArray, +): ((input: T | ReadonlyArray) => boolean) => { if (typeof value === 'undefined') { return () => true; } - const values = new Set(Array.isArray(value) ? value : [value]); + const values = new Set(isArray(value) ? value : [value]); - return (inputs) => inputs.some((input) => values.has(input)); + return (input) => + isArray(input) ? input.some((i) => values.has(i)) : values.has(input); }; diff --git a/src/readme.ts b/src/readme.ts index ed05bdb..a3acde3 100644 --- a/src/readme.ts +++ b/src/readme.ts @@ -2,8 +2,6 @@ import { fakeHr } from '.'; -console.log('hello there'); - console.log(fakeHr.competencies.all[0]); console.log(fakeHr.education.institutions.all[0]);