1.0.7 • Published 3 years ago
parse-base64-image v1.0.7
Parse Base64 Image
Parse base64 image from HTML rich text editor input.
Install
yarn add parse-base64-image
npm install parse-base64-image
Example
import fs from 'fs'
import path from 'path'
import ParseBase64Image from "parse-base64-image"
const HTMLInput = fs.readFileSync(path.join(__dirname, 'input.html'))
ParseBase64Image(HTMLInput.toString('utf-8'), path.join(__dirname, './'), '/').then(HTMLOutput => {
console.log(HTMLOutput)
})
Details
parse-base64-image can parse HTML input from rich text editor that contain base64 image
on the img tag. The rule is only if you put image from rich text editor, you need to make
sure that rich editor provide the data-filename dataset like
<img src="http://example.png" data-filename="example.png"/>
Test
Using yarn:
yarn test
or using npm:
npm run test
API
ParseBase64Image(HTMLContent: string, localPath: string, publicPath: string): Promise<string>
HTMLContent
: required. HTML input stringlocalPath
: required. Local path where is file will be savedpublicPath
: required. Public path that accessible from public url