Skip to content

Commit

Permalink
Codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
ayrton committed Apr 25, 2024
1 parent 40b253f commit 378258e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SqlString from 'sqlstring'
import { cast, connect, format, hex, DatabaseError, type Cast } from '../dist/index'
import { connect, format, hex, DatabaseError, type Cast } from '../dist/index'
import { fetch, MockAgent, setGlobalDispatcher } from 'undici'
import packageJSON from '../package.json'

Expand Down
14 changes: 7 additions & 7 deletions __tests__/text.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { decodeUTF8, hex, uint8Array, uint8ArrayToHex } from '../src/text'
import { decodeUtf8, hex, uint8Array, uint8ArrayToHex } from '../src/text'

describe('text', () => {
describe('decode', () => {
describe('decodeUtf8', () => {
test('decodes ascii bytes', () => {
expect(decodeUTF8('a')).toEqual('a')
expect(decodeUtf8('a')).toEqual('a')
})

test('decodes empty string', () => {
expect(decodeUTF8('')).toEqual('')
expect(decodeUtf8('')).toEqual('')
})

test('decodes null value', () => {
expect(decodeUTF8(null)).toEqual('')
expect(decodeUtf8(null)).toEqual('')
})

test('decodes undefined value', () => {
expect(decodeUTF8(undefined)).toEqual('')
expect(decodeUtf8(undefined)).toEqual('')
})

test('decodes multi-byte characters', () => {
expect(decodeUTF8('\xF0\x9F\xA4\x94')).toEqual('🤔')
expect(decodeUtf8('\xF0\x9F\xA4\x94')).toEqual('🤔')
})
})

Expand Down
4 changes: 2 additions & 2 deletions src/cast.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Field } from './index.js'
import { decodeUTF8, uint8Array } from './text.js'
import { decodeUtf8, uint8Array } from './text.js'

/**
* https://github.com/vitessio/vitess/blame/v19.0.3/go/mysql/json/helpers.go#L86-L112
Expand Down Expand Up @@ -38,7 +38,7 @@ export function cast(field: Field, value: any): any {
return uint8Array(value)
}

return decodeUTF8(value)
return decodeUtf8(value)
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { cast } from './cast.js'
export { cast } from './cast.js'
import { format } from './sanitization.js'
export { format } from './sanitization.js'
import { decodeUTF8, uint8Array } from './text.js'
export { hex } from './text.js'
import { Version } from './version.js'

Expand Down
2 changes: 1 addition & 1 deletion src/text.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const decoder = new TextDecoder('utf-8')

export function decodeUTF8(text: string | null | undefined): string {
export function decodeUtf8(text: string | null | undefined): string {
return text ? decoder.decode(uint8Array(text)) : ''
}

Expand Down

0 comments on commit 378258e

Please sign in to comment.