@hymnbook/abc 0.1.1 → 0.2.0
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/dist/index.cjs +4 -4
- package/dist/index.d.cts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +4 -4
- package/package.json +6 -5
- package/src/based.ts +10 -2
- package/src/parser.ts +13 -1
package/dist/index.cjs
CHANGED
|
@@ -381,10 +381,10 @@ var processAbcLyrics = (object) => {
|
|
|
381
381
|
)
|
|
382
382
|
);
|
|
383
383
|
};
|
|
384
|
-
var combineMelodyAndLyrics = (melody, lyrics) => {
|
|
384
|
+
var combineMelodyAndLyrics = (melody, lyrics, options = { trimLines: false }) => {
|
|
385
385
|
const song = new AbcSong();
|
|
386
386
|
const rawMelody = extractInfoFields(melody, song);
|
|
387
|
-
const melodyLines = rawMelody.replaceAll(/\n+/g, "\n").trim().split("\n");
|
|
387
|
+
const melodyLines = rawMelody.replaceAll(/\n+/g, "\n").trim().split("\n").map((it) => it.trim()).map((it) => options.trimLines ? it.replaceAll(/(^y+|y+$)*/gi, "").replaceAll(/ *y* *(\|+]*) *y* */gi, " $1 ").trim() : it);
|
|
388
388
|
const lyricLines = lyrics.replaceAll(/\n+/g, "\n").trim().split("\n");
|
|
389
389
|
const mixedMelody = [];
|
|
390
390
|
for (let i = 0; i < Math.max(melodyLines.length, lyricLines.length); i++) {
|
|
@@ -399,12 +399,12 @@ var getForVerse = (melody, verse) => melody.subMelodies.find((it) => (
|
|
|
399
399
|
// `.includes()` won't work due to the Realm data type of `verseUuids`.
|
|
400
400
|
it.verseUuids.some((it2) => it2 == verse.uuid)
|
|
401
401
|
));
|
|
402
|
-
var generateAbcForVerse = (verse, activeMelody) => {
|
|
402
|
+
var generateAbcForVerse = (verse, activeMelody, options = { trimLines: false }) => {
|
|
403
403
|
if (activeMelody === void 0) {
|
|
404
404
|
return "";
|
|
405
405
|
}
|
|
406
406
|
const melody = getForVerse(activeMelody, verse)?.melody || activeMelody.melody;
|
|
407
|
-
return combineMelodyAndLyrics(melody, verse.abcLyrics || "");
|
|
407
|
+
return combineMelodyAndLyrics(melody, verse.abcLyrics || "", options);
|
|
408
408
|
};
|
|
409
409
|
// Annotate the CommonJS export names for ESM import in node:
|
|
410
410
|
0 && (module.exports = {
|
package/dist/index.d.cts
CHANGED
|
@@ -264,8 +264,11 @@ declare const convertStringToAbcTune: (abc: string) => TuneObject;
|
|
|
264
264
|
* Combine multi line lyrics line with a multi line melody into a single ABC notation string.
|
|
265
265
|
* @param melody
|
|
266
266
|
* @param lyrics
|
|
267
|
+
* @param options
|
|
267
268
|
*/
|
|
268
|
-
declare const combineMelodyAndLyrics: (melody: string, lyrics: string
|
|
269
|
+
declare const combineMelodyAndLyrics: (melody: string, lyrics: string, options?: {
|
|
270
|
+
trimLines?: boolean;
|
|
271
|
+
}) => string;
|
|
269
272
|
|
|
270
273
|
type Verse = {
|
|
271
274
|
uuid: string;
|
|
@@ -281,7 +284,16 @@ type AbcMelody = {
|
|
|
281
284
|
};
|
|
282
285
|
|
|
283
286
|
declare const getForVerse: (melody: AbcMelody, verse: Verse) => AbcSubMelody | undefined;
|
|
284
|
-
|
|
287
|
+
/**
|
|
288
|
+
* Combine an ABC melody with the lyrics of a verse into a single ABC notation string.
|
|
289
|
+
*
|
|
290
|
+
* @param verse
|
|
291
|
+
* @param activeMelody - The active melody to use. The method returns an empty string if this is undefined.
|
|
292
|
+
* @param options { trimLines?: boolean } - Whether to trim `y` spacers from start/end of lines.
|
|
293
|
+
*/
|
|
294
|
+
declare const generateAbcForVerse: (verse: Verse, activeMelody?: AbcMelody, options?: {
|
|
295
|
+
trimLines?: boolean;
|
|
296
|
+
}) => string;
|
|
285
297
|
|
|
286
298
|
declare class ValidationError extends Error {
|
|
287
299
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -264,8 +264,11 @@ declare const convertStringToAbcTune: (abc: string) => TuneObject;
|
|
|
264
264
|
* Combine multi line lyrics line with a multi line melody into a single ABC notation string.
|
|
265
265
|
* @param melody
|
|
266
266
|
* @param lyrics
|
|
267
|
+
* @param options
|
|
267
268
|
*/
|
|
268
|
-
declare const combineMelodyAndLyrics: (melody: string, lyrics: string
|
|
269
|
+
declare const combineMelodyAndLyrics: (melody: string, lyrics: string, options?: {
|
|
270
|
+
trimLines?: boolean;
|
|
271
|
+
}) => string;
|
|
269
272
|
|
|
270
273
|
type Verse = {
|
|
271
274
|
uuid: string;
|
|
@@ -281,7 +284,16 @@ type AbcMelody = {
|
|
|
281
284
|
};
|
|
282
285
|
|
|
283
286
|
declare const getForVerse: (melody: AbcMelody, verse: Verse) => AbcSubMelody | undefined;
|
|
284
|
-
|
|
287
|
+
/**
|
|
288
|
+
* Combine an ABC melody with the lyrics of a verse into a single ABC notation string.
|
|
289
|
+
*
|
|
290
|
+
* @param verse
|
|
291
|
+
* @param activeMelody - The active melody to use. The method returns an empty string if this is undefined.
|
|
292
|
+
* @param options { trimLines?: boolean } - Whether to trim `y` spacers from start/end of lines.
|
|
293
|
+
*/
|
|
294
|
+
declare const generateAbcForVerse: (verse: Verse, activeMelody?: AbcMelody, options?: {
|
|
295
|
+
trimLines?: boolean;
|
|
296
|
+
}) => string;
|
|
285
297
|
|
|
286
298
|
declare class ValidationError extends Error {
|
|
287
299
|
}
|
package/dist/index.js
CHANGED
|
@@ -333,10 +333,10 @@ var processAbcLyrics = (object) => {
|
|
|
333
333
|
)
|
|
334
334
|
);
|
|
335
335
|
};
|
|
336
|
-
var combineMelodyAndLyrics = (melody, lyrics) => {
|
|
336
|
+
var combineMelodyAndLyrics = (melody, lyrics, options = { trimLines: false }) => {
|
|
337
337
|
const song = new AbcSong();
|
|
338
338
|
const rawMelody = extractInfoFields(melody, song);
|
|
339
|
-
const melodyLines = rawMelody.replaceAll(/\n+/g, "\n").trim().split("\n");
|
|
339
|
+
const melodyLines = rawMelody.replaceAll(/\n+/g, "\n").trim().split("\n").map((it) => it.trim()).map((it) => options.trimLines ? it.replaceAll(/(^y+|y+$)*/gi, "").replaceAll(/ *y* *(\|+]*) *y* */gi, " $1 ").trim() : it);
|
|
340
340
|
const lyricLines = lyrics.replaceAll(/\n+/g, "\n").trim().split("\n");
|
|
341
341
|
const mixedMelody = [];
|
|
342
342
|
for (let i = 0; i < Math.max(melodyLines.length, lyricLines.length); i++) {
|
|
@@ -351,12 +351,12 @@ var getForVerse = (melody, verse) => melody.subMelodies.find((it) => (
|
|
|
351
351
|
// `.includes()` won't work due to the Realm data type of `verseUuids`.
|
|
352
352
|
it.verseUuids.some((it2) => it2 == verse.uuid)
|
|
353
353
|
));
|
|
354
|
-
var generateAbcForVerse = (verse, activeMelody) => {
|
|
354
|
+
var generateAbcForVerse = (verse, activeMelody, options = { trimLines: false }) => {
|
|
355
355
|
if (activeMelody === void 0) {
|
|
356
356
|
return "";
|
|
357
357
|
}
|
|
358
358
|
const melody = getForVerse(activeMelody, verse)?.melody || activeMelody.melody;
|
|
359
|
-
return combineMelodyAndLyrics(melody, verse.abcLyrics || "");
|
|
359
|
+
return combineMelodyAndLyrics(melody, verse.abcLyrics || "", options);
|
|
360
360
|
};
|
|
361
361
|
export {
|
|
362
362
|
AbcSong,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hymnbook/abc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -9,10 +9,11 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"test": "node --experimental-vm-modules node_modules/.bin/jest",
|
|
11
11
|
"build": "tsup",
|
|
12
|
-
"
|
|
13
|
-
"publish
|
|
14
|
-
"publish-
|
|
15
|
-
"publish-
|
|
12
|
+
"link": "npm run build && rm -f /Users/samuel/workspace/js/hymnbook2/node_modules/@hymnbook/abc/dist/*; ln /Users/samuel/workspace/js/hymnbook-abc/dist/* /Users/samuel/workspace/js/hymnbook2/node_modules/@hymnbook/abc/dist/",
|
|
13
|
+
"build-publish": "npm run build && npm publish --access public",
|
|
14
|
+
"publish-patch": "npm run test && npm version patch && npm run build-publish",
|
|
15
|
+
"publish-minor": "npm run test && npm version minor && npm run build-publish",
|
|
16
|
+
"publish-major": "npm run test && npm version major && npm run build-publish"
|
|
16
17
|
},
|
|
17
18
|
"repository": {
|
|
18
19
|
"type": "git",
|
package/src/based.ts
CHANGED
|
@@ -7,13 +7,21 @@ export const getForVerse = (melody: AbcMelody, verse: Verse): AbcSubMelody | und
|
|
|
7
7
|
// `.includes()` won't work due to the Realm data type of `verseUuids`.
|
|
8
8
|
it.verseUuids.some(it => it == verse.uuid));
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Combine an ABC melody with the lyrics of a verse into a single ABC notation string.
|
|
12
|
+
*
|
|
13
|
+
* @param verse
|
|
14
|
+
* @param activeMelody - The active melody to use. The method returns an empty string if this is undefined.
|
|
15
|
+
* @param options { trimLines?: boolean } - Whether to trim `y` spacers from start/end of lines.
|
|
16
|
+
*/
|
|
10
17
|
export const generateAbcForVerse = (
|
|
11
18
|
verse: Verse,
|
|
12
|
-
activeMelody?: AbcMelody
|
|
19
|
+
activeMelody?: AbcMelody,
|
|
20
|
+
options: { trimLines?: boolean } = { trimLines: false },
|
|
13
21
|
): string => {
|
|
14
22
|
if (activeMelody === undefined) {
|
|
15
23
|
return "";
|
|
16
24
|
}
|
|
17
25
|
const melody = getForVerse(activeMelody, verse)?.melody || activeMelody.melody;
|
|
18
|
-
return combineMelodyAndLyrics(melody, verse.abcLyrics || "")
|
|
26
|
+
return combineMelodyAndLyrics(melody, verse.abcLyrics || "", options)
|
|
19
27
|
};
|
package/src/parser.ts
CHANGED
|
@@ -247,8 +247,13 @@ const processAbcLyrics = (object: Array<TuneObject>) => {
|
|
|
247
247
|
* Combine multi line lyrics line with a multi line melody into a single ABC notation string.
|
|
248
248
|
* @param melody
|
|
249
249
|
* @param lyrics
|
|
250
|
+
* @param options
|
|
250
251
|
*/
|
|
251
|
-
export const combineMelodyAndLyrics = (
|
|
252
|
+
export const combineMelodyAndLyrics = (
|
|
253
|
+
melody: string,
|
|
254
|
+
lyrics: string,
|
|
255
|
+
options: { trimLines?: boolean } = { trimLines: false },
|
|
256
|
+
): string => {
|
|
252
257
|
const song = new AbcSong();
|
|
253
258
|
const rawMelody = extractInfoFields(melody, song);
|
|
254
259
|
|
|
@@ -256,6 +261,13 @@ export const combineMelodyAndLyrics = (melody: string, lyrics: string): string =
|
|
|
256
261
|
.replaceAll(/\n+/g, "\n")
|
|
257
262
|
.trim()
|
|
258
263
|
.split("\n")
|
|
264
|
+
.map(it => it.trim())
|
|
265
|
+
.map(it => options.trimLines
|
|
266
|
+
? it
|
|
267
|
+
.replaceAll(/(^y+|y+$)*/gi, "")
|
|
268
|
+
.replaceAll(/ *y* *(\|+]*) *y* */gi, " $1 ")
|
|
269
|
+
.trim()
|
|
270
|
+
: it);
|
|
259
271
|
const lyricLines = lyrics
|
|
260
272
|
.replaceAll(/\n+/g, "\n")
|
|
261
273
|
.trim()
|