pax_global_header00006660000000000000000000000064145310057610014514gustar00rootroot0000000000000052 comment=9d2308783efb3fec44447fcd58962ff837b6666a jaywcjlove-image2uri-25bcf98/000077500000000000000000000000001453100576100161775ustar00rootroot00000000000000jaywcjlove-image2uri-25bcf98/.github/000077500000000000000000000000001453100576100175375ustar00rootroot00000000000000jaywcjlove-image2uri-25bcf98/.github/FUNDING.yml000066400000000000000000000006261453100576100213600ustar00rootroot00000000000000# These are supported funding model platforms # github: [jaywcjlove] # patreon: # Replace with a single Patreon username # open_collective: # Replace with a single Open Collective username # ko_fi: # Replace with a single Ko-fi username # tidelift: npm/colors-cli # community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry custom: https://jaywcjlove.github.io/#/sponsor jaywcjlove-image2uri-25bcf98/.github/workflows/000077500000000000000000000000001453100576100215745ustar00rootroot00000000000000jaywcjlove-image2uri-25bcf98/.github/workflows/ci.yml000066400000000000000000000057121453100576100227170ustar00rootroot00000000000000name: CI on: push: branches: - master jobs: build-deploy: runs-on: ubuntu-latest permissions: contents: write id-token: write steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: 18 registry-url: 'https://registry.npmjs.org' - run: npm install - run: npm run coverage - name: Create Coverage Badges uses: jaywcjlove/coverage-badges-cli@main - name: Create idoc config. run: | cat > idoc.yml << EOF site: "Image To URI {{version}}" menus: Home: index.html EOF - run: npm install idoc@1.27.2 -g - run: idoc --output="coverage" - name: Generate Contributors Images uses: jaywcjlove/github-action-contributors@main with: filter-author: (renovate\[bot\]|renovate-bot|dependabot\[bot\]) output: coverage/CONTRIBUTORS.svg avatarSize: 42 - name: Create Tag id: create_tag uses: jaywcjlove/create-tag-action@main with: package-path: ./package.json - name: get tag version id: tag_version uses: jaywcjlove/changelog-generator@main - name: Deploy Website uses: peaceiris/actions-gh-pages@v3 with: user_name: 'github-actions[bot]' user_email: 'github-actions[bot]@users.noreply.github.com' commit_message: ${{steps.tag_version.outputs.tag}} ${{ github.event.head_commit.message }} github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./coverage - name: Generate Changelog id: changelog uses: jaywcjlove/changelog-generator@main with: head-ref: ${{steps.create_tag.outputs.version}} filter-author: (å°�弟调调™|Renovate Bot) filter: '[R|r]elease[d]\s+[v|V]\d(\.\d+){0,2}' - name: Create Release uses: ncipollo/release-action@v1 if: steps.create_tag.outputs.successful with: name: ${{ steps.create_tag.outputs.version }} tag: ${{ steps.create_tag.outputs.version }} token: ${{ secrets.GITHUB_TOKEN }} body: | [![Buy me a coffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-048754?logo=buymeacoffee)](https://jaywcjlove.github.io/#/sponsor) [![](https://img.shields.io/badge/Open%20in-unpkg-blue)](https://uiwjs.github.io/npm-unpkg/#/pkg/image2uri@${{steps.changelog.outputs.version}}/file/README.md) Documentation ${{ steps.changelog.outputs.tag }}: https://raw.githack.com/jaywcjlove/idoc/${{ steps.changelog.outputs.gh-pages-short-hash }}/index.html Comparing Changes: ${{ steps.changelog.outputs.compareurl }} ${{ steps.changelog.outputs.changelog }} - run: npm publish --access public --provenance continue-on-error: true env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} jaywcjlove-image2uri-25bcf98/.gitignore000066400000000000000000000030351453100576100201700ustar00rootroot00000000000000# Created by https://www.gitignore.io/api/node # Edit at https://www.gitignore.io/?templates=node lib package-lock.json __snapshots__ ### Node ### # Logs logs *.log npm-debug.log* yarn-debug.log* yarn-error.log* lerna-debug.log* # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json # Runtime data pids *.pid *.seed *.pid.lock # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # nyc test coverage .nyc_output # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) .grunt # Bower dependency directory (https://bower.io/) bower_components # node-waf configuration .lock-wscript # Compiled binary addons (https://nodejs.org/api/addons.html) build/Release # Dependency directories node_modules/ jspm_packages/ # TypeScript v1 declaration files typings/ # Optional npm cache directory .npm # Optional eslint cache .eslintcache # Optional REPL history .node_repl_history # Output of 'npm pack' *.tgz # Yarn Integrity file .yarn-integrity # dotenv environment variables file .env .env.test # parcel-bundler cache (https://parceljs.org/) .cache # next.js build output .next # nuxt.js build output .nuxt # vuepress build output .vuepress/dist # Serverless directories .serverless/ # FuseBox cache .fusebox/ # DynamoDB Local files .dynamodb/ # End of https://www.gitignore.io/api/node .DS_Store .cache .vscode .idea .env *.bak *.tem *.temp #.swp *.*~ ~*.* # IDEA *.iml *.ipr *.iws .idea/jaywcjlove-image2uri-25bcf98/LICENSE000066400000000000000000000020601453100576100172020ustar00rootroot00000000000000MIT License Copyright (c) 2020 å°�弟调调™ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. jaywcjlove-image2uri-25bcf98/README.md000066400000000000000000000060031453100576100174550ustar00rootroot00000000000000Image To URI === [![Buy me a coffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-048754?logo=buymeacoffee)](https://jaywcjlove.github.io/#/sponsor) [![NPM Downloads](https://img.shields.io/npm/dm/image2uri.svg?style=flat)](https://www.npmjs.com/package/image2uri) [![Build & Test](https://github.com/jaywcjlove/image2uri/actions/workflows/ci.yml/badge.svg)](https://github.com/jaywcjlove/image2uri/actions/workflows/ci.yml) [![npm version](https://img.shields.io/npm/v/image2uri.svg)](https://www.npmjs.com/package/image2uri) [![Coverage Status](https://jaywcjlove.github.io/image2uri/badges.svg)](https://jaywcjlove.github.io/image2uri/lcov-report/) Convert image file to data URI. Support `.png`,`.gif`,`.jpg`,`.jpeg`,`.bm`,`.bmp`,`.webp`,`.ico`,`.svg`. ### Install This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): Node 12+ is needed to use it and it must be import instead of require. ```bash npm i image2uri ``` ```js const recursiveReaddirFiles = await import('image2uri'); // Fix compiling in typescript. // https://github.com/microsoft/TypeScript/issues/43329#issuecomment-922544562 const { getExt, recursiveReaddirFiles } = await (Function('return import("image2uri")')()) as Promise; ``` ### Basic Usage ```js import image2uri from "image2uri"; console.log(image2uri('./example.bmp')); // data:image/bmp;base64,Qk0YCAAAAAAAADYAAAAoAAAAGAAAABwAAAABABgAAAAAAOIHAAA.... console.log(image2uri('./example.jpg')); // data:image/jpeg;base64,Qk0YCAAAAAAAADYAAAAoAAAAGAAAABwAAAABABgAAAAAAOIHAAA.... const uri = await image2uri('https://avatars.githubusercontent.com/u/1680273?v=4', { ext: '.apng' }); // data:image/apng;base64,/9j/2wCEAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDc const avatar = await image2uri('https://avatars.githubusercontent.com/u/1680273?v=4'); // /9j/2wCEAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDc ``` ### API ```ts export declare const validUrl: (url: string) => boolean; export declare const extTypeMap: { '.png': string; '.apng': string; '.gif': string; '.jpg': string; '.jpeg': string; '.bm': string; '.bmp': string; '.webp': string; '.ico': string; '.svg': string; }; export type ExtType = keyof typeof extTypeMap; export default function image2uri(file: string, options?: { ext?: string; }): string | Promise; ``` ### Development ```bash npm run watch # Listen compile .ts files. npm run build # compile .ts files. npm run start ``` ### Related - [recursive-readdir-files](https://github.com/jaywcjlove/recursive-readdir-files) Node.js module to list all files in a directory or any subdirectories. ## Contributors As always, thanks to our amazing contributors! Made with [action-contributors](https://github.com/jaywcjlove/github-action-contributors). ### License Licensed under the MIT License. jaywcjlove-image2uri-25bcf98/package.json000066400000000000000000000020761453100576100204720ustar00rootroot00000000000000{ "name": "image2uri", "version": "2.1.2", "description": "Convert image file to data URI.", "homepage": "https://jaywcjlove.github.io/image2uri/", "funding": "https://jaywcjlove.github.io/#/sponsor", "license": "MIT", "author": "Kenny ", "type": "module", "exports": "./lib/index.js", "types": "./lib/index.d.ts", "main": "./lib/index.js", "scripts": { "prepare": "npm run build", "watch": "tsbb watch", "build": "tsbb build", "test": "tsbb test", "coverage": "tsbb test --coverage" }, "repository": { "type": "git", "url": "https://github.com/jaywcjlove/image2uri" }, "files": [ "lib", "src" ], "jest": { "transformIgnorePatterns": [ "/node_modules/?!(.*)" ], "coverageReporters": [ "lcov", "json-summary" ] }, "keywords": [ "image", "uri", "fs", "base64", "image-to-uri", "image2uri" ], "dependencies": { "node-fetch": "^3.3.1" }, "devDependencies": { "@types/node": "^18.15.11", "tsbb": "^4.1.14" } } jaywcjlove-image2uri-25bcf98/renovate.json000066400000000000000000000002141453100576100207120ustar00rootroot00000000000000{ "extends": ["config:base"], "packageRules": [ { "matchPackagePatterns": ["*"], "rangeStrategy": "replace" } ] } jaywcjlove-image2uri-25bcf98/src/000077500000000000000000000000001453100576100167665ustar00rootroot00000000000000jaywcjlove-image2uri-25bcf98/src/index.ts000066400000000000000000000021501453100576100204430ustar00rootroot00000000000000import fs from 'fs'; import path from 'path'; import fetch from 'node-fetch'; export const validUrl = (url: string) => /http(s)?:\/\/(\w+:?\w*@)?(\S+)(:\d+)?((?<=\.)\w+)+(\/([\w#!:.?+=&%@!\-/])*)?/gi.test(url); export const extTypeMap = { '.png': 'image/png', '.apng': 'image/apng', '.gif': 'image/gif', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.bm': 'image/bmp', '.bmp': 'image/bmp', '.webp': 'image/webp', '.ico': 'image/x-icon', '.svg': 'image/svg+xml' } export type ExtType = keyof typeof extTypeMap; export default function image2uri(file: string, options: { ext?: string } = {}): string | Promise { const ext: ExtType = (options.ext || path.extname(file)) as ExtType; const contentType = extTypeMap[ext] if (validUrl(file)) { return fetch(file).then((response) => response.buffer()).then((buffer) => { return contentType ? `data:${contentType};base64,${buffer.toString('base64')}` : buffer.toString('base64'); }); } const image = fs.readFileSync(file); return contentType ? `data:${contentType};base64,${image.toString('base64')}` : image.toString('base64'); }jaywcjlove-image2uri-25bcf98/test/000077500000000000000000000000001453100576100171565ustar00rootroot00000000000000jaywcjlove-image2uri-25bcf98/test/imgs/000077500000000000000000000000001453100576100201155ustar00rootroot00000000000000jaywcjlove-image2uri-25bcf98/test/imgs/uiw-jpeg000066400000000000000000000023761453100576100215770ustar00rootroot00000000000000ÿØÿáExifII*ÿìDuckyÿá.http://ns.adobe.com/xap/1.0/ ÿîAdobedÀÿÛ„))A&&AB///BG?>>?GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG))4&4?((?G?5?GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGÿÀ"ÿÄh!1Q¡ðAaÑq±á"2Bb$ÿÚ ?ʺٳ^[ð 7 F ÿþýüûúùø÷öõôóòñðïîíìëêéèçæåäãâáàßÞÝÜÛÚÙØ×ÖÕÔÓÒÑÐÏÎÍÌËÊÉÈÇÆÅÄÃÂÁÀ¿¾½¼»º¹¸·¶µ´³²±°¯®­¬«ª©¨§¦¥¤£¢¡ Ÿž�œ›š™˜—–•”“’‘��Ž�Œ‹Š‰ˆ‡†…„ƒ‚�€~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!  !ùL,å€L‚‚ !ƒˆ‰ŠL.KK5‹“‚*�˜”‰<˜ "œ‚ §K'¤)¨§3¤C®˜?¤@³K8ˆ&BŠ ºƒ$�(ƒ³1‚0I§4L³ƒº‚;®‚+ºK‚éêLHŸÞ¤J忤Dô‚ûü‚Ê1éÁÁÕAGŒx»1ËÂ&&6 ¸jÀ$à,ƒZ`2b@&,è*0è‚– *Q®H‚A¡—ƒÔ z×8 1 Â?R‚X@8µ@PD`bpáh¢ :Èp:©U&�;jaywcjlove-image2uri-25bcf98/test/imgs/uiw.ico000066400000000000000000000054561453100576100214270ustar00rootroot00000000000000  (8 € ]]] ```KKK•KKKîLLLQNNN'KKKÐJJJÿJJJÿJJJÿJJJ”mmmJJJ`JJJôJJJÿJJJÿJJJÿJJJÿJJJÿKKKÐNNN'NNN KKK¤JJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJôKKK_JJJÎJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJqKKKªJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿLLLMKKKXJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿKKKó```€€€NNN JJJøJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿKKK©UUUKKKÍKKKÃLLLoRRRKKK´JJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿLLLWJJJ�JJJÿJJJÿJJJÿJJJþJJJÇLLLrJJJKKKbJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJøNNN MMMFJJJþJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÊQQQKKKüJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJ³UUUKKKçJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿKKK»JJJúJJJúJJJúJJJúJJJúJJJúJJJúKKK_KKK´JJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿLLLlJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÑJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿRRRKKK)KKK)KKK)KKK)KKK)KKK)KKK)MMM KKK3JJJúJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿKKKÌJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿLLLoJJJuJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿKKKÁÿÿÿKKK»JJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJqJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿKKKýQQQNNNKKKëJJJÿJJJÿJJJÿJJJÿJJJÿJJJþKKKÅJJJqKKKÃJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿKKKfKKKNJJJÿJJJÿKKKýKKKÁKKKmLLLNNNKKKýJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿKKK¸KKKwKKKjJJJJJJgJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJúPPPJJJ¹JJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿKKK\JJJ²JJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJúMMMZÿÿÿKKKtJJJúJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿJJJÿKKKÝLLL6LLL6KKKÞJJJÿJJJÿJJJÿJJJÿJJJÿJJJ¨[[[UUUKKK©JJJÿJJJÿKKKöLLLeLLLeJJJÊMMM+ýÿÿðÿÿà?ÿÀÿÿÿÿ€€ €ÀÿðÿðÀÀ€€ €ÿÿÿÿÀÿàÿøÿÿjaywcjlove-image2uri-25bcf98/test/imgs/uiw.jpeg000066400000000000000000000023761453100576100216000ustar00rootroot00000000000000ÿØÿáExifII*ÿìDuckyÿá.http://ns.adobe.com/xap/1.0/ ÿîAdobedÀÿÛ„))A&&AB///BG?>>?GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG))4&4?((?G?5?GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGÿÀ"ÿÄh!1Q¡ðAaÑq±á"2Bb$ÿÚ ?ʺٳ^[ð 7 F ÿîAdobedÀÿÛ„))A&&AB///BG?>>?GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG))4&4?((?G?5?GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGÿÀ"ÿÄh!1Q¡ðAaÑq±á"2Bb$ÿÚ ?ʺٳ^[ð 7 F’(ÔÆJƒ�b³°‚ˆ«à6IŒDŒ«Ep‰6‚…‚Ø¥±TÔbEÈA—ÄI̯P°qÁ…Äb  bRˆŸhb>ž;î›gg&“Å�ûî½çžûîûÍðœA‹D"ÉÁ`�Eq¶T*½5€Ø6ñZd<ßÚn·ç†Ãái²ó<ÿýr¹\~ Å�3V`Ö“ ~Œ¾Ç€`Áçó]Èd2_ |–&„|½^¿ ™r» z_§Ó™ K�F㣠ÆÐ,Öjµ"<—ÐECĚчIHÁ`ð=’¼Y3[�¸ÝÖ�¼Nl>ÅØn–m£9î·Óé,��çh…~¿å�œNÔ‹B¡ðE› _ƒþ ñrµZý¤õÑX9E½à�ީבàb¥R™cvÄE÷”tø‹è9Œemå08ÈIÙ!,�Ëå*žZ4Ý…ÊþÕZ�ÃÔÁwÉ_AæØ²ØÙ‡Å|>ÿ™ȃ|ré�‡ï ì·”X»ÌðµP5QÙLÁìèÞcº•T–ˆn·û8.Ó630¬�ä ¿a†ÓÛÕ§Bï0ÓC¡Ð2|ûÍüz;Û½ÝTa¬‡O­¥?GéSfÌX¢$Žè<ù�-6ÃjíJ±XŒ¹£èN³ÂS,ÐãñÌ"áºKÅüZ©$èv»'@0ê±›ÆÙßBÁÙl¶‰¥:‡áPKf0®±=8iàÔ›ÜxèB̈/Ý3Œo3}URÂ%$¿¹ÇÒA³êõz¶Î4ª¤‰,¬’q^¯÷:¾€G ·±d9Üô'²,`~’<6ì i�fc�|߉–N§1L*•Ðé2l´Dv–G ÆD6·Z­i-“9áíÕŒcÆÂ øL¡ôÌ(bø'aãôkª^4<�wѽú/ãi¦X,¾ÓûFéì˜r˜YÕL™.èžßï?°râQ+`¤’$mj6›7¡ŸE²óø2å™ï¿ÊD"±n©6’àSÇ«¯•2ùIEND®B`‚jaywcjlove-image2uri-25bcf98/test/imgs/uiw.svg000066400000000000000000000007361453100576100214500ustar00rootroot00000000000000 jaywcjlove-image2uri-25bcf98/test/imgs/uiw.webp000066400000000000000000000007061453100576100216030ustar00rootroot00000000000000RIFF¾WEBPVP8L±/À·â¸‘$EÊšeÞ纻FžÌ\ê³Âu$ÙJ5{qç“t ’0žËºŽ$[©f/î|’.A†ÃsYÅm$µ9fÈ™jÓ6`öÝÛ¬ãÈfšÒ2 œÏ“í<;÷=Ç}wh^ï7ïÏI1�c?ß/ßß�Ï÷K�ç|¾_~ÿ?ešòx>cÇíûû™Bð÷ÿ7IQÒ³]m#)Å6)ÿ¿@´�$%EÛA’±ôûÿM!`ÛÈÙþ@•pm'IØn’R €h[ J ¶‘´€$ 9¶ü3A¶mÓщÓfضmÛˆÏü‡r_þ{çÿ!Dô?­¿T‘dð‚Ö\G|ý›Ñùtê Mÿ«yEÑ^‚º£Z†Ú¤hA�uÞ¢´5ï‘áÜ­û°3·Ç ; ›üeÔ{ÚC‰Á,uÏöJvH›¨øyÔÚ�ŸT�ÛT°û¶¿»¡Àp‡þ5lä‡!ִа™ýÜ0\€;¦ë=ï—Pl1¼€Ë¼=îN£¿HñŸƒKÿ¤š…z§Úƒ*ž1h¬ fµÁ裌ØòÝI r§óHX@<jaywcjlove-image2uri-25bcf98/test/index.test.ts000066400000000000000000000063141453100576100216170ustar00rootroot00000000000000import path from 'path'; import image2uri, { extTypeMap, ExtType } from '../src'; it('test uiw.bm', () => { const bmPath = path.join(__dirname, 'imgs', 'uiw.bm'); const uri = image2uri(bmPath); const ext = path.extname(bmPath) as ExtType; expect(image2uri).toBeDefined() expect(typeof uri).toBe('string'); // @ts-ignore expect(extTypeMap[ext]).toEqual(uri.replace(/^data:(.*);base64\,.+/, "$1")); }); it('test uiw.bmp', () => { const bmpPath = path.join(__dirname, 'imgs', 'uiw.bmp'); const uri = image2uri(bmpPath); const ext = path.extname(bmpPath) as ExtType; expect(typeof uri).toBe('string'); // @ts-ignore expect(extTypeMap[ext]).toEqual(uri.replace(/^data:(.*);base64\,.+/, "$1")); }); it('test uiw.gif', () => { const gifPath = path.join(__dirname, 'imgs', 'uiw.gif'); const uri = image2uri(gifPath); const ext = path.extname(gifPath) as ExtType; expect(typeof uri).toBe('string'); // @ts-ignore expect(extTypeMap[ext]).toEqual(uri.replace(/^data:(.*);base64\,.+/, "$1")); }); it('test uiw.ico', () => { const icoPath = path.join(__dirname, 'imgs', 'uiw.ico'); const uri = image2uri(icoPath) const ext = path.extname(icoPath) as ExtType; expect(typeof uri).toBe('string'); // @ts-ignore expect(extTypeMap[ext]).toEqual(uri.replace(/^data:(.*);base64\,.+/, "$1")); }); it('test uiw.jpeg', () => { const jpegPath = path.join(__dirname, 'imgs', 'uiw.jpeg'); const uri = image2uri(jpegPath); const ext = path.extname(jpegPath) as ExtType; expect(typeof uri).toBe('string'); // @ts-ignore expect(extTypeMap[ext]).toEqual(uri.replace(/^data:(.*);base64\,.+/, "$1")); }); it('test uiw-jpeg', () => { const jpegPath = path.join(__dirname, 'imgs', 'uiw-jpeg'); const uri = image2uri(jpegPath); const ext = path.extname(jpegPath) as ExtType; expect(typeof uri).toBe('string'); // @ts-ignore expect(uri.indexOf('data:image')).toEqual(-1); }); it('test uiw.jpg', () => { const jpgPath = path.join(__dirname, 'imgs', 'uiw.jpg'); const uri = image2uri(jpgPath); const ext = path.extname(jpgPath) as ExtType; // @ts-ignore expect(extTypeMap[ext]).toEqual(uri.replace(/^data:(.*);base64\,.+/, "$1")); }); it('test uiw.png', () => { const pngPath = path.join(__dirname, 'imgs', 'uiw.png'); const uri = image2uri(pngPath); const ext = path.extname(pngPath) as ExtType; expect(typeof uri).toBe('string'); // @ts-ignore expect(extTypeMap[ext]).toEqual(uri.replace(/^data:(.*);base64\,.+/, "$1")); }); it('test uiw.svg', () => { const svgPath = path.join(__dirname, 'imgs', 'uiw.svg'); const uri = image2uri(svgPath); const ext = path.extname(svgPath) as ExtType; // @ts-ignore expect(extTypeMap[ext]).toEqual(uri.replace(/^data:(.*);base64\,.+/, "$1")); }); it('test uiw.webp', () => { const webpPath = path.join(__dirname, 'imgs', 'uiw.webp'); const uri = image2uri(webpPath); const ext = path.extname(webpPath) as ExtType; expect(typeof uri).toBe('string'); // @ts-ignore expect(extTypeMap[ext]).toEqual(uri.replace(/^data:(.*);base64\,.+/, "$1")); }); it('test https....', async () => { const uri = await image2uri('https://avatars.githubusercontent.com/u/1680273?v=4', { ext: '.apng' }); expect(uri.indexOf('data:image/apng;base64')).toEqual(0); }); jaywcjlove-image2uri-25bcf98/tsconfig.json000066400000000000000000000010561453100576100207100ustar00rootroot00000000000000{ "compilerOptions": { "target": "ESNext", "module": "ESNext", "moduleResolution": "node", "sourceMap": true, "declaration": true, "allowSyntheticDefaultImports": true, "noFallthroughCasesInSwitch": true, "noImplicitThis": true, "strictBindCallApply": true, "strictNullChecks": true, "strictPropertyInitialization": true, "stripInternal": true, "skipLibCheck": true, "esModuleInterop": false, "noImplicitAny": true, "outDir": "lib", "baseUrl": "." }, "include": [ "src/**/*" ] }