@iconify/tools 4.2.0 → 5.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/colors/attribs.d.ts +2 -4
- package/lib/colors/attribs.js +33 -0
- package/lib/colors/detect.d.ts +2 -10
- package/lib/colors/detect.js +36 -0
- package/lib/colors/parse.d.ts +12 -19
- package/lib/colors/parse.js +241 -0
- package/lib/colors/validate.d.ts +3 -13
- package/lib/colors/validate.js +31 -0
- package/lib/css/parse.d.ts +1 -2
- package/lib/css/parse.js +18 -0
- package/lib/css/parser/error.d.ts +6 -7
- package/lib/css/parser/error.js +24 -0
- package/lib/css/parser/export.d.ts +2 -4
- package/lib/css/parser/export.js +34 -0
- package/lib/css/parser/strings.d.ts +2 -4
- package/lib/css/parser/strings.js +66 -0
- package/lib/css/parser/text.d.ts +2 -4
- package/lib/css/parser/text.js +103 -0
- package/lib/css/parser/tokens.d.ts +3 -5
- package/lib/css/parser/tokens.js +169 -0
- package/lib/css/parser/tree.d.ts +2 -4
- package/lib/css/parser/tree.js +35 -0
- package/lib/css/parser/types.d.ts +21 -22
- package/lib/css/parser/types.js +1 -0
- package/lib/download/api/cache.d.ts +2 -4
- package/lib/download/api/cache.js +84 -0
- package/lib/download/api/config.d.ts +6 -8
- package/lib/download/api/config.js +10 -0
- package/lib/download/api/download.d.ts +2 -4
- package/lib/download/api/download.js +26 -0
- package/lib/download/api/fetch.d.ts +1 -2
- package/lib/download/api/fetch.js +15 -0
- package/lib/download/api/index.d.ts +2 -4
- package/lib/download/api/index.js +50 -0
- package/lib/download/api/queue.d.ts +9 -10
- package/lib/download/api/queue.js +94 -0
- package/lib/download/api/types.d.ts +6 -7
- package/lib/download/api/types.js +1 -0
- package/lib/download/git/branch.d.ts +2 -4
- package/lib/download/git/branch.js +15 -0
- package/lib/download/git/hash.d.ts +2 -4
- package/lib/download/git/hash.js +10 -0
- package/lib/download/git/index.d.ts +10 -12
- package/lib/download/git/index.js +39 -0
- package/lib/download/git/reset.d.ts +1 -2
- package/lib/download/git/reset.js +12 -0
- package/lib/download/github/hash.d.ts +2 -4
- package/lib/download/github/hash.js +20 -0
- package/lib/download/github/index.d.ts +12 -14
- package/lib/download/github/index.js +66 -0
- package/lib/download/github/types.d.ts +5 -6
- package/lib/download/github/types.js +1 -0
- package/lib/download/gitlab/hash.d.ts +2 -4
- package/lib/download/gitlab/hash.js +19 -0
- package/lib/download/gitlab/index.d.ts +12 -14
- package/lib/download/gitlab/index.js +64 -0
- package/lib/download/gitlab/types.d.ts +5 -6
- package/lib/download/gitlab/types.js +6 -0
- package/lib/download/helpers/untar.d.ts +1 -2
- package/lib/download/helpers/untar.js +13 -0
- package/lib/download/helpers/unzip.d.ts +1 -2
- package/lib/download/helpers/unzip.js +39 -0
- package/lib/download/index.d.ts +15 -20
- package/lib/download/index.js +19 -0
- package/lib/download/npm/index.d.ts +11 -13
- package/lib/download/npm/index.js +51 -0
- package/lib/download/npm/types.d.ts +3 -4
- package/lib/download/npm/types.js +1 -0
- package/lib/download/npm/version.d.ts +4 -6
- package/lib/download/npm/version.js +23 -0
- package/lib/download/types/modified.d.ts +1 -2
- package/lib/download/types/modified.js +1 -0
- package/lib/download/types/sources.d.ts +2 -3
- package/lib/download/types/sources.js +1 -0
- package/lib/export/directory.d.ts +7 -15
- package/lib/export/directory.js +37 -0
- package/lib/export/helpers/custom-files.d.ts +2 -3
- package/lib/export/helpers/custom-files.js +23 -0
- package/lib/export/helpers/prepare.d.ts +3 -4
- package/lib/export/helpers/prepare.js +31 -0
- package/lib/export/helpers/types-version.d.ts +1 -2
- package/lib/export/helpers/types-version.js +19 -0
- package/lib/export/icon-package.d.ts +8 -15
- package/lib/export/icon-package.js +55 -0
- package/lib/export/json-package.d.ts +7 -14
- package/lib/export/json-package.js +129 -0
- package/lib/icon-set/index.d.ts +144 -147
- package/lib/icon-set/index.js +595 -0
- package/lib/icon-set/match.d.ts +3 -11
- package/lib/icon-set/match.js +45 -0
- package/lib/icon-set/merge.d.ts +2 -10
- package/lib/icon-set/merge.js +68 -0
- package/lib/icon-set/modified.d.ts +2 -10
- package/lib/icon-set/modified.js +20 -0
- package/lib/icon-set/props.d.ts +2 -5
- package/lib/icon-set/props.js +19 -0
- package/lib/icon-set/tags.d.ts +7 -15
- package/lib/icon-set/tags.js +53 -0
- package/lib/icon-set/types.d.ts +16 -21
- package/lib/icon-set/types.js +1 -0
- package/lib/import/directory.d.ts +11 -20
- package/lib/import/directory.js +101 -0
- package/lib/import/figma/index.d.ts +4 -15
- package/lib/import/figma/index.js +61 -0
- package/lib/import/figma/nodes.d.ts +4 -14
- package/lib/import/figma/nodes.js +80 -0
- package/lib/import/figma/query.d.ts +9 -19
- package/lib/import/figma/query.js +183 -0
- package/lib/import/figma/types/api.d.ts +23 -35
- package/lib/import/figma/types/nodes.d.ts +12 -21
- package/lib/import/figma/types/options.d.ts +23 -32
- package/lib/import/figma/types/result.d.ts +16 -24
- package/lib/index.d.ts +55 -80
- package/lib/index.js +56 -0
- package/lib/misc/bump-version.d.ts +1 -2
- package/lib/misc/bump-version.js +13 -0
- package/lib/misc/compare-dirs.d.ts +4 -5
- package/lib/misc/compare-dirs.js +65 -0
- package/lib/misc/exec.d.ts +4 -6
- package/lib/misc/exec.js +23 -0
- package/lib/misc/keyword.d.ts +1 -2
- package/lib/misc/keyword.js +12 -0
- package/lib/misc/scan.d.ts +2 -4
- package/lib/misc/scan.js +87 -0
- package/lib/misc/write-json.d.ts +1 -2
- package/lib/misc/write-json.js +10 -0
- package/lib/optimise/figma.d.ts +2 -7
- package/lib/optimise/figma.js +189 -0
- package/lib/optimise/flags.d.ts +2 -7
- package/lib/optimise/flags.js +231 -0
- package/lib/optimise/global-style.d.ts +2 -7
- package/lib/optimise/global-style.js +114 -0
- package/lib/optimise/mask.d.ts +9 -14
- package/lib/optimise/mask.js +83 -0
- package/lib/optimise/origin.d.ts +2 -7
- package/lib/optimise/origin.js +22 -0
- package/lib/optimise/scale.d.ts +2 -7
- package/lib/optimise/scale.js +24 -0
- package/lib/optimise/svgo.d.ts +10 -15
- package/lib/optimise/svgo.js +90 -0
- package/lib/optimise/unwrap.d.ts +2 -7
- package/lib/optimise/unwrap.js +25 -0
- package/lib/svg/analyse/error.d.ts +2 -7
- package/lib/svg/analyse/error.js +12 -0
- package/lib/svg/analyse/types.d.ts +31 -35
- package/lib/svg/analyse/types.js +1 -0
- package/lib/svg/analyse.d.ts +3 -10
- package/lib/svg/analyse.js +256 -0
- package/lib/svg/cleanup/attribs.d.ts +2 -7
- package/lib/svg/cleanup/attribs.js +37 -0
- package/lib/svg/cleanup/bad-tags.d.ts +3 -8
- package/lib/svg/cleanup/bad-tags.js +57 -0
- package/lib/svg/cleanup/inline-style.d.ts +2 -7
- package/lib/svg/cleanup/inline-style.js +80 -0
- package/lib/svg/cleanup/root-style.d.ts +4 -9
- package/lib/svg/cleanup/root-style.js +27 -0
- package/lib/svg/cleanup/root-svg.d.ts +2 -7
- package/lib/svg/cleanup/root-svg.js +73 -0
- package/lib/svg/cleanup/svgo-style.d.ts +2 -7
- package/lib/svg/cleanup/svgo-style.js +24 -0
- package/lib/svg/cleanup.d.ts +3 -8
- package/lib/svg/cleanup.js +20 -0
- package/lib/svg/data/attributes.d.ts +1 -2
- package/lib/svg/data/attributes.js +451 -0
- package/lib/svg/data/tags.d.ts +1 -2
- package/lib/svg/data/tags.js +182 -0
- package/lib/svg/index.d.ts +38 -47
- package/lib/svg/index.js +117 -0
- package/lib/svg/parse-style.d.ts +21 -28
- package/lib/svg/parse-style.js +199 -0
- package/lib/svg/parse.d.ts +8 -16
- package/lib/svg/parse.js +32 -0
- package/package.json +116 -222
- package/lib/colors/attribs.cjs +0 -33
- package/lib/colors/attribs.d.cts +0 -27
- package/lib/colors/attribs.d.mts +0 -27
- package/lib/colors/attribs.mjs +0 -26
- package/lib/colors/detect.cjs +0 -66
- package/lib/colors/detect.d.cts +0 -16
- package/lib/colors/detect.d.mts +0 -16
- package/lib/colors/detect.mjs +0 -64
- package/lib/colors/parse.cjs +0 -300
- package/lib/colors/parse.d.cts +0 -61
- package/lib/colors/parse.d.mts +0 -61
- package/lib/colors/parse.mjs +0 -297
- package/lib/colors/validate.cjs +0 -56
- package/lib/colors/validate.d.cts +0 -21
- package/lib/colors/validate.d.mts +0 -21
- package/lib/colors/validate.mjs +0 -54
- package/lib/css/parse.cjs +0 -24
- package/lib/css/parse.d.cts +0 -6
- package/lib/css/parse.d.mts +0 -6
- package/lib/css/parse.mjs +0 -22
- package/lib/css/parser/error.cjs +0 -23
- package/lib/css/parser/error.d.cts +0 -13
- package/lib/css/parser/error.d.mts +0 -13
- package/lib/css/parser/error.mjs +0 -21
- package/lib/css/parser/export.cjs +0 -37
- package/lib/css/parser/export.d.cts +0 -8
- package/lib/css/parser/export.d.mts +0 -8
- package/lib/css/parser/export.mjs +0 -35
- package/lib/css/parser/strings.cjs +0 -83
- package/lib/css/parser/strings.d.cts +0 -16
- package/lib/css/parser/strings.d.mts +0 -16
- package/lib/css/parser/strings.mjs +0 -80
- package/lib/css/parser/text.cjs +0 -114
- package/lib/css/parser/text.d.cts +0 -20
- package/lib/css/parser/text.d.mts +0 -20
- package/lib/css/parser/text.mjs +0 -109
- package/lib/css/parser/tokens.cjs +0 -206
- package/lib/css/parser/tokens.d.cts +0 -9
- package/lib/css/parser/tokens.d.mts +0 -9
- package/lib/css/parser/tokens.mjs +0 -204
- package/lib/css/parser/tree.cjs +0 -40
- package/lib/css/parser/tree.d.cts +0 -8
- package/lib/css/parser/tree.d.mts +0 -8
- package/lib/css/parser/tree.mjs +0 -38
- package/lib/css/parser/types.cjs +0 -2
- package/lib/css/parser/types.d.cts +0 -52
- package/lib/css/parser/types.d.mts +0 -52
- package/lib/css/parser/types.mjs +0 -1
- package/lib/download/api/cache.cjs +0 -91
- package/lib/download/api/cache.d.cts +0 -20
- package/lib/download/api/cache.d.mts +0 -20
- package/lib/download/api/cache.mjs +0 -86
- package/lib/download/api/config.cjs +0 -11
- package/lib/download/api/config.d.cts +0 -18
- package/lib/download/api/config.d.mts +0 -18
- package/lib/download/api/config.mjs +0 -8
- package/lib/download/api/download.cjs +0 -26
- package/lib/download/api/download.d.cts +0 -8
- package/lib/download/api/download.d.mts +0 -8
- package/lib/download/api/download.mjs +0 -24
- package/lib/download/api/fetch.cjs +0 -12
- package/lib/download/api/fetch.d.cts +0 -10
- package/lib/download/api/fetch.d.mts +0 -10
- package/lib/download/api/fetch.mjs +0 -9
- package/lib/download/api/index.cjs +0 -57
- package/lib/download/api/index.d.cts +0 -8
- package/lib/download/api/index.d.mts +0 -8
- package/lib/download/api/index.mjs +0 -55
- package/lib/download/api/queue.cjs +0 -104
- package/lib/download/api/queue.d.cts +0 -32
- package/lib/download/api/queue.d.mts +0 -32
- package/lib/download/api/queue.mjs +0 -101
- package/lib/download/api/types.cjs +0 -2
- package/lib/download/api/types.d.cts +0 -17
- package/lib/download/api/types.d.mts +0 -17
- package/lib/download/api/types.mjs +0 -1
- package/lib/download/git/branch.cjs +0 -19
- package/lib/download/git/branch.d.cts +0 -8
- package/lib/download/git/branch.d.mts +0 -8
- package/lib/download/git/branch.mjs +0 -17
- package/lib/download/git/hash.cjs +0 -14
- package/lib/download/git/hash.d.cts +0 -8
- package/lib/download/git/hash.d.mts +0 -8
- package/lib/download/git/hash.mjs +0 -12
- package/lib/download/git/index.cjs +0 -76
- package/lib/download/git/index.d.cts +0 -29
- package/lib/download/git/index.d.mts +0 -29
- package/lib/download/git/index.mjs +0 -74
- package/lib/download/git/reset.cjs +0 -36
- package/lib/download/git/reset.d.cts +0 -6
- package/lib/download/git/reset.d.mts +0 -6
- package/lib/download/git/reset.mjs +0 -34
- package/lib/download/github/hash.cjs +0 -31
- package/lib/download/github/hash.d.cts +0 -8
- package/lib/download/github/hash.d.mts +0 -8
- package/lib/download/github/hash.mjs +0 -29
- package/lib/download/github/index.cjs +0 -105
- package/lib/download/github/index.d.cts +0 -31
- package/lib/download/github/index.d.mts +0 -31
- package/lib/download/github/index.mjs +0 -103
- package/lib/download/github/types.cjs +0 -2
- package/lib/download/github/types.d.cts +0 -11
- package/lib/download/github/types.d.mts +0 -11
- package/lib/download/github/types.mjs +0 -1
- package/lib/download/gitlab/hash.cjs +0 -33
- package/lib/download/gitlab/hash.d.cts +0 -8
- package/lib/download/gitlab/hash.d.mts +0 -8
- package/lib/download/gitlab/hash.mjs +0 -31
- package/lib/download/gitlab/index.cjs +0 -105
- package/lib/download/gitlab/index.d.cts +0 -31
- package/lib/download/gitlab/index.d.mts +0 -31
- package/lib/download/gitlab/index.mjs +0 -103
- package/lib/download/gitlab/types.cjs +0 -5
- package/lib/download/gitlab/types.d.cts +0 -15
- package/lib/download/gitlab/types.d.mts +0 -15
- package/lib/download/gitlab/types.mjs +0 -3
- package/lib/download/helpers/untar.cjs +0 -12
- package/lib/download/helpers/untar.d.cts +0 -6
- package/lib/download/helpers/untar.d.mts +0 -6
- package/lib/download/helpers/untar.mjs +0 -10
- package/lib/download/helpers/unzip.cjs +0 -17
- package/lib/download/helpers/unzip.d.cts +0 -6
- package/lib/download/helpers/unzip.d.mts +0 -6
- package/lib/download/helpers/unzip.mjs +0 -11
- package/lib/download/index.cjs +0 -64
- package/lib/download/index.d.cts +0 -48
- package/lib/download/index.d.mts +0 -48
- package/lib/download/index.mjs +0 -62
- package/lib/download/npm/index.cjs +0 -85
- package/lib/download/npm/index.d.cts +0 -30
- package/lib/download/npm/index.d.mts +0 -30
- package/lib/download/npm/index.mjs +0 -83
- package/lib/download/npm/types.cjs +0 -2
- package/lib/download/npm/types.d.cts +0 -9
- package/lib/download/npm/types.d.mts +0 -9
- package/lib/download/npm/types.mjs +0 -1
- package/lib/download/npm/version.cjs +0 -29
- package/lib/download/npm/version.d.cts +0 -16
- package/lib/download/npm/version.d.mts +0 -16
- package/lib/download/npm/version.mjs +0 -26
- package/lib/download/types/modified.cjs +0 -2
- package/lib/download/types/modified.d.cts +0 -6
- package/lib/download/types/modified.d.mts +0 -6
- package/lib/download/types/modified.mjs +0 -1
- package/lib/download/types/sources.cjs +0 -2
- package/lib/download/types/sources.d.cts +0 -12
- package/lib/download/types/sources.d.mts +0 -12
- package/lib/download/types/sources.mjs +0 -1
- package/lib/export/directory.cjs +0 -43
- package/lib/export/directory.d.cts +0 -26
- package/lib/export/directory.d.mts +0 -26
- package/lib/export/directory.mjs +0 -41
- package/lib/export/helpers/custom-files.cjs +0 -26
- package/lib/export/helpers/custom-files.d.cts +0 -12
- package/lib/export/helpers/custom-files.d.mts +0 -12
- package/lib/export/helpers/custom-files.mjs +0 -24
- package/lib/export/helpers/prepare.cjs +0 -34
- package/lib/export/helpers/prepare.d.cts +0 -19
- package/lib/export/helpers/prepare.d.mts +0 -19
- package/lib/export/helpers/prepare.mjs +0 -31
- package/lib/export/helpers/types-version.cjs +0 -12
- package/lib/export/helpers/types-version.d.cts +0 -6
- package/lib/export/helpers/types-version.d.mts +0 -6
- package/lib/export/helpers/types-version.mjs +0 -10
- package/lib/export/icon-package.cjs +0 -56
- package/lib/export/icon-package.d.cts +0 -26
- package/lib/export/icon-package.d.mts +0 -26
- package/lib/export/icon-package.mjs +0 -54
- package/lib/export/json-package.cjs +0 -144
- package/lib/export/json-package.d.cts +0 -25
- package/lib/export/json-package.d.mts +0 -25
- package/lib/export/json-package.mjs +0 -142
- package/lib/icon-set/index.cjs +0 -720
- package/lib/icon-set/index.d.cts +0 -162
- package/lib/icon-set/index.d.mts +0 -162
- package/lib/icon-set/index.mjs +0 -716
- package/lib/icon-set/match.cjs +0 -56
- package/lib/icon-set/match.d.cts +0 -15
- package/lib/icon-set/match.d.mts +0 -15
- package/lib/icon-set/match.mjs +0 -54
- package/lib/icon-set/merge.cjs +0 -87
- package/lib/icon-set/merge.d.cts +0 -14
- package/lib/icon-set/merge.d.mts +0 -14
- package/lib/icon-set/merge.mjs +0 -85
- package/lib/icon-set/modified.cjs +0 -25
- package/lib/icon-set/modified.d.cts +0 -16
- package/lib/icon-set/modified.d.mts +0 -16
- package/lib/icon-set/modified.mjs +0 -23
- package/lib/icon-set/props.cjs +0 -16
- package/lib/icon-set/props.d.cts +0 -13
- package/lib/icon-set/props.d.mts +0 -13
- package/lib/icon-set/props.mjs +0 -13
- package/lib/icon-set/tags.cjs +0 -95
- package/lib/icon-set/tags.d.cts +0 -25
- package/lib/icon-set/tags.d.mts +0 -25
- package/lib/icon-set/tags.mjs +0 -91
- package/lib/icon-set/types.cjs +0 -2
- package/lib/icon-set/types.d.cts +0 -75
- package/lib/icon-set/types.d.mts +0 -75
- package/lib/icon-set/types.mjs +0 -1
- package/lib/import/directory.cjs +0 -169
- package/lib/import/directory.d.cts +0 -52
- package/lib/import/directory.d.mts +0 -52
- package/lib/import/directory.mjs +0 -166
- package/lib/import/figma/index.cjs +0 -115
- package/lib/import/figma/index.d.cts +0 -20
- package/lib/import/figma/index.d.mts +0 -20
- package/lib/import/figma/index.mjs +0 -113
- package/lib/import/figma/nodes.cjs +0 -90
- package/lib/import/figma/nodes.d.cts +0 -18
- package/lib/import/figma/nodes.d.mts +0 -18
- package/lib/import/figma/nodes.mjs +0 -88
- package/lib/import/figma/query.cjs +0 -260
- package/lib/import/figma/query.d.cts +0 -42
- package/lib/import/figma/query.d.mts +0 -42
- package/lib/import/figma/query.mjs +0 -256
- package/lib/import/figma/types/api.cjs +0 -2
- package/lib/import/figma/types/api.d.cts +0 -53
- package/lib/import/figma/types/api.d.mts +0 -53
- package/lib/import/figma/types/api.mjs +0 -1
- package/lib/import/figma/types/nodes.cjs +0 -2
- package/lib/import/figma/types/nodes.d.cts +0 -44
- package/lib/import/figma/types/nodes.d.mts +0 -44
- package/lib/import/figma/types/nodes.mjs +0 -1
- package/lib/import/figma/types/options.cjs +0 -2
- package/lib/import/figma/types/options.d.cts +0 -59
- package/lib/import/figma/types/options.d.mts +0 -59
- package/lib/import/figma/types/options.mjs +0 -1
- package/lib/import/figma/types/result.cjs +0 -2
- package/lib/import/figma/types/result.d.cts +0 -44
- package/lib/import/figma/types/result.d.mts +0 -44
- package/lib/import/figma/types/result.mjs +0 -1
- package/lib/index.cjs +0 -157
- package/lib/index.d.cts +0 -80
- package/lib/index.d.mts +0 -80
- package/lib/index.mjs +0 -91
- package/lib/misc/bump-version.cjs +0 -15
- package/lib/misc/bump-version.d.cts +0 -6
- package/lib/misc/bump-version.d.mts +0 -6
- package/lib/misc/bump-version.mjs +0 -13
- package/lib/misc/cheerio.cjs +0 -2
- package/lib/misc/cheerio.d.cts +0 -10
- package/lib/misc/cheerio.d.mts +0 -10
- package/lib/misc/cheerio.d.ts +0 -10
- package/lib/misc/cheerio.mjs +0 -1
- package/lib/misc/compare-dirs.cjs +0 -75
- package/lib/misc/compare-dirs.d.cts +0 -11
- package/lib/misc/compare-dirs.d.mts +0 -11
- package/lib/misc/compare-dirs.mjs +0 -73
- package/lib/misc/exec.cjs +0 -27
- package/lib/misc/exec.d.cts +0 -12
- package/lib/misc/exec.d.mts +0 -12
- package/lib/misc/exec.mjs +0 -25
- package/lib/misc/keyword.cjs +0 -20
- package/lib/misc/keyword.d.cts +0 -6
- package/lib/misc/keyword.d.mts +0 -6
- package/lib/misc/keyword.mjs +0 -18
- package/lib/misc/scan.cjs +0 -114
- package/lib/misc/scan.d.cts +0 -33
- package/lib/misc/scan.d.mts +0 -33
- package/lib/misc/scan.mjs +0 -111
- package/lib/misc/write-json.cjs +0 -9
- package/lib/misc/write-json.d.cts +0 -6
- package/lib/misc/write-json.d.mts +0 -6
- package/lib/misc/write-json.mjs +0 -7
- package/lib/optimise/figma.cjs +0 -232
- package/lib/optimise/figma.d.cts +0 -14
- package/lib/optimise/figma.d.mts +0 -14
- package/lib/optimise/figma.mjs +0 -230
- package/lib/optimise/flags.cjs +0 -256
- package/lib/optimise/flags.d.cts +0 -11
- package/lib/optimise/flags.d.mts +0 -11
- package/lib/optimise/flags.mjs +0 -254
- package/lib/optimise/global-style.cjs +0 -158
- package/lib/optimise/global-style.d.cts +0 -11
- package/lib/optimise/global-style.d.mts +0 -11
- package/lib/optimise/global-style.mjs +0 -156
- package/lib/optimise/mask.cjs +0 -110
- package/lib/optimise/mask.d.cts +0 -24
- package/lib/optimise/mask.d.mts +0 -24
- package/lib/optimise/mask.mjs +0 -108
- package/lib/optimise/origin.cjs +0 -23
- package/lib/optimise/origin.d.cts +0 -11
- package/lib/optimise/origin.d.mts +0 -11
- package/lib/optimise/origin.mjs +0 -21
- package/lib/optimise/scale.cjs +0 -27
- package/lib/optimise/scale.d.cts +0 -11
- package/lib/optimise/scale.d.mts +0 -11
- package/lib/optimise/scale.mjs +0 -25
- package/lib/optimise/svgo.cjs +0 -107
- package/lib/optimise/svgo.d.cts +0 -37
- package/lib/optimise/svgo.d.mts +0 -37
- package/lib/optimise/svgo.mjs +0 -104
- package/lib/optimise/unwrap.cjs +0 -31
- package/lib/optimise/unwrap.d.cts +0 -11
- package/lib/optimise/unwrap.d.mts +0 -11
- package/lib/optimise/unwrap.mjs +0 -29
- package/lib/svg/analyse/error.cjs +0 -16
- package/lib/svg/analyse/error.d.cts +0 -11
- package/lib/svg/analyse/error.d.mts +0 -11
- package/lib/svg/analyse/error.mjs +0 -14
- package/lib/svg/analyse/types.cjs +0 -2
- package/lib/svg/analyse/types.d.cts +0 -93
- package/lib/svg/analyse/types.d.mts +0 -93
- package/lib/svg/analyse/types.mjs +0 -1
- package/lib/svg/analyse.cjs +0 -303
- package/lib/svg/analyse.d.cts +0 -16
- package/lib/svg/analyse.d.mts +0 -16
- package/lib/svg/analyse.mjs +0 -301
- package/lib/svg/cleanup/attribs.cjs +0 -39
- package/lib/svg/cleanup/attribs.d.cts +0 -11
- package/lib/svg/cleanup/attribs.d.mts +0 -11
- package/lib/svg/cleanup/attribs.mjs +0 -37
- package/lib/svg/cleanup/bad-tags.cjs +0 -69
- package/lib/svg/cleanup/bad-tags.d.cts +0 -17
- package/lib/svg/cleanup/bad-tags.d.mts +0 -17
- package/lib/svg/cleanup/bad-tags.mjs +0 -67
- package/lib/svg/cleanup/inline-style.cjs +0 -97
- package/lib/svg/cleanup/inline-style.d.cts +0 -11
- package/lib/svg/cleanup/inline-style.d.mts +0 -11
- package/lib/svg/cleanup/inline-style.mjs +0 -95
- package/lib/svg/cleanup/root-style.cjs +0 -34
- package/lib/svg/cleanup/root-style.d.cts +0 -17
- package/lib/svg/cleanup/root-style.d.mts +0 -17
- package/lib/svg/cleanup/root-style.mjs +0 -32
- package/lib/svg/cleanup/root-svg.cjs +0 -84
- package/lib/svg/cleanup/root-svg.d.cts +0 -11
- package/lib/svg/cleanup/root-svg.d.mts +0 -11
- package/lib/svg/cleanup/root-svg.mjs +0 -82
- package/lib/svg/cleanup/svgo-style.cjs +0 -43
- package/lib/svg/cleanup/svgo-style.d.cts +0 -11
- package/lib/svg/cleanup/svgo-style.d.mts +0 -11
- package/lib/svg/cleanup/svgo-style.mjs +0 -41
- package/lib/svg/cleanup.cjs +0 -33
- package/lib/svg/cleanup.d.cts +0 -16
- package/lib/svg/cleanup.d.mts +0 -16
- package/lib/svg/cleanup.mjs +0 -31
- package/lib/svg/data/attributes.cjs +0 -373
- package/lib/svg/data/attributes.d.cts +0 -77
- package/lib/svg/data/attributes.d.mts +0 -77
- package/lib/svg/data/attributes.mjs +0 -346
- package/lib/svg/data/tags.cjs +0 -141
- package/lib/svg/data/tags.d.cts +0 -95
- package/lib/svg/data/tags.d.mts +0 -95
- package/lib/svg/data/tags.mjs +0 -117
- package/lib/svg/index.cjs +0 -178
- package/lib/svg/index.d.cts +0 -52
- package/lib/svg/index.d.mts +0 -52
- package/lib/svg/index.mjs +0 -162
- package/lib/svg/parse-style.cjs +0 -243
- package/lib/svg/parse-style.d.cts +0 -59
- package/lib/svg/parse-style.d.mts +0 -59
- package/lib/svg/parse-style.mjs +0 -241
- package/lib/svg/parse.cjs +0 -46
- package/lib/svg/parse.d.cts +0 -31
- package/lib/svg/parse.d.mts +0 -31
- package/lib/svg/parse.mjs +0 -44
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merge text tokens to string
|
|
3
|
+
*/
|
|
4
|
+
function mergeTextTokens(tokens) {
|
|
5
|
+
return tokens.map((token) => token.text).join("").trim();
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Get list of selectors from list of words
|
|
9
|
+
*/
|
|
10
|
+
function getSelectors(tokens) {
|
|
11
|
+
const selectors = [];
|
|
12
|
+
let selector = "";
|
|
13
|
+
tokens.forEach((token) => {
|
|
14
|
+
if (token.type !== "chunk") {
|
|
15
|
+
selector += token.text;
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const list = token.text.split(",");
|
|
19
|
+
selector += list.shift();
|
|
20
|
+
while (list.length > 0) {
|
|
21
|
+
selectors.push(selector.trim());
|
|
22
|
+
selector = list.shift();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
selectors.push(selector.trim());
|
|
26
|
+
return selectors.filter((item) => item.length > 0);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Convert text token to rule
|
|
30
|
+
*/
|
|
31
|
+
function textTokensToRule(tokens) {
|
|
32
|
+
let prop = "";
|
|
33
|
+
let value = "";
|
|
34
|
+
let isProp = true;
|
|
35
|
+
let error = false;
|
|
36
|
+
tokens.forEach((token) => {
|
|
37
|
+
if (error) return;
|
|
38
|
+
if (token.type !== "chunk") {
|
|
39
|
+
if (isProp) error = true;
|
|
40
|
+
else value += token.text;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const pairs = token.text.split(":");
|
|
44
|
+
if (pairs.length > 2) {
|
|
45
|
+
error = true;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (pairs.length === 2) {
|
|
49
|
+
if (!isProp) {
|
|
50
|
+
error = true;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
prop += pairs[0];
|
|
54
|
+
value = pairs[1];
|
|
55
|
+
isProp = false;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (isProp) prop += token.text;
|
|
59
|
+
else value += token.text;
|
|
60
|
+
});
|
|
61
|
+
if (error || isProp) return null;
|
|
62
|
+
prop = prop.trim();
|
|
63
|
+
value = value.trim();
|
|
64
|
+
if (!prop.length || !value.length) return null;
|
|
65
|
+
const result = {
|
|
66
|
+
type: "rule",
|
|
67
|
+
prop: prop.toLowerCase(),
|
|
68
|
+
value,
|
|
69
|
+
index: tokens[0].index
|
|
70
|
+
};
|
|
71
|
+
["important"].forEach((word) => {
|
|
72
|
+
if (result.value.slice(-1 - word.length).toLowerCase() === "!" + word) {
|
|
73
|
+
result[word] = true;
|
|
74
|
+
result.value = result.value.slice(0, -1 - word.length).trim();
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return result.value.length ? result : null;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Create at-rule or selector token from text tokens
|
|
81
|
+
*/
|
|
82
|
+
function textTokensToSelector(tokens) {
|
|
83
|
+
const selectors = getSelectors(tokens);
|
|
84
|
+
const code = mergeTextTokens(tokens);
|
|
85
|
+
const index = tokens[0].index;
|
|
86
|
+
if (!selectors.length) return null;
|
|
87
|
+
if (code.charAt(0) === "@") {
|
|
88
|
+
const parts = code.split(/\s+/);
|
|
89
|
+
return {
|
|
90
|
+
type: "at-rule",
|
|
91
|
+
index,
|
|
92
|
+
rule: parts.shift().slice(1),
|
|
93
|
+
value: parts.join(" ").trim()
|
|
94
|
+
};
|
|
95
|
+
} else return {
|
|
96
|
+
type: "selector",
|
|
97
|
+
code,
|
|
98
|
+
index,
|
|
99
|
+
selectors
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { getSelectors, mergeTextTokens, textTokensToRule, textTokensToSelector };
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { StyleParseError } from
|
|
2
|
-
import { CSSToken } from
|
|
3
|
-
|
|
1
|
+
import { StyleParseError } from "./error.js";
|
|
2
|
+
import { CSSToken } from "./types.js";
|
|
4
3
|
/**
|
|
5
4
|
* Get tokens
|
|
6
5
|
*/
|
|
7
6
|
declare function getTokens(css: string): CSSToken[] | StyleParseError;
|
|
8
|
-
|
|
9
|
-
export { getTokens };
|
|
7
|
+
export { getTokens };
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { styleParseError } from "./error.js";
|
|
2
|
+
import { findEndOfQuotedString, findEndOfURL } from "./strings.js";
|
|
3
|
+
import { mergeTextTokens, textTokensToRule, textTokensToSelector } from "./text.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Find all tokens in css, sort by index
|
|
7
|
+
*/
|
|
8
|
+
function findTokens(code, tokens) {
|
|
9
|
+
const list = [];
|
|
10
|
+
const lc = code.toLowerCase();
|
|
11
|
+
tokens.forEach((token) => {
|
|
12
|
+
let index = 0;
|
|
13
|
+
while (true) {
|
|
14
|
+
index = lc.indexOf(token, index);
|
|
15
|
+
if (index === -1) return;
|
|
16
|
+
list.push({
|
|
17
|
+
token,
|
|
18
|
+
index
|
|
19
|
+
});
|
|
20
|
+
index++;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
list.sort((a, b) => a.index - b.index);
|
|
24
|
+
return list;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get tokens
|
|
28
|
+
*/
|
|
29
|
+
function getTokens(css) {
|
|
30
|
+
const items = [];
|
|
31
|
+
let textQueue = [];
|
|
32
|
+
let start = 0;
|
|
33
|
+
let depth = 0;
|
|
34
|
+
try {
|
|
35
|
+
const checkRule = (text) => {
|
|
36
|
+
if (!textQueue.length) return;
|
|
37
|
+
const item = textTokensToRule(textQueue);
|
|
38
|
+
if (item) {
|
|
39
|
+
items.push(item);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (!(mergeTextTokens(textQueue) + text).length) return;
|
|
43
|
+
throw styleParseError("Invalid css rule", css, textQueue[0]?.index);
|
|
44
|
+
};
|
|
45
|
+
findTokens(css, [
|
|
46
|
+
"\"",
|
|
47
|
+
"'",
|
|
48
|
+
"/*",
|
|
49
|
+
"{",
|
|
50
|
+
"}",
|
|
51
|
+
";",
|
|
52
|
+
"url(",
|
|
53
|
+
"\\"
|
|
54
|
+
]).forEach((token) => {
|
|
55
|
+
if (token.index < start) return;
|
|
56
|
+
switch (token.token) {
|
|
57
|
+
case "/*": {
|
|
58
|
+
textQueue.push({
|
|
59
|
+
type: "chunk",
|
|
60
|
+
text: css.slice(start, token.index),
|
|
61
|
+
index: start
|
|
62
|
+
});
|
|
63
|
+
start = token.index;
|
|
64
|
+
const end = css.indexOf("*/", start + 2);
|
|
65
|
+
if (end === -1) throw styleParseError("Missing comment closing statement", css, start);
|
|
66
|
+
start = end + 2;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case "\\":
|
|
70
|
+
textQueue.push({
|
|
71
|
+
type: "chunk",
|
|
72
|
+
text: css.slice(start, token.index + 2),
|
|
73
|
+
index: start
|
|
74
|
+
});
|
|
75
|
+
start = token.index + 2;
|
|
76
|
+
break;
|
|
77
|
+
case "url(": {
|
|
78
|
+
textQueue.push({
|
|
79
|
+
type: "chunk",
|
|
80
|
+
text: css.slice(start, token.index),
|
|
81
|
+
index: start
|
|
82
|
+
});
|
|
83
|
+
start = token.index;
|
|
84
|
+
const end = findEndOfURL(css, start);
|
|
85
|
+
if (typeof end !== "number") throw end;
|
|
86
|
+
textQueue.push({
|
|
87
|
+
type: "url",
|
|
88
|
+
text: css.slice(start, end),
|
|
89
|
+
index: start
|
|
90
|
+
});
|
|
91
|
+
start = end;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case "\"":
|
|
95
|
+
case "'": {
|
|
96
|
+
textQueue.push({
|
|
97
|
+
type: "chunk",
|
|
98
|
+
text: css.slice(start, token.index),
|
|
99
|
+
index: start
|
|
100
|
+
});
|
|
101
|
+
start = token.index;
|
|
102
|
+
const end = findEndOfQuotedString(css, token.token, start);
|
|
103
|
+
if (end === null) throw styleParseError("Missing closing " + token.token, css, start);
|
|
104
|
+
textQueue.push({
|
|
105
|
+
type: "quoted-string",
|
|
106
|
+
text: css.slice(start, end),
|
|
107
|
+
index: start
|
|
108
|
+
});
|
|
109
|
+
start = end;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
case ";":
|
|
113
|
+
textQueue.push({
|
|
114
|
+
type: "chunk",
|
|
115
|
+
text: css.slice(start, token.index),
|
|
116
|
+
index: start
|
|
117
|
+
});
|
|
118
|
+
checkRule(token.token);
|
|
119
|
+
start = token.index + 1;
|
|
120
|
+
textQueue = [];
|
|
121
|
+
break;
|
|
122
|
+
case "{": {
|
|
123
|
+
textQueue.push({
|
|
124
|
+
type: "chunk",
|
|
125
|
+
text: css.slice(start, token.index),
|
|
126
|
+
index: start
|
|
127
|
+
});
|
|
128
|
+
const item = textTokensToSelector(textQueue);
|
|
129
|
+
if (!item) throw styleParseError("Invalid css rule", css, start);
|
|
130
|
+
items.push(item);
|
|
131
|
+
start = token.index + 1;
|
|
132
|
+
textQueue = [];
|
|
133
|
+
depth++;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
case "}":
|
|
137
|
+
textQueue.push({
|
|
138
|
+
type: "chunk",
|
|
139
|
+
text: css.slice(start, token.index),
|
|
140
|
+
index: start
|
|
141
|
+
});
|
|
142
|
+
checkRule("");
|
|
143
|
+
items.push({
|
|
144
|
+
type: "close",
|
|
145
|
+
index: token.index
|
|
146
|
+
});
|
|
147
|
+
if (!depth) throw styleParseError("Unexpected }", css, token.index);
|
|
148
|
+
depth--;
|
|
149
|
+
start = token.index + 1;
|
|
150
|
+
textQueue = [];
|
|
151
|
+
break;
|
|
152
|
+
default: throw new Error(`Forgot to parse token: ${token.token}`);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
if (depth) return styleParseError("Missing }", css);
|
|
156
|
+
textQueue.push({
|
|
157
|
+
type: "chunk",
|
|
158
|
+
text: css.slice(start),
|
|
159
|
+
index: start
|
|
160
|
+
});
|
|
161
|
+
checkRule("");
|
|
162
|
+
} catch (err) {
|
|
163
|
+
if (typeof err === "object" && err.type === "style-parse-error") return err;
|
|
164
|
+
throw err;
|
|
165
|
+
}
|
|
166
|
+
return items;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export { getTokens };
|
package/lib/css/parser/tree.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { CSSToken, CSSTreeToken } from
|
|
2
|
-
|
|
1
|
+
import { CSSToken, CSSTreeToken } from "./types.js";
|
|
3
2
|
/**
|
|
4
3
|
* Convert tokens list to tree
|
|
5
4
|
*/
|
|
6
5
|
declare function tokensTree(tokens: CSSToken[]): CSSTreeToken[];
|
|
7
|
-
|
|
8
|
-
export { tokensTree };
|
|
6
|
+
export { tokensTree };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert tokens list to tree
|
|
3
|
+
*/
|
|
4
|
+
function tokensTree(tokens) {
|
|
5
|
+
const result = [];
|
|
6
|
+
let index = 0;
|
|
7
|
+
function parse(target) {
|
|
8
|
+
while (index < tokens.length) {
|
|
9
|
+
const token = tokens[index];
|
|
10
|
+
index++;
|
|
11
|
+
switch (token.type) {
|
|
12
|
+
case "close": return;
|
|
13
|
+
case "selector":
|
|
14
|
+
case "at-rule": {
|
|
15
|
+
const newItem = {
|
|
16
|
+
...token,
|
|
17
|
+
children: []
|
|
18
|
+
};
|
|
19
|
+
target.push(newItem);
|
|
20
|
+
parse(newItem.children);
|
|
21
|
+
if (!newItem.children.length) {
|
|
22
|
+
const index$1 = target.indexOf(newItem);
|
|
23
|
+
if (index$1 !== -1) target.splice(index$1, 1);
|
|
24
|
+
}
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
default: target.push(token);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
while (index < tokens.length) parse(result);
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { tokensTree };
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Text tokens, to be split combined into correct tokens later
|
|
3
3
|
*/
|
|
4
4
|
interface TextToken {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
type: 'chunk' | 'url' | 'quoted-string';
|
|
6
|
+
index: number;
|
|
7
|
+
text: string;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Values
|
|
@@ -14,27 +14,27 @@ type CSSATValue = string | string[];
|
|
|
14
14
|
* Tokens
|
|
15
15
|
*/
|
|
16
16
|
interface CSSRuleToken {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
type: 'rule';
|
|
18
|
+
index: number;
|
|
19
|
+
prop: string;
|
|
20
|
+
value: string;
|
|
21
|
+
important?: boolean;
|
|
22
22
|
}
|
|
23
23
|
interface CSSSelectorToken {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
type: 'selector';
|
|
25
|
+
index: number;
|
|
26
|
+
code: string;
|
|
27
|
+
selectors: string[];
|
|
28
28
|
}
|
|
29
29
|
interface CSSAtRuleToken {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
type: 'at-rule';
|
|
31
|
+
index: number;
|
|
32
|
+
rule: string;
|
|
33
|
+
value: string;
|
|
34
34
|
}
|
|
35
35
|
interface CSSCloseToken {
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
type: 'close';
|
|
37
|
+
index: number;
|
|
38
38
|
}
|
|
39
39
|
type CSSTokenWithSelector = CSSSelectorToken | CSSAtRuleToken;
|
|
40
40
|
type CSSToken = CSSRuleToken | CSSSelectorToken | CSSAtRuleToken | CSSCloseToken;
|
|
@@ -42,11 +42,10 @@ type CSSToken = CSSRuleToken | CSSSelectorToken | CSSAtRuleToken | CSSCloseToken
|
|
|
42
42
|
* Tree tokens
|
|
43
43
|
*/
|
|
44
44
|
interface CSSSelectorTreeToken extends CSSSelectorToken {
|
|
45
|
-
|
|
45
|
+
children: CSSTreeToken[];
|
|
46
46
|
}
|
|
47
47
|
interface CSSAtRuleTreeToken extends CSSAtRuleToken {
|
|
48
|
-
|
|
48
|
+
children: CSSTreeToken[];
|
|
49
49
|
}
|
|
50
50
|
type CSSTreeToken = CSSRuleToken | CSSSelectorTreeToken | CSSAtRuleTreeToken;
|
|
51
|
-
|
|
52
|
-
export type { CSSATValue, CSSAtRuleToken, CSSAtRuleTreeToken, CSSCloseToken, CSSRuleToken, CSSSelectorToken, CSSSelectorTreeToken, CSSToken, CSSTokenWithSelector, CSSTreeToken, TextToken };
|
|
51
|
+
export { CSSATValue, CSSAtRuleToken, CSSAtRuleTreeToken, CSSCloseToken, CSSRuleToken, CSSSelectorToken, CSSSelectorTreeToken, CSSToken, CSSTokenWithSelector, CSSTreeToken, TextToken };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { APICacheOptions, APIQueryParams } from "./types.js";
|
|
3
2
|
/**
|
|
4
3
|
* Unique key
|
|
5
4
|
*/
|
|
@@ -16,5 +15,4 @@ declare function getAPICache(dir: string, key: string): Promise<string | null>;
|
|
|
16
15
|
* Clear cache
|
|
17
16
|
*/
|
|
18
17
|
declare function clearAPICache(dir: string): Promise<void>;
|
|
19
|
-
|
|
20
|
-
export { apiCacheKey, clearAPICache, getAPICache, storeAPICache };
|
|
18
|
+
export { apiCacheKey, clearAPICache, getAPICache, storeAPICache };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { scanDirectory } from "../../misc/scan.js";
|
|
2
|
+
import { promises } from "fs";
|
|
3
|
+
import { createHash } from "crypto";
|
|
4
|
+
|
|
5
|
+
const cacheVersion = 1;
|
|
6
|
+
const storedFiles = Object.create(null);
|
|
7
|
+
/**
|
|
8
|
+
* Unique key
|
|
9
|
+
*/
|
|
10
|
+
function apiCacheKey(query) {
|
|
11
|
+
const item = JSON.stringify({
|
|
12
|
+
uri: query.uri,
|
|
13
|
+
params: query.params?.toString(),
|
|
14
|
+
headers: query.headers
|
|
15
|
+
});
|
|
16
|
+
return createHash("md5").update(item).digest("hex");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Store cache
|
|
20
|
+
*/
|
|
21
|
+
async function storeAPICache(options, key, data) {
|
|
22
|
+
const expires = Date.now() + options.ttl * 1e3;
|
|
23
|
+
const filename = options.dir + "/" + key + "." + expires.toString() + ".json";
|
|
24
|
+
if (!storedFiles[options.dir]) await getStoredFiles(options.dir);
|
|
25
|
+
const content = {
|
|
26
|
+
version: cacheVersion,
|
|
27
|
+
expires,
|
|
28
|
+
data
|
|
29
|
+
};
|
|
30
|
+
await promises.writeFile(filename, JSON.stringify(content, null, 4), "utf8");
|
|
31
|
+
storedFiles[options.dir][key] = {
|
|
32
|
+
filename,
|
|
33
|
+
expires
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get item from cache
|
|
38
|
+
*/
|
|
39
|
+
async function getAPICache(dir, key) {
|
|
40
|
+
if (!storedFiles[dir]) await getStoredFiles(dir);
|
|
41
|
+
const item = storedFiles[dir][key];
|
|
42
|
+
if (!item) return null;
|
|
43
|
+
const time = Date.now();
|
|
44
|
+
try {
|
|
45
|
+
const content = JSON.parse(await promises.readFile(item.filename, "utf8"));
|
|
46
|
+
return content.version === cacheVersion && content.expires > time ? content.data : null;
|
|
47
|
+
} catch (err) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Clear cache
|
|
53
|
+
*/
|
|
54
|
+
function clearAPICache(dir) {
|
|
55
|
+
return getStoredFiles(dir, true);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Find all stored files
|
|
59
|
+
*/
|
|
60
|
+
async function getStoredFiles(dir, clear = false) {
|
|
61
|
+
const storage = !clear && storedFiles[dir] || Object.create(null);
|
|
62
|
+
const time = Date.now();
|
|
63
|
+
storedFiles[dir] = storage;
|
|
64
|
+
try {
|
|
65
|
+
await promises.mkdir(dir, { recursive: true });
|
|
66
|
+
} catch (err) {}
|
|
67
|
+
await scanDirectory(dir, async (ext, file, subdir, path) => {
|
|
68
|
+
if (ext !== ".json") return false;
|
|
69
|
+
const filename = path + subdir + file + ext;
|
|
70
|
+
const parts = file.split(".");
|
|
71
|
+
const expires = parseInt(parts.pop());
|
|
72
|
+
if (clear || expires < time || parts.length !== 1) {
|
|
73
|
+
await promises.unlink(filename);
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const cacheKey = parts[0];
|
|
77
|
+
storage[cacheKey] = {
|
|
78
|
+
filename,
|
|
79
|
+
expires
|
|
80
|
+
};
|
|
81
|
+
}, false);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { apiCacheKey, clearAPICache, getAPICache, storeAPICache };
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { APIQueryParams } from "./types.js";
|
|
2
|
+
import { RequestOptions } from "node:http";
|
|
4
3
|
/**
|
|
5
4
|
* Axios config, customisable
|
|
6
5
|
*/
|
|
7
6
|
declare const axiosConfig: Omit<RequestOptions, 'headers' | 'responseType' | 'url' | 'method' | 'data'>;
|
|
8
7
|
interface AxiosCallbacks {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
onStart?: (url: string, params: APIQueryParams) => void;
|
|
9
|
+
onSuccess?: (url: string, params: APIQueryParams) => void;
|
|
10
|
+
onError?: (url: string, params: APIQueryParams, errorCode?: number) => void;
|
|
12
11
|
}
|
|
13
12
|
/**
|
|
14
13
|
* Customisable callbacks, used for logging
|
|
15
14
|
*/
|
|
16
15
|
declare const fetchCallbacks: AxiosCallbacks;
|
|
17
|
-
|
|
18
|
-
export { axiosConfig, fetchCallbacks };
|
|
16
|
+
export { axiosConfig, fetchCallbacks };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { APIQueryParams } from
|
|
2
|
-
|
|
1
|
+
import { APIQueryParams } from "./types.js";
|
|
3
2
|
/**
|
|
4
3
|
* Download file
|
|
5
4
|
*/
|
|
6
5
|
declare function downloadFile(query: APIQueryParams, target: string): Promise<void>;
|
|
7
|
-
|
|
8
|
-
export { downloadFile };
|
|
6
|
+
export { downloadFile };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { axiosConfig, fetchCallbacks } from "./config.js";
|
|
2
|
+
import { getFetch } from "./fetch.js";
|
|
3
|
+
import { writeFile } from "fs/promises";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Download file
|
|
7
|
+
*/
|
|
8
|
+
async function downloadFile(query, target) {
|
|
9
|
+
const params = query.params ? query.params.toString() : "";
|
|
10
|
+
const url = query.uri + (params ? "?" + params : "");
|
|
11
|
+
const headers = query.headers;
|
|
12
|
+
fetchCallbacks.onStart?.(url, query);
|
|
13
|
+
const response = await getFetch()(url, {
|
|
14
|
+
...axiosConfig,
|
|
15
|
+
headers
|
|
16
|
+
});
|
|
17
|
+
if (response.status !== 200) {
|
|
18
|
+
fetchCallbacks.onError?.(url, query, response.status);
|
|
19
|
+
throw new Error(`Error downloading ${url}: ${response.status}`);
|
|
20
|
+
}
|
|
21
|
+
const data = await response.arrayBuffer();
|
|
22
|
+
fetchCallbacks.onSuccess?.(url, query);
|
|
23
|
+
await writeFile(target, Buffer.from(data));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { downloadFile };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
let customFetch = fetch;
|
|
2
|
+
/**
|
|
3
|
+
* Set custom fetch function
|
|
4
|
+
*/
|
|
5
|
+
function setFetch(fetchFunction) {
|
|
6
|
+
customFetch = fetchFunction;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Get fetch function
|
|
10
|
+
*/
|
|
11
|
+
function getFetch() {
|
|
12
|
+
return customFetch;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { getFetch, setFetch };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { APICacheOptions, APIQueryParams } from "./types.js";
|
|
3
2
|
/**
|
|
4
3
|
* Send API query
|
|
5
4
|
*/
|
|
6
5
|
declare function sendAPIQuery(query: APIQueryParams, cache?: APICacheOptions): Promise<number | string>;
|
|
7
|
-
|
|
8
|
-
export { sendAPIQuery };
|
|
6
|
+
export { sendAPIQuery };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { apiCacheKey, getAPICache, storeAPICache } from "./cache.js";
|
|
2
|
+
import { axiosConfig, fetchCallbacks } from "./config.js";
|
|
3
|
+
import { getFetch } from "./fetch.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Send API query
|
|
7
|
+
*/
|
|
8
|
+
async function sendAPIQuery(query, cache) {
|
|
9
|
+
const cacheKey = cache ? apiCacheKey(query) : "";
|
|
10
|
+
if (cache) {
|
|
11
|
+
const cached = await getAPICache(cache.dir, cacheKey);
|
|
12
|
+
if (cached) return cached;
|
|
13
|
+
}
|
|
14
|
+
const result = await sendQuery(query);
|
|
15
|
+
if (cache && typeof result !== "number") try {
|
|
16
|
+
await storeAPICache(cache, cacheKey, result);
|
|
17
|
+
} catch (err) {
|
|
18
|
+
console.error("Error writing API cache");
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Send query
|
|
24
|
+
*/
|
|
25
|
+
async function sendQuery(query) {
|
|
26
|
+
const params = query.params ? query.params.toString() : "";
|
|
27
|
+
const url = query.uri + (params ? "?" + params : "");
|
|
28
|
+
const headers = query.headers;
|
|
29
|
+
fetchCallbacks.onStart?.(url, query);
|
|
30
|
+
function fail(value) {
|
|
31
|
+
fetchCallbacks.onError?.(url, query, value);
|
|
32
|
+
return value ?? 404;
|
|
33
|
+
}
|
|
34
|
+
const fetch = getFetch();
|
|
35
|
+
try {
|
|
36
|
+
const response = await fetch(url, {
|
|
37
|
+
...axiosConfig,
|
|
38
|
+
headers
|
|
39
|
+
});
|
|
40
|
+
if (response.status !== 200) return fail(response.status);
|
|
41
|
+
const data = await response.text();
|
|
42
|
+
if (typeof data !== "string") return fail();
|
|
43
|
+
fetchCallbacks.onSuccess?.(url, query);
|
|
44
|
+
return data;
|
|
45
|
+
} catch (err) {
|
|
46
|
+
return fail();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { sendAPIQuery };
|