@sequencemedia/music-library 1.1.3 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/app.mjs CHANGED
@@ -14,6 +14,10 @@ import {
14
14
  Command
15
15
  } from 'commander'
16
16
 
17
+ import {
18
+ DEFAULT_ERROR_MESSAGE
19
+ } from '#music-library/common'
20
+
17
21
  import * as watch from '#music-library/watch'
18
22
 
19
23
  const {
@@ -70,7 +74,9 @@ async function app () {
70
74
 
71
75
  process.kill(pid)
72
76
  }
73
- } catch ({ message }) {
77
+ } catch ({
78
+ message = DEFAULT_ERROR_MESSAGE
79
+ }) {
74
80
  const error = debug('@sequencemedia/music-library:process:error')
75
81
 
76
82
  error(message)
@@ -151,7 +157,9 @@ async function app () {
151
157
  }
152
158
  }
153
159
  }
154
- } catch ({ message }) {
160
+ } catch ({
161
+ message = DEFAULT_ERROR_MESSAGE
162
+ }) {
155
163
  const error = debug('@sequencemedia/music-library:error')
156
164
 
157
165
  error(message)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequencemedia/music-library",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "Watch Apple Music Library XML and parse to JSON, JS, ES, or M3U",
5
5
  "keywords": [
6
6
  "music",
@@ -43,7 +43,7 @@
43
43
  "start": "cross-env NODE_OPTIONS=\"--no-warnings\" NODE_ENV=production node ."
44
44
  },
45
45
  "dependencies": {
46
- "@sequencemedia/music-library-parser": "1.1.3",
46
+ "@sequencemedia/music-library-parser": "1.1.4",
47
47
  "chokidar": "^3.6.0",
48
48
  "commander": "^12.1.0",
49
49
  "cross-env": "^7.0.3",
@@ -54,8 +54,8 @@
54
54
  "devDependencies": {
55
55
  "@babel/core": "^7.25.2",
56
56
  "@babel/preset-env": "^7.25.4",
57
- "@sequencemedia/eslint-config-standard": "^0.0.51",
58
- "@sequencemedia/hooks": "^1.0.542",
57
+ "@sequencemedia/eslint-config-standard": "^0.0.53",
58
+ "@sequencemedia/hooks": "^1.0.544",
59
59
  "core-js": "^3.38.1",
60
60
  "eslint": "^9.9.1",
61
61
  "globals": "^15.9.0",
@@ -64,6 +64,7 @@
64
64
  "imports": {
65
65
  "#music-library": "./src/index.mjs",
66
66
  "#music-library/*": "./src/*/index.mjs",
67
- "#music-library/common/normalise": "./src/common/normalise.mjs"
67
+ "#music-library/common": "./src/common/index.mjs",
68
+ "#music-library/common/*": "./src/common/*.mjs"
68
69
  }
69
70
  }
@@ -0,0 +1,9 @@
1
+ import debug from 'debug'
2
+
3
+ const log = debug('@sequencemedia/music-library')
4
+
5
+ export const DEFAULT_ERROR_MESSAGE = 'No error message defined'
6
+
7
+ export function DEFAULT_FUNC () {
8
+ log('DEFAULT_FUNC')
9
+ }
@@ -6,6 +6,8 @@ import {
6
6
  resolve
7
7
  } from 'path'
8
8
 
9
- const normalise = (p = '') => resolve(String(p).trim().replace(/^~/, homedir()))
10
-
11
- export default normalise
9
+ export default function normalise (p = '') {
10
+ return (
11
+ resolve(String(p).trim().replace(/^~/, homedir()))
12
+ )
13
+ }
@@ -2,6 +2,10 @@ import debug from 'debug'
2
2
 
3
3
  import musicLibraryParser from '@sequencemedia/music-library-parser'
4
4
 
5
+ import {
6
+ DEFAULT_ERROR_MESSAGE
7
+ } from '#music-library/common'
8
+
5
9
  import normalise from '#music-library/common/normalise'
6
10
 
7
11
  const {
@@ -15,6 +19,12 @@ const error = debug('@sequencemedia/music-library:error')
15
19
 
16
20
  log('`music-library` is awake')
17
21
 
22
+ function handleError ({
23
+ message = DEFAULT_ERROR_MESSAGE
24
+ } = {}) {
25
+ error(message)
26
+ }
27
+
18
28
  export async function toM3U (jar, xml, destination) {
19
29
  try {
20
30
  const j = jar
@@ -32,8 +42,8 @@ export async function toM3U (jar, xml, destination) {
32
42
  return (
33
43
  await parseToM3U(j, x, d)
34
44
  )
35
- } catch ({ message }) {
36
- error(message)
45
+ } catch (e) {
46
+ handleError(e)
37
47
  }
38
48
  }
39
49
 
@@ -2,6 +2,10 @@ import debug from 'debug'
2
2
 
3
3
  import musicLibraryParser from '@sequencemedia/music-library-parser'
4
4
 
5
+ import {
6
+ DEFAULT_ERROR_MESSAGE
7
+ } from '#music-library/common'
8
+
5
9
  import normalise from '#music-library/common/normalise'
6
10
 
7
11
  const {
@@ -17,6 +21,12 @@ const error = debug('@sequencemedia/music-library:error')
17
21
 
18
22
  log('`music-library` is awake')
19
23
 
24
+ function handleError ({
25
+ message = DEFAULT_ERROR_MESSAGE
26
+ } = {}) {
27
+ error(message)
28
+ }
29
+
20
30
  export async function toM3U (jar, xml, destination) {
21
31
  try {
22
32
  const j = jar
@@ -34,8 +44,8 @@ export async function toM3U (jar, xml, destination) {
34
44
  return (
35
45
  await parseToM3U(j, x, d)
36
46
  )
37
- } catch ({ message }) {
38
- error(message)
47
+ } catch (e) {
48
+ handleError(e)
39
49
  }
40
50
  }
41
51
 
@@ -2,6 +2,10 @@ import debug from 'debug'
2
2
 
3
3
  import musicLibraryParser from '@sequencemedia/music-library-parser'
4
4
 
5
+ import {
6
+ DEFAULT_ERROR_MESSAGE
7
+ } from '#music-library/common'
8
+
5
9
  import normalise from '#music-library/common/normalise'
6
10
 
7
11
  const {
@@ -21,6 +25,12 @@ const error = debug('@sequencemedia/music-library:transform:error')
21
25
 
22
26
  log('`music-library` is awake')
23
27
 
28
+ function handleError ({
29
+ message = DEFAULT_ERROR_MESSAGE
30
+ } = {}) {
31
+ error(message)
32
+ }
33
+
24
34
  export async function toJSON (jar, xml) {
25
35
  try {
26
36
  const j = jar
@@ -34,8 +44,8 @@ export async function toJSON (jar, xml) {
34
44
  return (
35
45
  await transformToJSON(j, x)
36
46
  )
37
- } catch ({ message }) {
38
- error(message)
47
+ } catch (e) {
48
+ handleError(e)
39
49
  }
40
50
  }
41
51
 
@@ -52,8 +62,8 @@ export async function toJS (jar, xml) {
52
62
  return (
53
63
  await transformToJS(j, x)
54
64
  )
55
- } catch ({ message }) {
56
- error(message)
65
+ } catch (e) {
66
+ handleError(e)
57
67
  }
58
68
  }
59
69
 
@@ -70,7 +80,7 @@ export async function toES (jar, xml) {
70
80
  return (
71
81
  await transformToES(j, x)
72
82
  )
73
- } catch ({ message }) {
74
- error(message)
83
+ } catch (e) {
84
+ handleError(e)
75
85
  }
76
86
  }
@@ -2,6 +2,10 @@ import debug from 'debug'
2
2
 
3
3
  import musicLibraryParser from '@sequencemedia/music-library-parser'
4
4
 
5
+ import {
6
+ DEFAULT_ERROR_MESSAGE
7
+ } from '#music-library/common'
8
+
5
9
  import normalise from '#music-library/common/normalise'
6
10
 
7
11
  const {
@@ -17,6 +21,12 @@ const error = debug('@sequencemedia/music-library:error')
17
21
 
18
22
  log('`music-library` is awake')
19
23
 
24
+ function handleError ({
25
+ message = DEFAULT_ERROR_MESSAGE
26
+ } = {}) {
27
+ error(message)
28
+ }
29
+
20
30
  export async function toM3U (jar, xml, destination) {
21
31
  try {
22
32
  const j = jar
@@ -34,8 +44,8 @@ export async function toM3U (jar, xml, destination) {
34
44
  return (
35
45
  await parseToM3U(j, x, d)
36
46
  )
37
- } catch ({ message }) {
38
- error(message)
47
+ } catch (e) {
48
+ handleError(e)
39
49
  }
40
50
  }
41
51
 
@@ -2,6 +2,10 @@ import debug from 'debug'
2
2
 
3
3
  import musicLibraryParser from '@sequencemedia/music-library-parser'
4
4
 
5
+ import {
6
+ DEFAULT_ERROR_MESSAGE
7
+ } from '#music-library/common'
8
+
5
9
  import normalise from '#music-library/common/normalise'
6
10
 
7
11
  const {
@@ -21,6 +25,12 @@ const error = debug('@sequencemedia/music-library:transform:error')
21
25
 
22
26
  log('`music-library` is awake')
23
27
 
28
+ function handleError ({
29
+ message = DEFAULT_ERROR_MESSAGE
30
+ } = {}) {
31
+ error(message)
32
+ }
33
+
24
34
  export async function toJSON (jar, xml) {
25
35
  try {
26
36
  const j = jar
@@ -34,8 +44,8 @@ export async function toJSON (jar, xml) {
34
44
  return (
35
45
  await transformToJSON(j, x)
36
46
  )
37
- } catch ({ message }) {
38
- error(message)
47
+ } catch (e) {
48
+ handleError(e)
39
49
  }
40
50
  }
41
51
 
@@ -52,8 +62,8 @@ export async function toJS (jar, xml) {
52
62
  return (
53
63
  await transformToJS(j, x)
54
64
  )
55
- } catch ({ message }) {
56
- error(message)
65
+ } catch (e) {
66
+ handleError(e)
57
67
  }
58
68
  }
59
69
 
@@ -70,7 +80,7 @@ export async function toES (jar, xml) {
70
80
  return (
71
81
  await transformToES(j, x)
72
82
  )
73
- } catch ({ message }) {
74
- error(message)
83
+ } catch (e) {
84
+ handleError(e)
75
85
  }
76
86
  }
@@ -2,6 +2,10 @@ import debug from 'debug'
2
2
 
3
3
  import musicLibraryParser from '@sequencemedia/music-library-parser'
4
4
 
5
+ import {
6
+ DEFAULT_ERROR_MESSAGE
7
+ } from '#music-library/common'
8
+
5
9
  import normalise from '#music-library/common/normalise'
6
10
 
7
11
  const {
@@ -19,6 +23,12 @@ const error = debug('@sequencemedia/music-library:transform:error')
19
23
 
20
24
  log('`music-library` is awake')
21
25
 
26
+ function handleError ({
27
+ message = DEFAULT_ERROR_MESSAGE
28
+ } = {}) {
29
+ error(message)
30
+ }
31
+
22
32
  export async function toJSON (jar, xml) {
23
33
  try {
24
34
  const j = jar
@@ -32,8 +42,8 @@ export async function toJSON (jar, xml) {
32
42
  return (
33
43
  await transformToJSON(j, x)
34
44
  )
35
- } catch ({ message }) {
36
- error(message)
45
+ } catch (e) {
46
+ handleError(e)
37
47
  }
38
48
  }
39
49
 
@@ -50,8 +60,8 @@ export async function toJS (jar, xml) {
50
60
  return (
51
61
  await transformToJS(j, x)
52
62
  )
53
- } catch ({ message }) {
54
- error(message)
63
+ } catch (e) {
64
+ handleError(e)
55
65
  }
56
66
  }
57
67
 
@@ -68,7 +78,7 @@ export async function toES (jar, xml) {
68
78
  return (
69
79
  await transformToES(j, x)
70
80
  )
71
- } catch ({ message }) {
72
- error(message)
81
+ } catch (e) {
82
+ handleError(e)
73
83
  }
74
84
  }
@@ -4,6 +4,10 @@ import debug from 'debug'
4
4
 
5
5
  import musicLibraryParser from '@sequencemedia/music-library-parser'
6
6
 
7
+ import {
8
+ DEFAULT_ERROR_MESSAGE
9
+ } from '#music-library/common'
10
+
7
11
  import normalise from '#music-library/common/normalise'
8
12
 
9
13
  const {
@@ -17,6 +21,12 @@ const error = debug('@sequencemedia/music-library:library:error')
17
21
 
18
22
  log('`music-library` is awake')
19
23
 
24
+ function handleError ({
25
+ message = DEFAULT_ERROR_MESSAGE
26
+ } = {}) {
27
+ error(`Error in watcher. The message was "${message}"`)
28
+ }
29
+
20
30
  export function toM3U (jar, xml, destination) {
21
31
  const j = jar
22
32
  ? normalise(jar)
@@ -32,18 +42,20 @@ export function toM3U (jar, xml, destination) {
32
42
 
33
43
  return (
34
44
  chokidar.watch(x)
35
- .on('all', (t, p) => {
45
+ .on('all', function handleEvent (t, p) {
36
46
  log(`Event "${t}" for "${p}"`)
37
47
  })
38
- .on('ready', () => (
39
- parseToM3U(j, x, d)
40
- ))
41
- .on('change', () => (
42
- parseToM3U(j, x, d)
43
- ))
44
- .on('error', ({ message }) => {
45
- error(`Error in watcher: "${message}"`)
48
+ .on('ready', function handleReady () {
49
+ return (
50
+ parseToM3U(j, x, d)
51
+ )
52
+ })
53
+ .on('change', function handleChange () {
54
+ return (
55
+ parseToM3U(j, x, d)
56
+ )
46
57
  })
58
+ .on('error', handleError)
47
59
  )
48
60
  }
49
61
 
@@ -4,6 +4,10 @@ import debug from 'debug'
4
4
 
5
5
  import musicLibraryParser from '@sequencemedia/music-library-parser'
6
6
 
7
+ import {
8
+ DEFAULT_ERROR_MESSAGE
9
+ } from '#music-library/common'
10
+
7
11
  import normalise from '#music-library/common/normalise'
8
12
 
9
13
  const {
@@ -19,6 +23,12 @@ const error = debug('@sequencemedia/music-library:playlists:error')
19
23
 
20
24
  log('`music-library` is awake')
21
25
 
26
+ function handleError ({
27
+ message = DEFAULT_ERROR_MESSAGE
28
+ } = {}) {
29
+ error(`Error in watcher. The message was "${message}"`)
30
+ }
31
+
22
32
  export function toM3U (jar, xml, destination) {
23
33
  const j = jar
24
34
  ? normalise(jar)
@@ -34,18 +44,20 @@ export function toM3U (jar, xml, destination) {
34
44
 
35
45
  return (
36
46
  chokidar.watch(x)
37
- .on('all', (t, p) => {
47
+ .on('all', function handleEvent (t, p) {
38
48
  log(`Event "${t}" for "${p}"`)
39
49
  })
40
- .on('ready', () => (
41
- parseToM3U(j, x, d)
42
- ))
43
- .on('change', () => (
44
- parseToM3U(j, x, d)
45
- ))
46
- .on('error', ({ message }) => {
47
- error(`Error in watcher: "${message}"`)
50
+ .on('ready', function handleReady () {
51
+ return (
52
+ parseToM3U(j, x, d)
53
+ )
54
+ })
55
+ .on('change', function handleChange () {
56
+ return (
57
+ parseToM3U(j, x, d)
58
+ )
48
59
  })
60
+ .on('error', handleError)
49
61
  )
50
62
  }
51
63
 
@@ -4,6 +4,11 @@ import debug from 'debug'
4
4
 
5
5
  import musicLibraryParser from '@sequencemedia/music-library-parser'
6
6
 
7
+ import {
8
+ DEFAULT_ERROR_MESSAGE,
9
+ DEFAULT_FUNC
10
+ } from '#music-library/common'
11
+
7
12
  import normalise from '#music-library/common/normalise'
8
13
 
9
14
  const {
@@ -23,7 +28,13 @@ const error = debug('@sequencemedia/music-library:transform:error')
23
28
 
24
29
  log('`music-library` is awake')
25
30
 
26
- export function toJSON (jar, xml, func = () => {}) {
31
+ function handleError ({
32
+ message = DEFAULT_ERROR_MESSAGE
33
+ } = {}) {
34
+ error(`Error in watcher. The message was "${message}"`)
35
+ }
36
+
37
+ export function toJSON (jar, xml, func = DEFAULT_FUNC) {
27
38
  const j = jar
28
39
  ? normalise(jar)
29
40
  : jar
@@ -34,23 +45,21 @@ export function toJSON (jar, xml, func = () => {}) {
34
45
 
35
46
  return (
36
47
  chokidar.watch(x)
37
- .on('ready', async function ready () {
48
+ .on('ready', async function handleReady () {
38
49
  func(
39
50
  await transformToJSON(j, x)
40
51
  )
41
52
  })
42
- .on('change', async function change () {
53
+ .on('change', async function handleChange () {
43
54
  func(
44
55
  await transformToJSON(j, x)
45
56
  )
46
57
  })
47
- .on('error', ({ message }) => {
48
- error(`Error in watcher: "${message}"`)
49
- })
58
+ .on('error', handleError)
50
59
  )
51
60
  }
52
61
 
53
- export function toJS (jar, xml, func = () => {}) {
62
+ export function toJS (jar, xml, func = DEFAULT_FUNC) {
54
63
  const j = jar
55
64
  ? normalise(jar)
56
65
  : jar
@@ -61,23 +70,21 @@ export function toJS (jar, xml, func = () => {}) {
61
70
 
62
71
  return (
63
72
  chokidar.watch(x)
64
- .on('ready', async function ready () {
73
+ .on('ready', async function handleReady () {
65
74
  func(
66
75
  await transformToJS(j, x)
67
76
  )
68
77
  })
69
- .on('change', async function change () {
78
+ .on('change', async function handleChange () {
70
79
  func(
71
80
  await transformToJS(j, x)
72
81
  )
73
82
  })
74
- .on('error', ({ message }) => {
75
- error(`Error in watcher: "${message}"`)
76
- })
83
+ .on('error', handleError)
77
84
  )
78
85
  }
79
86
 
80
- export function toES (jar, xml, func = () => {}) {
87
+ export function toES (jar, xml, func = DEFAULT_FUNC) {
81
88
  const j = jar
82
89
  ? normalise(jar)
83
90
  : jar
@@ -88,18 +95,16 @@ export function toES (jar, xml, func = () => {}) {
88
95
 
89
96
  return (
90
97
  chokidar.watch(x)
91
- .on('ready', async function ready () {
98
+ .on('ready', async function handleReady () {
92
99
  func(
93
100
  await transformToES(j, x)
94
101
  )
95
102
  })
96
- .on('change', async function change () {
103
+ .on('change', async function handleChange () {
97
104
  func(
98
105
  await transformToES(j, x)
99
106
  )
100
107
  })
101
- .on('error', ({ message }) => {
102
- error(`Error in watcher: "${message}"`)
103
- })
108
+ .on('error', handleError)
104
109
  )
105
110
  }
@@ -4,6 +4,10 @@ import debug from 'debug'
4
4
 
5
5
  import musicLibraryParser from '@sequencemedia/music-library-parser'
6
6
 
7
+ import {
8
+ DEFAULT_ERROR_MESSAGE
9
+ } from '#music-library/common'
10
+
7
11
  import normalise from '#music-library/common/normalise'
8
12
 
9
13
  const {
@@ -19,6 +23,12 @@ const error = debug('@sequencemedia/music-library:tracks:error')
19
23
 
20
24
  log('`music-library` is awake')
21
25
 
26
+ function handleError ({
27
+ message = DEFAULT_ERROR_MESSAGE
28
+ } = {}) {
29
+ error(`Error in watcher. The message was "${message}"`)
30
+ }
31
+
22
32
  export function toM3U (jar, xml, destination) {
23
33
  const j = jar
24
34
  ? normalise(jar)
@@ -34,18 +44,20 @@ export function toM3U (jar, xml, destination) {
34
44
 
35
45
  return (
36
46
  chokidar.watch(x)
37
- .on('all', (t, p) => {
47
+ .on('all', function handleEvent (t, p) {
38
48
  log(`Event "${t}" for "${p}"`)
39
49
  })
40
- .on('ready', () => (
41
- parseToM3U(j, x, d)
42
- ))
43
- .on('change', () => (
44
- parseToM3U(j, x, d)
45
- ))
46
- .on('error', ({ message }) => {
47
- error(`Error in watcher: "${message}"`)
50
+ .on('ready', function handleReady () {
51
+ return (
52
+ parseToM3U(j, x, d)
53
+ )
54
+ })
55
+ .on('change', function handleChange () {
56
+ return (
57
+ parseToM3U(j, x, d)
58
+ )
48
59
  })
60
+ .on('error', handleError)
49
61
  )
50
62
  }
51
63
 
@@ -4,6 +4,11 @@ import debug from 'debug'
4
4
 
5
5
  import musicLibraryParser from '@sequencemedia/music-library-parser'
6
6
 
7
+ import {
8
+ DEFAULT_ERROR_MESSAGE,
9
+ DEFAULT_FUNC
10
+ } from '#music-library/common'
11
+
7
12
  import normalise from '#music-library/common/normalise'
8
13
 
9
14
  const {
@@ -23,7 +28,13 @@ const error = debug('@sequencemedia/music-library:transform:error')
23
28
 
24
29
  log('`music-library` is awake')
25
30
 
26
- export function toJSON (jar, xml, func = () => {}) {
31
+ function handleError ({
32
+ message = DEFAULT_ERROR_MESSAGE
33
+ } = {}) {
34
+ error(`Error in watcher. The message was "${message}"`)
35
+ }
36
+
37
+ export function toJSON (jar, xml, func = DEFAULT_FUNC) {
27
38
  const j = jar
28
39
  ? normalise(jar)
29
40
  : jar
@@ -34,23 +45,21 @@ export function toJSON (jar, xml, func = () => {}) {
34
45
 
35
46
  return (
36
47
  chokidar.watch(x)
37
- .on('ready', async function ready () {
48
+ .on('ready', async function handleReady () {
38
49
  func(
39
50
  await transformToJSON(j, x)
40
51
  )
41
52
  })
42
- .on('change', async function change () {
53
+ .on('change', async function handleChange () {
43
54
  func(
44
55
  await transformToJSON(j, x)
45
56
  )
46
57
  })
47
- .on('error', ({ message }) => {
48
- error(`Error in watcher: "${message}"`)
49
- })
58
+ .on('error', handleError)
50
59
  )
51
60
  }
52
61
 
53
- export function toJS (jar, xml, func = () => {}) {
62
+ export function toJS (jar, xml, func = DEFAULT_FUNC) {
54
63
  const j = jar
55
64
  ? normalise(jar)
56
65
  : jar
@@ -61,23 +70,21 @@ export function toJS (jar, xml, func = () => {}) {
61
70
 
62
71
  return (
63
72
  chokidar.watch(x)
64
- .on('ready', async function ready () {
73
+ .on('ready', async function handleReady () {
65
74
  func(
66
75
  await transformToJS(j, x)
67
76
  )
68
77
  })
69
- .on('change', async function change () {
78
+ .on('change', async function handleChange () {
70
79
  func(
71
80
  await transformToJS(j, x)
72
81
  )
73
82
  })
74
- .on('error', ({ message }) => {
75
- error(`Error in watcher: "${message}"`)
76
- })
83
+ .on('error', handleError)
77
84
  )
78
85
  }
79
86
 
80
- export function toES (jar, xml, func = () => {}) {
87
+ export function toES (jar, xml, func = DEFAULT_FUNC) {
81
88
  const j = jar
82
89
  ? normalise(jar)
83
90
  : jar
@@ -88,18 +95,16 @@ export function toES (jar, xml, func = () => {}) {
88
95
 
89
96
  return (
90
97
  chokidar.watch(x)
91
- .on('ready', async function ready () {
98
+ .on('ready', async function handleReady () {
92
99
  func(
93
100
  await transformToES(j, x)
94
101
  )
95
102
  })
96
- .on('change', async function change () {
103
+ .on('change', async function handleChange () {
97
104
  func(
98
105
  await transformToES(j, x)
99
106
  )
100
107
  })
101
- .on('error', ({ message }) => {
102
- error(`Error in watcher: "${message}"`)
103
- })
108
+ .on('error', handleError)
104
109
  )
105
110
  }
@@ -4,6 +4,11 @@ import debug from 'debug'
4
4
 
5
5
  import musicLibraryParser from '@sequencemedia/music-library-parser'
6
6
 
7
+ import {
8
+ DEFAULT_ERROR_MESSAGE,
9
+ DEFAULT_FUNC
10
+ } from '#music-library/common'
11
+
7
12
  import normalise from '#music-library/common/normalise'
8
13
 
9
14
  const {
@@ -21,7 +26,13 @@ const error = debug('@sequencemedia/music-library:transform:error')
21
26
 
22
27
  log('`music-library` is awake')
23
28
 
24
- export function toJSON (jar, xml, func = () => {}) {
29
+ function handleError ({
30
+ message = DEFAULT_ERROR_MESSAGE
31
+ } = {}) {
32
+ error(`Error in watcher. The message was "${message}"`)
33
+ }
34
+
35
+ export function toJSON (jar, xml, func = DEFAULT_FUNC) {
25
36
  const j = jar
26
37
  ? normalise(jar)
27
38
  : jar
@@ -32,23 +43,21 @@ export function toJSON (jar, xml, func = () => {}) {
32
43
 
33
44
  return (
34
45
  chokidar.watch(x)
35
- .on('ready', async function ready () {
46
+ .on('ready', async function handleReady () {
36
47
  func(
37
48
  await transformToJSON(j, x)
38
49
  )
39
50
  })
40
- .on('change', async function change () {
51
+ .on('change', async function handleChange () {
41
52
  func(
42
53
  await transformToJSON(j, x)
43
54
  )
44
55
  })
45
- .on('error', ({ message }) => {
46
- error(`Error in watcher: "${message}"`)
47
- })
56
+ .on('error', handleError)
48
57
  )
49
58
  }
50
59
 
51
- export function toJS (jar, xml, func = () => {}) {
60
+ export function toJS (jar, xml, func = DEFAULT_FUNC) {
52
61
  const j = jar
53
62
  ? normalise(jar)
54
63
  : jar
@@ -59,23 +68,21 @@ export function toJS (jar, xml, func = () => {}) {
59
68
 
60
69
  return (
61
70
  chokidar.watch(x)
62
- .on('ready', async function ready () {
71
+ .on('ready', async function handleReady () {
63
72
  func(
64
73
  await transformToJS(j, x)
65
74
  )
66
75
  })
67
- .on('change', async function change () {
76
+ .on('change', async function handleChange () {
68
77
  func(
69
78
  await transformToJS(j, x)
70
79
  )
71
80
  })
72
- .on('error', ({ message }) => {
73
- error(`Error in watcher: "${message}"`)
74
- })
81
+ .on('error', handleError)
75
82
  )
76
83
  }
77
84
 
78
- export function toES (jar, xml, func = () => {}) {
85
+ export function toES (jar, xml, func = DEFAULT_FUNC) {
79
86
  const j = jar
80
87
  ? normalise(jar)
81
88
  : jar
@@ -86,18 +93,16 @@ export function toES (jar, xml, func = () => {}) {
86
93
 
87
94
  return (
88
95
  chokidar.watch(x)
89
- .on('ready', async function ready () {
96
+ .on('ready', async function handleReady () {
90
97
  func(
91
98
  await transformToES(j, x)
92
99
  )
93
100
  })
94
- .on('change', async function change () {
101
+ .on('change', async function handleChange () {
95
102
  func(
96
103
  await transformToES(j, x)
97
104
  )
98
105
  })
99
- .on('error', ({ message }) => {
100
- error(`Error in watcher: "${message}"`)
101
- })
106
+ .on('error', handleError)
102
107
  )
103
108
  }