[
  {
    "path": ".editorconfig",
    "content": "# http://editorconfig.org\nroot = true\n\n[*]\nindent_style = space\nindent_size = 4\nend_of_line = lf\ncharset = utf-8\ntrim_trailing_whitespace = true\ninsert_final_newline = true\n\n[*.md]\ntrim_trailing_whitespace = false\n"
  },
  {
    "path": ".github/FUNDING.yml",
    "content": "# These are supported funding model platforms\n\ngithub: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]\npatreon: # Replace with a single Patreon username\nopen_collective: # Replace with a single Open Collective username\nko_fi: # Replace with a single Ko-fi username\ntidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel\ncommunity_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry\nliberapay: # Replace with a single Liberapay username\nissuehunt: # Replace with a single IssueHunt username\notechie: # Replace with a single Otechie username\ncustom: https://www.buymeacoffee.com/renanbastos93\n"
  },
  {
    "path": ".github/dependabot.yml",
    "content": "version: 2\nupdates:\n\n  # Maintain dependencies for GitHub Actions\n  - package-ecosystem: \"github-actions\"\n    directory: \"/\"\n    schedule:\n      interval: \"daily\"\n\n  # Maintain dependencies for npm\n  - package-ecosystem: \"npm\"\n    directory: \"/\"\n    schedule:\n      interval: \"daily\"\n"
  },
  {
    "path": ".github/workflows/tests.yml",
    "content": "# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node\n# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions\n\nname: Tests\n\non:\n  pull_request:\n    types: [opened, synchronize]\n\njobs:\n  build:\n\n    runs-on: ubuntu-latest\n\n    strategy:\n      matrix:\n        node-version: [8.x, 10.x, 12.x]\n\n    steps:\n    - uses: actions/checkout@v2.3.4\n    - name: Use Node.js ${{ matrix.node-version }}\n      uses: actions/setup-node@v2.1.5\n      with:\n        node-version: ${{ matrix.node-version }}\n    - run: npm install -g mocha\n    - run: npm install\n    - run: npm test\n"
  },
  {
    "path": ".gitignore",
    "content": "# Logs\nlogs\n*.log\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\n\n# Runtime data\npids\n*.pid\n*.seed\n*.pid.lock\n\n# Directory for instrumented libs generated by jscoverage/JSCover\nlib-cov\n\n# Coverage directory used by tools like istanbul\ncoverage\n\n# nyc test coverage\n.nyc_output\n\n# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)\n.grunt\n\n# Bower dependency directory (https://bower.io/)\nbower_components\n\n# node-waf configuration\n.lock-wscript\n\n# Compiled binary addons (http://nodejs.org/api/addons.html)\nbuild/Release\n\n# Dependency directories\nnode_modules/\njspm_packages/\n\n# Typescript v1 declaration files\ntypings/\n\n# Optional npm cache directory\n.npm\n\n# Optional eslint cache\n.eslintcache\n\n# Optional REPL history\n.node_repl_history\n\n# Output of 'npm pack'\n*.tgz\n\n# Yarn Integrity file\n.yarn-integrity\n\n# dotenv environment variables file\n.env\n\n# package-lock.json from NPM\npackage-lock.json\nyarn.lock\n\n# macOS file\n.DS_Store\n*/**/.DS_Store\n"
  },
  {
    "path": ".npmrc",
    "content": "registry = https://registry.npmjs.org \nemail=renanbastos.tec@gmail.com"
  },
  {
    "path": ".travis.yml",
    "content": "language: node_js\nnode_js:\n  - \"9\"\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2017 RENAN.BASTOS\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# image-to-base64\nGenerate a base64 code from an image through a URL or a path.\n \n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Build Status](https://travis-ci.org/renanbastos93/image-to-base64.svg?branch=master)](https://travis-ci.org/renanbastos93/image-to-base64)\n![Tests](https://github.com/renanbastos93/image-to-base64/workflows/Tests/badge.svg)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/319a6e0b35474cf3ada5b0894e959b65)](https://www.codacy.com/app/renanbastos93/image-to-base64?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=renanbastos93/image-to-base64&amp;utm_campaign=Badge_Grade)\n<a href=\"https://www.npmjs.com/package/vue\"><img src=\"https://img.shields.io/npm/l/vue.svg\" alt=\"License\"></a>\n\n[npm-image]: https://img.shields.io/npm/v/image-to-base64.svg\n[npm-url]: https://npmjs.org/package/image-to-base64\n[downloads-image]: https://img.shields.io/npm/dm/image-to-base64.svg\n[downloads-url]: https://npmjs.org/package/image-to-base64\n\n## About\nIt's a thing you can use in many situations, for example you can just save the base64 string in your database and increment it in the front-end with the `<img>` tag in HTML.\n\n## Getting Started\nInstallation:\n```bash\nnpm i -S image-to-base64\n```\nCode Example:\n```js\nconst imageToBase64 = require('image-to-base64');\n//or\n//import imageToBase64 from 'image-to-base64/browser';\n\nimageToBase64(\"path/to/file.jpg\") // Path to the image\n    .then(\n        (response) => {\n            console.log(response); // \"cGF0aC90by9maWxlLmpwZw==\"\n        }\n    )\n    .catch(\n        (error) => {\n            console.log(error); // Logs an error if there was one\n        }\n    )\n```\nRemember that you can also use an image URL as a parameter.\n\nCode Example:\n```js\nimageToBase64(\"https://whatever-image/\") // Image URL\n    .then(\n        (response) => {\n            console.log(response); // \"iVBORw0KGgoAAAANSwCAIA...\"\n        }\n    )\n    .catch(\n        (error) => {\n            console.log(error); // Logs an error if there was one\n        }\n    )\n```\n\n#### Browser Usage\nYou can import image-to-base64 using the `<script>` tag in HTML.\n\nCode Example:\n```html\n<script src=\"node_modules/image-to-base64/image-to-base64.min.js\"></script>\n```\nNow you can use the module normally as in the JS examples above, but you can only use a URL and not a path. \n\n### LICENSE\n[MIT](https://opensource.org/licenses/MIT) © 2017 RENAN.BASTOS\n"
  },
  {
    "path": "browser.js",
    "content": "'use strict';\n(function(escope) {\n    function base64ToBrowser(buffer) {\n        return window.btoa([].slice.call(new Uint8Array(buffer)).map(function(bin) { return String.fromCharCode(bin); }).join(''));\n    }\n\n    function imageToBase64Browser(urlOrImage, param) {\n        if (!('fetch' in window && 'Promise' in window)) {\n            return Promise.reject('[*] image-to-base64 is not compatible with your browser.');\n        }\n        return fetch(urlOrImage, param || {}).then(function(response) {\n            return response.arrayBuffer();\n        }).then(base64ToBrowser);\n    }\n\n    if (typeof module !== 'undefined') {\n        module.exports = imageToBase64Browser;\n    } else {\n        escope.imageToBase64 = imageToBase64Browser;\n    }\n})(this);\n"
  },
  {
    "path": "image-to-base64.js",
    "content": "'use strict';\n\nvar fileSystem = require('fs');\nvar path = require('path');\nvar fetch = require('node-fetch');\n\nfunction validUrl(url) {\n    return /http(s)?:\\/\\/(\\w+:?\\w*@)?(\\S+)(:\\d+)?((?<=\\.)\\w+)+(\\/([\\w#!:.?+=&%@!\\-/])*)?/gi.test(url);\n}\n\nfunction validTypeImage(image) {\n    return /(?<=\\S+)\\.(jpg|png|jpeg)/gi.test(image);\n}\n\nfunction base64ToNode(buffer) {\n    return buffer.toString('base64');\n}\n\nfunction readFileAndConvert(fileName) {\n    if (fileSystem.statSync(fileName).isFile()) {\n        return base64ToNode(fileSystem.readFileSync(path.resolve(fileName)).toString('base64'));\n    }\n    return null;\n}\n\nfunction isImage(urlOrImage) {\n    if (validTypeImage(urlOrImage)) {\n        return Promise.resolve(readFileAndConvert(urlOrImage));\n    } else {\n        return Promise.reject('[*] An error occured: Invalid image [validTypeImage === false]');\n    }\n}\n\nfunction imageToBase64(urlOrImage) {\n    if (validUrl(urlOrImage)) {\n        return fetch(urlOrImage).then(function (response) {\n            return response.buffer();\n        }).then(base64ToNode);\n    } else {\n        return isImage(urlOrImage);\n    }\n}\n\nmodule.exports = imageToBase64;\n"
  },
  {
    "path": "package.json",
    "content": "{\n    \"name\": \"image-to-base64\",\n    \"version\": \"2.2.0\",\n    \"description\": \"Generate a image to base64.\",\n    \"main\": \"image-to-base64.min.js\",\n    \"scripts\": {\n        \"minify:base\": \"uglifyjs image-to-base64.js -c -m -o image-to-base64.min.js\",\n        \"minify:browser\": \"uglifyjs browser.js -c -m -o browser.min.js\",\n        \"minify\": \"npm run minify:base && npm run minify:browser\",\n        \"test\": \"mocha ./test\"\n    },\n    \"repository\": {\n        \"type\": \"git\",\n        \"url\": \"git+https://github.com/renanbastos93/image-to-base64.git\"\n    },\n    \"keywords\": [\n        \"node\",\n        \"nodejs\",\n        \"module convert base64 nodejs\",\n        \"image2base64\",\n        \"image-to-base64\",\n        \"convert-image-base64\",\n        \"convert\",\n        \"save\",\n        \"code\",\n        \"base64\",\n        \"image\",\n        \"webpack\",\n        \"loader\",\n        \"img\",\n        \"src\",\n        \"img src\"\n    ],\n    \"author\": \"Renan Bastos - <renanbastos.tec@gmail.com>\",\n    \"license\": \"MIT\",\n    \"bugs\": {\n        \"url\": \"https://github.com/renanbastos93/image-to-base64/issues\"\n    },\n    \"homepage\": \"https://github.com/renanbastos93/image-to-base64#readme\",\n    \"dependencies\": {\n        \"node-fetch\": \"^2.6.0\"\n    },\n    \"devDependencies\": {\n        \"uglify-js\": \"^3.9.1\",\n        \"mocha\": \"^7.1.1\"\n    }\n}\n"
  },
  {
    "path": "test/index.js",
    "content": "const image2base64 = require(\"./../image-to-base64.js\");\nconst assert = require(\"assert\");\nconst pt = require(\"path\");\n\nlet url = \"https://jaystack.com/wp-content/uploads/2015/12/nodejs-logo-e1497443346889.png\";\nlet path = pt.resolve(\"test/nodejs.png\");\nlet validBase64 = new RegExp(\"^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{0,2}==)$\",\"gim\");\n\ndescribe(\"must to be resolved the promise\", function(){\n\n    it(\"get image of the url and convert to base64\", function(){\n        image2base64(url)\n        .then(\n            (data) => {\n                assert(validBase64.test(data), true);\n            }\n        )\n        .catch((err) => assert(err, true));\n    });\n\n    it(\"get image of the path and convert to base64\", function(){\n        image2base64(path)\n        .then(\n            (data) => {\n                assert(validBase64.test(data).test(data), true);\n            }\n        )\n        .catch((err) => assert(err, true));\n    });\n\n});\n"
  }
]