Completed
Push — master ( 61d444...b3f358 )
by Jan
16s queued 14s
created

src/frames/frame-uslt.ts   A

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 35
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 25
mnd 2
bc 2
fnc 0
dl 0
loc 35
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import { FrameBuilder } from "../FrameBuilder"
2
import { FrameReader } from "../FrameReader"
3
import { isString } from '../util'
4
import type { Data } from "./type"
5
6
export const USLT = {
7
    create: (data: Data) => {
8
        data = data || {}
9
        if(isString(data)) {
10
            data = {
11
                text: data
12
            }
13
        }
14
        if(!data.text) {
15
            return null
16
        }
17
18
        return new FrameBuilder("USLT")
19
            .appendNumber(0x01, 1)
20
            .appendValue(data.language)
21
            .appendNullTerminatedValue(data.shortText, 0x01)
22
            .appendValue(data.text, null, 0x01)
23
            .getBuffer()
24
    },
25
    read: (buffer: Buffer) => {
26
        const reader = new FrameReader(buffer, 0)
27
28
        return {
29
            language: reader.consumeStaticValue('string', 3, 0x00),
30
            shortText: reader.consumeNullTerminatedValue('string'),
31
            text: reader.consumeStaticValue('string', null)
32
        }
33
    }
34
}
35