mirror of https://github.com/iconify/api.git
chore: premade importer for npm package
This commit is contained in:
parent
2963c7a666
commit
a391ce96cf
|
|
@ -3,7 +3,7 @@
|
|||
"description": "Iconify API",
|
||||
"author": "Vjacheslav Trushkin",
|
||||
"license": "MIT",
|
||||
"version": "3.1.0-beta.2",
|
||||
"version": "3.1.0-beta.4",
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"tag": "next"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
import { dirname } from 'node:path';
|
||||
import { Importer } from '../../types/importers.js';
|
||||
import { createIconSetsPackageImporter } from '../../importers/full/json.js';
|
||||
import { ImportedData } from '../../types/importers/common.js';
|
||||
import { DirectoryDownloader } from '../../downloaders/directory.js';
|
||||
|
||||
/**
|
||||
* Create importer for package
|
||||
*/
|
||||
export function createPackageIconSetImporter(packageName = '@iconify/json'): Importer {
|
||||
const dir = dirname(import.meta.resolve(`${packageName}/package.json`));
|
||||
return createIconSetsPackageImporter(new DirectoryDownloader<ImportedData>(dir), {});
|
||||
}
|
||||
|
|
@ -7,9 +7,10 @@ import { iconSets } from '../../data/icon-sets.js';
|
|||
*/
|
||||
export function createIconsDataResponse(
|
||||
prefix: string,
|
||||
q: Record<string, string>
|
||||
q: Record<string, string | string[]>
|
||||
): number | IconifyJSON | Promise<IconifyJSON | number> {
|
||||
const names = q.icons?.split(',');
|
||||
const iconNames = q.icons;
|
||||
const names = typeof iconNames === 'string' ? iconNames.split(',') : iconNames;
|
||||
|
||||
if (!names || !names.length) {
|
||||
// Missing or invalid icons parameter
|
||||
|
|
@ -47,7 +48,10 @@ export function createIconsDataResponse(
|
|||
/**
|
||||
* Awaitable version of createIconsDataResponse()
|
||||
*/
|
||||
export function createIconsDataResponseAsync(prefix: string, q: Record<string, string>): Promise<IconifyJSON | number> {
|
||||
export function createIconsDataResponseAsync(
|
||||
prefix: string,
|
||||
q: Record<string, string | string[]>
|
||||
): Promise<IconifyJSON | number> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const result = createIconsDataResponse(prefix, q);
|
||||
if (result instanceof Promise) {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
import type { FastifyReply, FastifyRequest } from 'fastify';
|
||||
import { iconSets } from '../../data/icon-sets.js';
|
||||
import { searchIndex } from '../../data/search.js';
|
||||
import { search } from '../../data/search/index.js';
|
||||
import { paramToBoolean } from '../../misc/bool.js';
|
||||
import type { SearchParams } from '../../types/search.js';
|
||||
import type { APIv2SearchParams, APIv2SearchResponse } from '../../types/server/v2.js';
|
||||
import { checkJSONPQuery, sendJSONResponse } from '../helpers/json.js';
|
||||
|
||||
const minSearchLimit = 32;
|
||||
const maxSearchLimit = 999;
|
||||
|
|
|
|||
Loading…
Reference in New Issue