mirror of
https://github.com/iconify/collections-json.git
synced 2024-12-22 02:48:58 +00:00
chore: refactor
This commit is contained in:
parent
d389d11f93
commit
0b0bf01ca6
@ -1,8 +1,3 @@
|
||||
{
|
||||
"extends": "@antfu/eslint-config",
|
||||
"rules": {
|
||||
"@typescript-eslint/no-unused-vars": "off",
|
||||
"react/react-in-jsx-scope": "off",
|
||||
"react/no-unknown-property": "off"
|
||||
}
|
||||
"extends": "@antfu"
|
||||
}
|
||||
|
10
lib/test.ts
10
lib/test.ts
@ -1,10 +0,0 @@
|
||||
import { collection, locate } from './finder'
|
||||
|
||||
const test = async(): Promise<void> => {
|
||||
const fa = locate('fa')
|
||||
console.log(fa)
|
||||
const faLib = await collection('fa')
|
||||
console.log(faLib)
|
||||
}
|
||||
|
||||
test()
|
12
package.json
12
package.json
@ -16,20 +16,20 @@
|
||||
"composer.md",
|
||||
"readme.md"
|
||||
],
|
||||
"main": "dist/finder.js",
|
||||
"module": "dist/finder.mjs",
|
||||
"types": "dist/finder.d.ts",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.mjs",
|
||||
"types": "dist/index.d.ts",
|
||||
"homepage": "https://iconify.design/icon-sets/",
|
||||
"bugs": "https://github.com/iconify/collections-json/issues",
|
||||
"scripts": {
|
||||
"build": "rimraf dist && tsup lib/finder.ts --format cjs,esm --dts",
|
||||
"test": "esno lib/test.ts"
|
||||
"build": "rimraf dist && tsup src/index.ts --format cjs,esm --dts",
|
||||
"test": "esno src/test.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"upath": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@antfu/eslint-config": "^0.8.2",
|
||||
"@antfu/eslint-config": "^0.9.0",
|
||||
"@types/node": "^16.9.1",
|
||||
"@typescript-eslint/eslint-plugin": "^4.31.0",
|
||||
"eslint": "^7.32.0",
|
||||
|
@ -383,25 +383,24 @@ export interface IconifyJSON extends IconifyOptional, IconifyMetaData {
|
||||
// This is used to reduce duplication.
|
||||
}
|
||||
|
||||
/**
|
||||
* Collection info map
|
||||
*/
|
||||
export type IconifyMetaDataCollection = {
|
||||
[prefix: string]: IconifyMetaData
|
||||
}
|
||||
|
||||
const _dirname = typeof __dirname !== 'undefined' ? __dirname : dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
const dir = resolve(_dirname, '..')
|
||||
|
||||
/**
|
||||
* Get root directory of this package
|
||||
* (not really useful in Node.js because require can do it, but added anyway to match php code)
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
const rootDir = () => dir
|
||||
|
||||
/**
|
||||
* Locate JSON file
|
||||
*
|
||||
* @param {string} name Collection name
|
||||
* @returns {string} Path to collection json file
|
||||
*/
|
||||
const locate = (name: string): PathLike => `${dir}/json/${name}.json`
|
||||
export const locate = (name: string): PathLike => `${dir}/json/${name}.json`
|
||||
|
||||
/**
|
||||
* Loads a collection.
|
||||
@ -419,15 +418,15 @@ export const loadCollection = async(path: PathLike): Promise<IconifyJSON> => {
|
||||
* @param {string} name The name of the collection
|
||||
* @return {Promise<IconifyJSON>}
|
||||
*/
|
||||
export const collection = async(name: string): Promise<IconifyJSON> => {
|
||||
export const lookupCollection = async(name: string): Promise<IconifyJSON> => {
|
||||
return await loadCollection(locate(name))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of collections info.
|
||||
*
|
||||
* @return {Promise<IconifyMetaData[]>}
|
||||
* @return {Promise<IconifyMetaDataCollection>}
|
||||
*/
|
||||
export const collections = async(): Promise<IconifyMetaData[]> => {
|
||||
export const lookupCollections = async(): Promise<IconifyMetaDataCollection> => {
|
||||
return JSON.parse(await fs.readFile(`${dir}/collections.json`, 'utf8'))
|
||||
}
|
12
src/test.ts
Normal file
12
src/test.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { lookupCollection, locate, lookupCollections } from '.'
|
||||
|
||||
const test = async(): Promise<void> => {
|
||||
const fa = locate('fa')
|
||||
console.log(fa)
|
||||
const faLib = await lookupCollection('fa')
|
||||
console.log(faLib)
|
||||
const allCollections = await lookupCollections()
|
||||
console.log(allCollections.fa)
|
||||
}
|
||||
|
||||
test()
|
@ -1,20 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"module": "ESNext",
|
||||
"target": "es2017",
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"lib": ["ESNext"],
|
||||
"esModuleInterop": true,
|
||||
"strict": true,
|
||||
"strictNullChecks": true,
|
||||
"moduleResolution": "Node",
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true,
|
||||
"jsx": "preserve"
|
||||
},
|
||||
"exclude": [
|
||||
"**/dist",
|
||||
"**/node_modules",
|
||||
"**/test"
|
||||
"**/test",
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
|
64
yarn.lock
64
yarn.lock
@ -2,10 +2,10 @@
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@antfu/eslint-config-basic@^0.8.1":
|
||||
version "0.8.1"
|
||||
resolved "https://registry.yarnpkg.com/@antfu/eslint-config-basic/-/eslint-config-basic-0.8.1.tgz#38938504c324ab2b210ba6e08d60275e565dae59"
|
||||
integrity sha512-LUukPMgwvUTFxnsdMzi6zGmTCmqOul64BYs57R0YOKKxsza/ZvB/Wx3kwgsTxHUcc8i10mw9pAf8RhpHT35RcQ==
|
||||
"@antfu/eslint-config-basic@^0.9.0":
|
||||
version "0.9.0"
|
||||
resolved "https://registry.yarnpkg.com/@antfu/eslint-config-basic/-/eslint-config-basic-0.9.0.tgz#88e6c272df2e359dbd4e90f824d8959480f7dd92"
|
||||
integrity sha512-jiNycDenS19pppDvaa0oO3wWr4WDIog5Dz6WernBk+FsCyC7UzPfnG1KB3L/sovNVBB80wLZ7anGXZn0gKEHrQ==
|
||||
dependencies:
|
||||
eslint-config-standard "^16.0.3"
|
||||
eslint-plugin-eslint-comments "^3.2.0"
|
||||
@ -19,38 +19,52 @@
|
||||
jsonc-eslint-parser "^1.3.1"
|
||||
yaml-eslint-parser "^0.4.1"
|
||||
|
||||
"@antfu/eslint-config-react@^0.8.2":
|
||||
version "0.8.2"
|
||||
resolved "https://registry.yarnpkg.com/@antfu/eslint-config-react/-/eslint-config-react-0.8.2.tgz#29f68136e7facf3fd7fd86cb5ce66e35d3a853f0"
|
||||
integrity sha512-HBneMnAHIwV5UTVIKOcfXWnXnHdEndoIjggra9PyJwQjjQahNhT73N7l8c7IjwcQ6NkDOI151SmOQQxi418Yzw==
|
||||
"@antfu/eslint-config-react@^0.9.0":
|
||||
version "0.9.0"
|
||||
resolved "https://registry.yarnpkg.com/@antfu/eslint-config-react/-/eslint-config-react-0.9.0.tgz#ff5a7fc6466e2d213d2c822498373116400529c2"
|
||||
integrity sha512-5b4PHHamJfMTfzmcUb7rDg9oH34delky8ZmTJ+r5LLfbbPdIthYLS9Ybns5v3q6rjhhTsfHOQz3gxp9604tYbQ==
|
||||
dependencies:
|
||||
"@antfu/eslint-config-ts" "^0.8.2"
|
||||
"@antfu/eslint-config-ts" "^0.9.0"
|
||||
eslint-plugin-react "^7.25.1"
|
||||
|
||||
"@antfu/eslint-config-ts@^0.8.2":
|
||||
version "0.8.2"
|
||||
resolved "https://registry.yarnpkg.com/@antfu/eslint-config-ts/-/eslint-config-ts-0.8.2.tgz#b4af9fc21a7fa46cf0839c3dff89c035235d1fd2"
|
||||
integrity sha512-Rx1pGmt6mFTJ+ZZGZXLdWqYezViPWgbLbyPxajqP7rTctzo7bvd6T3qBTMCL5ZbxV+sdaTlYxM1eFN9t2ug/CA==
|
||||
"@antfu/eslint-config-ts@^0.9.0":
|
||||
version "0.9.0"
|
||||
resolved "https://registry.yarnpkg.com/@antfu/eslint-config-ts/-/eslint-config-ts-0.9.0.tgz#8a04b56a5694381ff1c8657782185c37c437a91a"
|
||||
integrity sha512-FXLLgMVjh5MpBvMteYQeQ9vkeL/cV5vig7IRoAJIpG1E5cbE+ENJt6w1YBf45PLQmoV/eZZID7cnT8ZOJ9VJfQ==
|
||||
dependencies:
|
||||
"@antfu/eslint-config-basic" "^0.8.1"
|
||||
"@antfu/eslint-config-basic" "^0.9.0"
|
||||
"@typescript-eslint/eslint-plugin" "^4.31.0"
|
||||
"@typescript-eslint/parser" "^4.31.0"
|
||||
|
||||
"@antfu/eslint-config-vue@^0.8.2":
|
||||
version "0.8.2"
|
||||
resolved "https://registry.yarnpkg.com/@antfu/eslint-config-vue/-/eslint-config-vue-0.8.2.tgz#3e3ff66f6e30dad9e30fc85429c0dbabdc2cf0e2"
|
||||
integrity sha512-m5HLvnyhbTj2kSrddNeQoUIZ+BY7AgWZel7CVkMPajx8SACh4DpYcNFezuwjCwcCM5A/ZulktSKqdF9rEzKWBg==
|
||||
"@antfu/eslint-config-vue@^0.9.0":
|
||||
version "0.9.0"
|
||||
resolved "https://registry.yarnpkg.com/@antfu/eslint-config-vue/-/eslint-config-vue-0.9.0.tgz#ea3b625b3af01e441295877dd32934a29010d10a"
|
||||
integrity sha512-h1Ab6TdcZyhQhBJIjr3CrI6U66x/izRddTQeF/OrjEyLz6HjeASbUOMgDQhmH9u47+6RP68cR6Wnjls/rlZb2g==
|
||||
dependencies:
|
||||
"@antfu/eslint-config-ts" "^0.8.2"
|
||||
"@antfu/eslint-config-ts" "^0.9.0"
|
||||
eslint-plugin-vue "7.17.0"
|
||||
|
||||
"@antfu/eslint-config@^0.8.2":
|
||||
version "0.8.2"
|
||||
resolved "https://registry.yarnpkg.com/@antfu/eslint-config/-/eslint-config-0.8.2.tgz#aecc0283f65105e42278734e533804c41c88cc0f"
|
||||
integrity sha512-MqNrYl30gIPPIPIKVPqc3aQs5DAi9JVohsZHvBw3KeplbJK0SZujDnlaeGxeC7D0Zp+Z4E/D8KxefgJHz1G8Kw==
|
||||
"@antfu/eslint-config@^0.9.0":
|
||||
version "0.9.0"
|
||||
resolved "https://registry.yarnpkg.com/@antfu/eslint-config/-/eslint-config-0.9.0.tgz#ed62a2c7c4e88b45356d1f925dd8a85e9aaac950"
|
||||
integrity sha512-oQ6kNRHfF7PqZocX2+mfvY/oNdLGPjysb9huVJzMji7QtLAVL5+25Mm/kzJEIfcFWxRpDqctOcflXLYFnXiroA==
|
||||
dependencies:
|
||||
"@antfu/eslint-config-react" "^0.8.2"
|
||||
"@antfu/eslint-config-vue" "^0.8.2"
|
||||
"@antfu/eslint-config-react" "^0.9.0"
|
||||
"@antfu/eslint-config-vue" "^0.9.0"
|
||||
"@typescript-eslint/eslint-plugin" "^4.31.0"
|
||||
"@typescript-eslint/parser" "^4.31.0"
|
||||
eslint-config-standard "^16.0.3"
|
||||
eslint-plugin-eslint-comments "^3.2.0"
|
||||
eslint-plugin-html "^6.1.2"
|
||||
eslint-plugin-import "^2.24.2"
|
||||
eslint-plugin-jsonc "^1.6.0"
|
||||
eslint-plugin-node "^11.1.0"
|
||||
eslint-plugin-promise "^5.1.0"
|
||||
eslint-plugin-unicorn "^35.0.0"
|
||||
eslint-plugin-vue "7.17.0"
|
||||
eslint-plugin-yml "^0.10.0"
|
||||
jsonc-eslint-parser "^1.3.1"
|
||||
yaml-eslint-parser "^0.4.1"
|
||||
|
||||
"@babel/code-frame@7.12.11":
|
||||
version "7.12.11"
|
||||
|
Loading…
Reference in New Issue
Block a user