Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function saveSong() {
if (title.trim() == '') return setError('Invalid Title')
if (artist.trim() == '') return setError('Invalid Artist')
if (content.trim() == '') return setError('Invalid content')
let artistName = artist.trim()
let songTitle = title.trim()
let header =
`{title: ${songTitle}}\n` +
`{artist: ${artistName}}\n`
let chordPro: string
if (mode == 'CHORD_PRO') {
chordPro = header + content
} else {
const formatter = new ChordSheetJS.ChordProFormatter();
let chordSheetSong = new ChordSheetJS.ChordSheetParser({ preserveWhitespace: true }).parse(content)
chordPro = header + formatter.format(chordSheetSong)
}
let songId = props.navigation.getParam('id')
let artistDb: Artist | undefined = Artist.getByName(artistName)
if (artistDb == null) {
artistDb = Artist.create(artistName)
}
if (songId) {
Song.update(songId, artistDb, songTitle, chordPro)
} else {
let song = Song.create(artistDb, songTitle, chordPro)
songId = song.id
}
props.navigation.replace(ROUTES.SongView, { id: songId, title: songTitle })
}
importChordSheet(chordSheet) {
const song = new ChordSheetJS.ChordSheetParser().parse(chordSheet);
this.editor.value = new ChordSheetJS.ChordProFormatter().format(song);
this.onEditorChange();
}
const SongTransformer: FunctionComponent = (props) => {
let { showTabs = true, transposeDelta = 0, chordProSong, fontSize = 14 } = props
let htmlSong = ''
let song: Song
if (chordProSong != null) {
if (!showTabs) {
chordProSong = chordProSong.replace(/{sot}(.|\n|\r)*?{eot}\r?\n?/g, '')
}
song = new ChordSheetJS.ChordProParser().parse(chordProSong);
} else {
song = new ChordSheetJS.ChordSheetParser({ preserveWhitespace: true }).parse(props.chordSheetSong!);
}
let transposedSong = song
if (transposeDelta != 0) {
transposedSong = transposeSong(song, transposeDelta);
}
let allChords = getChords(transposedSong)
htmlSong = new CustomHtmlDivFormatter().format(transposedSong, fontSize)
return props.children({ chords: allChords, htmlSong })
}
export default SongTransformer
export const convertChordSheetToChordPro = (chordSheet) => {
const parser = new ChordSheetJS.ChordSheetParser({ preserveWhitespace: false });
const formatter = new ChordSheetJS.ChordProFormatter();
const song = parser.parse(chordSheet);
return formatter.format(song);
};