Add fuzzy matching for licenses search to add-icon-data script (#10593)

This commit is contained in:
Álvaro Mondéjar 2024-03-08 19:52:11 +01:00 committed by GitHub
parent 31e7bed99c
commit ce2f63e591
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 6 deletions

View File

@ -90,6 +90,7 @@
"editorconfig-checker": "5.1.1", "editorconfig-checker": "5.1.1",
"esbuild": "0.19.4", "esbuild": "0.19.4",
"fake-diff": "1.0.0", "fake-diff": "1.0.0",
"fast-fuzzy": "1.12.0",
"get-relative-luminance": "1.0.0", "get-relative-luminance": "1.0.0",
"husky": "9.0.10", "husky": "9.0.10",
"inquirer-autocomplete-standalone": "0.8.1", "inquirer-autocomplete-standalone": "0.8.1",

View File

@ -3,6 +3,7 @@ import chalk from 'chalk';
import { input, confirm, checkbox } from '@inquirer/prompts'; import { input, confirm, checkbox } from '@inquirer/prompts';
import autocomplete from 'inquirer-autocomplete-standalone'; import autocomplete from 'inquirer-autocomplete-standalone';
import getRelativeLuminance from 'get-relative-luminance'; import getRelativeLuminance from 'get-relative-luminance';
import { search } from 'fast-fuzzy';
import { import {
URL_REGEX, URL_REGEX,
collator, collator,
@ -24,7 +25,7 @@ const titleValidator = (text) => {
(x) => x.title === text || titleToSlug(x.title) === titleToSlug(text), (x) => x.title === text || titleToSlug(x.title) === titleToSlug(text),
) )
) )
return 'This icon title or slug already exist'; return 'This icon title or slug already exists';
return true; return true;
}; };
@ -132,16 +133,14 @@ if (answers.hasLicense) {
source: async (input) => { source: async (input) => {
input = (input || '').trim(); input = (input || '').trim();
return input return input
? licenseTypes.filter((license) => ? search(input, licenseTypes, { keySelector: (x) => x.value })
license.value.toLowerCase().includes(input.toLowerCase()),
)
: licenseTypes; : licenseTypes;
}, },
}); });
answers.licenseUrl = await input({ answers.licenseUrl = await input({
message: `License URL ${chalk.reset('(optional)')}:`, message: `License URL ${chalk.reset('(optional)')}:`,
validate: (text) => !Boolean(text) || sourceValidator(text), validate: (text) => text.length === 0 || sourceValidator(text),
}); });
} }
@ -160,7 +159,7 @@ if (answers.hasAliases) {
if (!answers?.aliasesTypes?.includes(x.value)) continue; if (!answers?.aliasesTypes?.includes(x.value)) continue;
answers[`${x.value}AliasesList`] = await input({ answers[`${x.value}AliasesList`] = await input({
message: x.value + chalk.reset(' (separate with commas)'), message: x.value + chalk.reset(' (separate with commas)'),
validate: (text) => Boolean(text), validate: (text) => text.trim().length > 0,
transformer: aliasesTransformer, transformer: aliasesTransformer,
}); });
} }