Skip to content

Commit

Permalink
chore: add config color
Browse files Browse the repository at this point in the history
  • Loading branch information
hunghg255 committed Dec 11, 2023
1 parent 0fe3354 commit 7534280
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hqr",
"type": "module",
"version": "0.0.8",
"version": "0.0.9",
"description": "Generate QR Code universally, in any runtime, to ANSI, Unicode or SVG.",
"license": "MIT",
"homepage": "https://github.com/hunghg255/hqr#readme",
Expand Down Expand Up @@ -40,7 +40,6 @@
"build": "unbuild",
"dev": "unbuild --stub",
"lint": "eslint .",
"prepublishOnly": "nr build",
"release": "bumpp && npm publish",
"play": "esno play/run.ts",
"test": "vitest",
Expand Down
8 changes: 3 additions & 5 deletions src/base64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ function hex2rgba(hex: any) {
}
}

function getOptions(options: any) {
function getOptions(options: QrCodeGenerateImageOptions) {
if (!options)
options = {}
if (!options.color)
options.color = {}

const width = options.width && options.width >= 21 ? options.width : undefined
const scale = options.scale || 4
Expand All @@ -49,8 +47,8 @@ function getOptions(options: any) {
width,
scale: width ? 4 : scale,
color: {
dark: hex2rgba('#000000ff'),
light: hex2rgba('#ffffffff'),
dark: hex2rgba(options?.blackColor ?? '#000'),
light: hex2rgba('#fff'),
},
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,10 @@ export interface QrCodeGenerateImageOptions extends QrCodeGenerateOptions {
width?: number
height?: number
scale?: number
/**
* Hex color of the white module
*
* @default '#000'
*/
blackColor?: string
}
4 changes: 2 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import { renderUnicode, renderUnicodeCompact } from '../src/render'
import { encode, renderSVG } from '../src'
import { encode, renderBase64, renderSVG } from '../src'

describe('should', () => {
it('generate', () => {
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('should', () => {
expect(svg).toMatchFileSnapshot('./output/out1.svg')
})
it('render-base64', async () => {
// const base64 = await renderBase64('HUNG')
const base64 = await renderBase64('HUNG')

expect(base64).toEqual('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAklEQVR4AewaftIAAAKMSURBVO3BQY4bQQwEwSxi/v/ltI889aIxspYGGBH/Yo1RrFGKNUqxRinWKMUapVijFGuUhx8k4ZtUTpLQqXRJOFHpkvBNKifFGqVYoxRrlIdLKp+UhDeScKJyQ+WTknCjWKMUa5RijfLwUhJuqNxIwolKl4QuCZ3KjSTcUHmjWKMUa5RijfIwnEqXhBsq/5NijVKsUYo1ysN/RqVLQqfSJaFTmaxYoxRrlGKN8vCSym9S+ZdUvqlYoxRrlGKN8nApCd+UhE6lS0Kn8kYSflOxRinWKMUa5eEHKpMkoVPpknBDZZJijVKsUYo1ysMPknBDpUvCv5SEE5UuCScqN5LQqbxRrFGKNUqxRnn4gcobKjeS8IbKiUqXhBtJuJGETuWkWKMUa5RijfJwKQn/kkqXhE6lS8JJEjqVTuUkCZ1Kl4QTlRvFGqVYoxRrlPgXLyShUzlJQqfSJeFE5ZOS0KmcJKFT+aRijVKsUYo1ysOlJHQqN1S6JJyonCShU+mS0KncSMIbSehUToo1SrFGKdYoD5dUPknlJAmdSqfSJaFT6ZLQqXRJ6FS+qVijFGuUYo3y8IMkfJPKSRI+KQmTFGuUYo1SrFEeLql8UhJuqJwkoUvCiUqXhC4JJypdEt4o1ijFGqVYozy8lIQbKm8koVM5UemS0CXhROUkCZ1Kl4QbxRqlWKMUa5SH4VRuqJyodEnoVN5IQqdyo1ijFGuUYo3yMFwSbqh0SehUOpWTJHQqncpJEjqVk2KNUqxRijXKw0sq36RyQ+UkCZ1Kp3KShE8q1ijFGqVYozxcSsJvSkKncpKETuVGEjqVE5UuCTeKNUqxRinWKPEv1hjFGqVYoxRrlGKNUqxRijVKsUb5AzIkEdnWdO42AAAAAElFTkSuQmCC')
})
Expand Down

0 comments on commit 7534280

Please sign in to comment.