Completed
Push — master ( d83c14...87c801 )
by Jan
16s queued 16s
created

src/api/update.ts   A

Complexity

Total Complexity 11
Complexity/F 2.2

Size

Lines of Code 53
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 45
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 11
mnd 6
bc 6
fnc 5
bpm 1.2
cpm 2.2
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B update.ts ➔ update 0 9 7
1
import { WriteTags } from "../types/Tags"
2
import { Options } from "../types/Options"
3
import { isFunction, isString } from "../util"
4
import { read } from "./read"
5
import { updateTags } from '../updateTags'
6
import { write, WriteCallback } from "./write"
7
8
/**
9
 * Update ID3-Tags from passed buffer/filepath
10
 */
11
 export function update(
12
    tags: WriteTags,
13
    buffer: Buffer,
14
    options?: Options
15
): Buffer
16
export function update(
17
    tags: WriteTags,
18
    filepath: string,
19
    options?: Options
20
): true | Error
21
export function update(
22
    tags: WriteTags,
23
    filebuffer: string | Buffer,
24
    callback: WriteCallback
25
): void
26
export function update(
27
    tags: WriteTags,
28
    filebuffer: string | Buffer,
29
    options: Options,
30
    callback: WriteCallback
31
): void
32
export function update(
33
    tags: WriteTags,
34
    filebuffer: string | Buffer,
35
    optionsOrCallback?: Options | WriteCallback,
36
    callback?: WriteCallback
37
): Buffer | true | Error | void {
38
    const options: Options =
39
        (isFunction(optionsOrCallback) ? {} : optionsOrCallback) ?? {}
40
    callback =
41
        isFunction(optionsOrCallback) ? optionsOrCallback : callback
42
43
    const currentTags = read(filebuffer, options)
44
    const updatedTags = updateTags(tags, currentTags)
45
    if (isFunction(callback)) {
46
        return write(updatedTags, filebuffer, callback)
47
    }
48
    if (isString(filebuffer)) {
49
        return write(updatedTags, filebuffer)
50
    }
51
    return write(updatedTags, filebuffer)
52
}
53