Best JavaScript code snippet using stryker-parent
chordpro.js
Source:chordpro.js
1module.exports = {2 fromString: function(input) {3 title = "";4 artist = "";5 lyrics = [];6 chords = [];7 chorddefinitions = [];8 lineNum = 0;9 sections = [];10 lines = input.split("\n");11 for (i = 0; i < lines.length; i++) {12 line = lines[i].trim();13 if (isaDirective(line)) {14 directive = parseDirective(line);15 if (directive.name == 'title') {16 title = directive.value;17 }18 if (directive.name == 'subtitle') {19 artist = directive.value;20 }21 if (directive.name == 'define') {22 chorddefinitions.push(parseDefinition(directive.value));23 }24 } else {25 if (i == lines.length-1 && !line) {26 // ignore last line if it's empty27 } else {28 lyric = parseLyric(line, lineNum);29 if ((lyric.text.startsWith("Verse") ||30 lyric.text.startsWith("Intro") ||31 lyric.text.startsWith("Outro") ||32 lyric.text.startsWith("Chorus") ||33 lyric.text.startsWith("Bridge")) && lyric.chords.length == 0) {34 if (sections.length > 0) {35 sections[sections.length-1].end = lineNum-1;36 }37 sections.push({ text:lyric.text , start:lineNum , end:0 });38 lyrics.push("");39 } else {40 lyrics.push(lyric.text);41 }42 lineNum++;43 for (c = 0; c < lyric.chords.length; c++) {44 chords.push(lyric.chords[c]);45 }46 }47 }48 }49 if (sections.length > 0) {50 sections[sections.length-1].end = lineNum-1;51 }52 return { title:title , artist:artist , lyrics:lyrics , chords:chords , chorddefs:chorddefinitions , sections:sections };53 },54 toString: function(song) {55 string = "";56 if (song.title != "") {57 string += "{t:" + song.title + "}\n";58 }59 if (song.artist != "") {60 string += "{st:" + song.artist + "}\n";61 }62 for (i = 0; i < song.chorddefs.length; i++) {63 string += "{define: " + song.chorddefs[i].name +64 " base-fret " + song.chorddefs[i].basefret.toString() +65 " frets ";66 for (f = 0; f < song.chorddefs[i].frets.length; f++) {67 if (song.chorddefs[i].frets[f] < 0) {68 string += "x";69 } else {70 string += song.chorddefs[i].frets[f].toString();71 }72 if (f < 5) {73 string += " ";74 }75 }76 string += "}\n"77 }78 var chordNum = 0;79 var sectionNum = 0;80 for (i = 0; i < song.lyrics.length; i++) {81 if (song.sections.length > 0 && song.lyrics[i].length == 0 && song.sections[sectionNum].start == i) {82 string += song.sections[sectionNum].text + "\n";83 if (sectionNum < song.sections.length-1) {84 sectionNum++;85 }86 } else {87 lastCol = 0;88 while (chordNum < song.chords.length && song.chords[chordNum].line == i) {89 string += song.lyrics[i].substring(lastCol, song.chords[chordNum].col) + "["+ song.chords[chordNum].name + "]";90 lastCol = song.chords[chordNum].col;91 chordNum++;92 }93 string += song.lyrics[i].substring(lastCol, song.lyrics[i].length) + "\n";94 }95 }96 return string;97 },98 distinctChords: function(song) {99 distinct = [];100 for (i = 0; i < song.chords.length; i++) {101 found = false;102 if (distinct.indexOf(song.chords[i].name) == -1) {103 distinct.push(song.chords[i].name);104 }105 }106 return distinct;107 },108 addDefs: function(song, defs, options) {109 if (defs.length == 0) {110 return song;111 }112 var hasDefine = defs[0].hasOwnProperty('define');113 // replace first114 if (options.replace) {115 for (i = 0; i < song.chorddefs.length; i++) {116 for (j = 0; j < defs.length; j++) {117 if (song.chorddefs[i].name == defs[j].name) {118 if (hasDefine) {119 define = defs[i].define.substring(8,defs[j].define.length);120 song.chorddefs[i] = parseDefinition(define);121 } else {122 song.chorddefs[i] = defs[j];123 }124 }125 }126 }127 }128 // then add the rest129 for (i = 0; i < defs.length; i++) {130 if (!hasDefinition(song.chorddefs, defs[i].name)) {131 if (hasDefine) {132 define = defs[i].define.substring(8,defs[i].define.length);133 song.chorddefs.push(parseDefinition(define));134 } else {135 song.chorddefs.push(defs[i]);136 }137 }138 }139 return song;140 },141 setChordSequence: function(song, sequence) {142 newChordDefs = [];143 for (i = 0; i < sequence.length; i++) {144 newChordDefs.push(getDefinition(song.chorddefs, sequence[i]));145 }146 song.chorddefs = newChordDefs;147 return song;148 },149 renameChord: function(song, from, to) {150 for (i = 0; i < song.chords.length; i++) {151 if (song.chords[i].name == from) {152 song.chords[i].name = to;153 }154 }155 for (i = 0; i < song.chorddefs.length; i++) {156 if (song.chorddefs[i].name == from) {157 song.chorddefs[i].name = to;158 }159 }160 return song;161 },162 getSection: function(song, id) {163 return getSongSection(song, id);164 },165 moveChord: function(song, from, to) {166 for(ci = 0; ci < song.chords.length; ci++) {167 if (from.line == song.chords[ci].line && from.col == song.chords[ci].col && from.name == song.chords[ci].name) {168 song.chords[ci].col = to.col;169 }170 }171 return song;172 },173 copyChords: function(song, section, toSectionId) {174 var newChords = [];175 for (i = 0; i < song.chords.length; i++) {176 if (song.chords[i].line < song.sections[toSectionId].start) {177 newChords.push(song.chords[i]);178 }179 }180 for (i = 0; i < section.chords.length; i++) {181 section.chords[i].line += (song.sections[toSectionId].start + 1);182 newChords.push(section.chords[i]);183 }184 for (i = 0; i < song.chords.length; i++) {185 if (song.chords[i].line > song.sections[toSectionId].end) {186 newChords.push(song.chords[i]);187 }188 }189 for (i = 0; i < song.chords.length; i++) {190 if (song.chords[i].line > song.sections[toSectionId].end) {191 newChords.push(song.chords[i]);192 }193 }194 song.chords = newChords;195 return song;196 }197};198function hasDefinition(chorddefs, name) {199 for (d = 0; d < chorddefs.length; d++) {200 if (chorddefs[d].name == name) {201 return true;202 }203 }204 return false;205}206function getDefinition(chorddefs, name) {207 for (d = 0; d < chorddefs.length; d++) {208 if (chorddefs[d].name == name) {209 return chorddefs[d];210 }211 }212 return {};213}214function parseDefinition(definition) {215 name = "";216 basefret = "";217 frets = [0,0,0,0,0,0];218 // {define: Am base-fret 0 frets x 0 2 2 1 0}219 var defineRegEx = /([^}]+)\sbase-fret\s([^}]+)\sfrets\s([^}]+)\s([^}]+)\s([^}]+)\s([^}]+)\s([^}]+)\s([^}]+)/;220 if (defineRegEx.test(definition)) {221 match = defineRegEx.exec(definition);222 name = match[1].trim();223 basefret = parseInt(match[2]);224 for (f = 0; f < frets.length; f++) {225 if (match[3+f] == 'x') {226 frets[f] = -1;227 } else {228 frets[f] = parseInt(match[3+f]);229 }230 }231 }232 return { name:name , basefret:basefret , frets:frets };233}234var directiveRegEx = /{([^}]+):([^}]+)}/;235function isaDirective(line) {236 return directiveRegEx.test(line);237}238function parseDirective(line) {239 var matches = directiveRegEx.exec(line);240 if (matches.length == 3) {241 if (matches[1] == 't') {242 matches[1] = 'title';243 }244 if (matches[1] == 'st') {245 matches[1] = 'subtitle';246 }247 return { name:matches[1] , value:matches[2] }248 }249 return {};250}251function getSongSection(song, id) {252 section = { title:"" , chords:[] , lyrics:[] };253 if (id >= 0 && id < song.sections.length) {254 section.title = sections[id].text;255 }256 for (li = sections[id].start+1; li <= sections[id].end; li++) {257 section.lyrics.push(song.lyrics[li]);258 }259 for(ci = 0; ci < song.chords.length; ci++) {260 if (song.sections[id].start <= song.chords[ci].line && song.chords[ci].line <= song.sections[id].end) {261 var newChord = { line:song.chords[ci].line , col:song.chords[ci].col , name:song.chords[ci].name };262 newChord.line -= (song.sections[id].start+1);263 section.chords.push(newChord);264 }265 }266 return section;267}268function parseLyric(line, lineNum) {269 lyric = "";270 isaChord = false;271 chord = "";272 linechords = [];273 col = 0;274 for (j=0; j < line.length; j++) {275 if (line[j] == '[') {276 isaChord = true;277 } else if (line[j] == ']') {278 isaChord = false;279 linechords.push({ name:chord , line:lineNum , col:col });280 chord = "";281 } else {282 if (isaChord) {283 chord += line[j];284 } else {285 col++;286 lyric += line[j];287 }288 }289 }290 return { text:lyric , chords:linechords };...
app.js
Source:app.js
...71 var length = songs.length - 1;72 id = length.toString();73 }74 }75 service.getSong(id)76 .success(function(song) {77 $scope.song = song;78 });79 });80 service.getFretboard()81 .success(function(fb) {82 $scope.fretboard = fb;83 $scope.newchordname = fb.chorddef.name;84 });85 }86 $scope.initSection = function() {87 var id = $routeParams.id;88 var sectionid = $routeParams.sectionid;89 service.getSection(id, sectionid)90 .success(function(section) {91 $scope.section = section;92 $scope.sectionid = sectionid;93 if ($scope.section.chords.length > 0) {94 $scope.from = $scope.section.chords[0];95 $scope.to = $scope.section.chords[0];96 }97 });98 service.getSong(id)99 .success(function(song) {100 $scope.song = song;101 });102 }103 $scope.changeSectionChord = function(chordId) {104 var ch = parseInt(chordId);105 $scope.from = $scope.section.chords[ch];106 $scope.to = $scope.section.chords[ch];107 $scope.confirmMoveChord();108 }109 $scope.moveChordRight = function() {110 $scope.to.col += 1;111 $scope.confirmMoveChord();112 }113 $scope.moveChordLeft = function() {114 $scope.to.col -= 1;115 $scope.confirmMoveChord();116 }117 $scope.updateSection = function() {118 service.updateSection($scope.section._id, {section:$scope.section}, $scope.sectionid)119 .success(function(song) {120 $scope.song = song;121 });122 }123 $scope.filterMutedStrings = function(note) {124 return note.mute;125 }126 $scope.filterExcludeMutedStrings = function(note) {127 return !note.mute;128 }129 $scope.filterBaseFretNotZero = function(chorddef) {130 return chorddef.basefret != 0;131 }132 $scope.updateSong = function() {133 service.updateSong({text:$scope.song.text}, $scope.song._id)134 .success(function(song) {135 $scope.song = song;136 });137 }138 $scope.copyChords = function() {139// service.copyChords({text:$scope.song.text}, $scope.song._id)140// .success(function(song) {141// $scope.song = song;142// });143 }144 $scope.editChord = function(chordId) {145 var ch = parseInt(chordId);146 if (ch >= 0 && ch < $scope.song.chorddefs.length) {147 service.updateFretboard($scope.song.chorddefs[ch])...
lyrics.js
Source:lyrics.js
1const axios = require('axios');2const LenoxCommand = require('../LenoxCommand.js');3const config = require('../../settings.json');4module.exports = class lyricsCommand extends LenoxCommand {5 constructor(client) {6 super(client, {7 name: 'lyrics',8 group: 'botowner',9 memberName: 'lyrics',10 description: 'Fetch lyrics for a given artist and song',11 format: 'lyrics {query}',12 aliases: [],13 examples: ['lyrics parkway drive - boneyards'],14 clientpermissions: ['SEND_MESSAGES', 'EMBED_LINKS'],15 userpermissions: [],16 shortDescription: 'Lyrics',17 dashboardsettings: false18 });19 }20 async run(msg) {21 const langSet = msg.client.provider.getGuild(msg.guild.id, 'language');22 const lang = require(`../../languages/${langSet}.json`);23 if (!config.owners.includes(msg.author.id)) return msg.channel.send(lang.botownercommands_error);24 const text_truncate = (str, length, ending) => {25 if (length === null) length = 100;26 if (ending === null) ending = '...';27 if (str.length > length) return str.substring(0, length - ending.length) + ending;28 return str;29 };30 const MESSAGE_CHAR_LIMIT = 2000;31 const splitString = (string, prepend = '', append = '') => {32 if (string.length <= MESSAGE_CHAR_LIMIT) return [string];33 const splitIndex = string.lastIndexOf('\n', MESSAGE_CHAR_LIMIT - prepend.length - append.length);34 const sliceEnd = splitIndex > 0 ? splitIndex : MESSAGE_CHAR_LIMIT - prepend.length - append.length;35 const rest = splitString(string.slice(sliceEnd), prepend, append);36 return [`${string.slice(0, sliceEnd)}${append}`, `${prepend}${rest[0]}`, ...rest.slice(1)];37 };38 const input = msg.content.split(' ');39 const searchString = input.slice(1).join(' ');40 if (!searchString) return msg.channel.send(lang.lyrics_nosongname);41 await axios({42 method: 'GET',43 url: `https://api.audd.io/findLyrics/?itunes_country=us&api_token=${config.auddKey}&q=${encodeURIComponent(searchString)}`,44 headers: {45 Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',46 'Content-Type': 'application/json; charset=utf-8'47 }48 }).then(async (res) => {49 if (!res.data.result.length) return msg.channel.send(`Couldn't find lyrics for the song \`${searchString}\`.`);50 const audd_song = res.data.result[0];51 const ksoft_res = await axios.get(`https://ksoft.derpyenterprises.org/lyrics?input=${encodeURIComponent(`${audd_song.artist} - ${audd_song.title}`)}`);52 if (ksoft_res.data.data.length) { // check to make sure ksoft returned a response (this response is used to add properties from ksoft to audd)53 const ksoft_song = ksoft_res.data.data[0];54 if (!audd_song.lyrics && ksoft_song.lyrics) { // make sure audd and ksoft returned lyrics55 audd_song.lyrics = ksoft_song.lyrics;56 }57 else if (!audd_song.lyrics && !ksoft_song.lyrics) { // if audd and ksoft didn't return lyrics then try to get them from makeitpersonal as a last resort58 try {59 const mip_lyrics = await axios.get(`https://makeitpersonal.co/lyrics?artist=${encodeURIComponent(audd_song.artist)}&title=${encodeURIComponent(audd_song.title)}`); // use this api if audd is down or can't find lyrics for a song. (it is rare for audd not to find lyrics for a song but just as a safety precaution.)60 audd_song.lyrics = mip_lyrics.data; // add the lyrics to the audd api (I like doing it this way so I won't have to check the api if it didn't find lyrics before having them sent.)61 }62 catch (e) { }63 }64 /* add properties from ksoft to audd */65 audd_song.album = ksoft_song.album;66 audd_song.album_ids = ksoft_song.album_ids;67 audd_song.album_year = ksoft_song.album_year;68 audd_song.album_art = ksoft_song.album_art;69 audd_song.artist_id = ksoft_song.artist_id;70 audd_song.search_str = ksoft_song.search_str;71 audd_song.popularity = ksoft_song.popularity;72 audd_song.id = ksoft_song.id;73 audd_song.search_score = ksoft_song.search_score;74 }75 audd_song.lyrics = audd_song.lyrics.replace(/^\n+/, '').replace(/\n{3,}/g, '\n\n').replace(/&/g, '&')76 .replace(/>/g, '>')77 .replace(/</g, '<')78 .replace(/"/g, '"')79 .replace(/Œ/g, 'Å')80 .replace(/œ/g, 'Å')81 .replace(/Š/g, 'Å ')82 .replace(/š/g, 'Å¡')83 .replace(/Ÿ/g, 'Ÿ')84 .replace(/ˆ/g, 'Ë')85 .replace(/˜/g, 'Ë')86 .replace(/–/g, 'â')87 .replace(/—/g, 'â')88 .replace(/‘/g, 'â')89 .replace(/’/g, 'â')90 .replace(/‚/g, 'â')91 .replace(/“/g, 'â')92 .replace(/”/g, 'â')93 .replace(/„/g, 'â')94 .replace(/†/g, 'â ')95 .replace(/‡/g, 'â¡')96 .replace(/‰/g, 'â°')97 .replace(/‹/g, 'â¹')98 .replace(/›/g, 'âº')99 .replace(/€/g, 'â¬')100 .replace(/©/g, '©')101 .replace(/™/g, 'â¢')102 .replace(/®/g, '®')103 .replace(/ /g, ' ');104 audd_song.lyrics = splitString(audd_song.lyrics);105 let pagenum = 1;106 audd_song.lyrics.forEach((page) => { // iterate through the pages107 msg.channel.send({108 embed: {109 description: page.toString() || 'N/A',110 thumbnail: {111 url: audd_song.album_art ? audd_song.album_art : undefined112 },113 timestamp: new Date(),114 color: 3447003,115 title: text_truncate(`${audd_song.album ? `[${audd_song.album}] ` : ''}${audd_song.artist} - ${audd_song.title}${audd_song.album_year ? ` (${audd_song.album_year})` : ''}`, 256),116 author: {117 name: text_truncate(audd_song.artist, 256) || 'N/A'118 },119 footer: {120 text: `${lang.lyrics_page} ${pagenum++ || 'N/A'}`121 }122 }123 });124 });125 }).catch((e) => console.error(e));126 }...
song.js
Source:song.js
...4var text2chordpro = require('../../lib/text2chordpro');5var router = require('express').Router();6var Song = require('../../lib/songinmem');7var songs = [];8function getSong(paramId) {9 for (i = 0; i < songs.length; i++) {10 if (songs[i]._id == paramId) {11 return songs[i];12 }13 }14 return null;15}16function parseSong(newText) {17 var song = {18 title: "", _id: "", artist: "",19 lyrics: [],20 chorddefs:[],21 chords: [],22 text: "",23 sections:[]24 };25 if (!text2chordpro.isChordpro(newText)) {26 newText = text2chordpro.fromText(newText);27 }28 song = chordpro.fromString(newText);29 chords = chordpro.distinctChords(song);30 defs = chorddefs.getdefs(chords);31 song = chordpro.addDefs(song, defs, { replace:false });32 for (s = 0; s < song.chorddefs.length; s++) {33 song.chorddefs[s].positions = fretboard.getFingerPositions(song.chorddefs[s]);34 }35 song.text = chordpro.toString(song);36 return song;37}38router.get('/:id',function(req,res,next) {39 var song = getSong(req.params.id);40 if (song == null) {41 Song.findById(req.params.id, function(err, dbSong) {42 if (err) {43 console.error(err);44 return next(err);45 }46 if (dbSong != null && dbSong.text != null) {47 song = parseSong(dbSong.text);48 songs.push(song);49 res.json(song);50 }51 });52 } else {53 res.json(song);54 }55});56router.get('/',function(req,res,next) {57 res.json(songs);58});59router.post('/',function(req,res,next) {60 var song = parseSong(req.body.text);61 song._id = songs.length.toString();62 songs.push(song);63 res.status(201).json(songs[songs.length-1]);64});65router.put('/:id',function(req,res,next) {66 var song = getSong(req.params.id);67 if (song != null) {68 var id = parseInt(song._id);69 if ( req.body.hasOwnProperty('chorddef') ) {70 song = chordpro.addDefs(song, req.body.chorddef, { replace:true });71 song = parseSong(chordpro.toString(song));72 }73 if ( req.body.hasOwnProperty('text') ) {74 song = parseSong(req.body.text);75 }76 song._id = req.params.id;77 songs[id] = song;78 res.status(200).json(song);79 }80});81router.put('/:id/chords/:chordid',function(req,res,next) {82 var song = getSong(req.params.id);83 if (song != null) {84 var id = parseInt(song._id);85 if (req.params.chordid >= 0 && req.params.chordid < song.chords.length) {86 if ( req.body.hasOwnProperty('name') ) {87 song = chordpro.renameChord(song, song.chords[req.params.chordid].name, req.body.name);88 }89 if ( req.body.hasOwnProperty('col') ) {90 var col = parseInt(req.body.col);91 var to = { name:song.chords[req.params.chordid].name , line:song.chords[req.params.chordid].line , col:col };92 song = chordpro.moveChord(song, song.chords[req.params.chordid], to);93 }94 song._id = req.params.id;95 songs[id] = song;96 }97 res.status(200).json(song);98 }99});100router.get('/:id/sections/:sectionid',function(req,res,next) {101 var song = getSong(req.params.id);102 var section = { title:"" , chords:[] , lyrics:[] , _id:''};103 if (song != null) {104 section = chordpro.getSection(song, req.params.sectionid);105 section._id = req.params.id;106 }107 res.json(section);108});109router.put('/:id/sections/:sectionid',function(req,res,next) {110 var song = getSong(req.params.id);111 if (song != null) {112 var id = parseInt(song._id);113 if (req.params.sectionid >= 0 && req.params.sectionid < song.sections.length) {114 if ( req.body.hasOwnProperty('section') ) {115 song = chordpro.copyChords(song, req.body.section, req.params.sectionid);116 }117 song._id = req.params.id;118 songs[id] = song;119 }120 res.status(200).json(song);121 }122});...
script.js
Source:script.js
...11const songs = ['hey', 'summer', 'ukulele'];12// Keep track of song13let songIndex = 2;14// Initially load song details into DOM15loadSong(songs[songIndex]);16// Update song details17function loadSong(song) {18 title.innerText = song;19 audio.src = `music/${song}.mp3`;20 cover.src = `images/${song}.jpg`;21}22// Play song23function playSong() {24 musicContainer.classList.add('play');25 playBtn.querySelector('i.fas').classList.remove('fa-play');26 playBtn.querySelector('i.fas').classList.add('fa-pause');27 audio.play();28}29// Pause song30function pauseSong() {31 musicContainer.classList.remove('play');32 playBtn.querySelector('i.fas').classList.add('fa-play');33 playBtn.querySelector('i.fas').classList.remove('fa-pause');34 audio.pause();35}36// Previous song37function prevSong() {38 songIndex--;39 if (songIndex < 0) {40 songIndex = songs.length - 1;41 }42 loadSong(songs[songIndex]);43 playSong();44}45// Next song46function nextSong() {47 songIndex++;48 if (songIndex > songs.length - 1) {49 songIndex = 0;50 }51 loadSong(songs[songIndex]);52 playSong();53}54// Update progress bar55function updateProgress(e) {56 const { duration, currentTime } = e.srcElement;57 const progressPercent = (currentTime / duration) * 100;58 progress.style.width = `${progressPercent}%`;59}60// Set progress bar61function setProgress(e) {62console.log(this);63 const width = this.clientWidth;64 console.log(width);65 console.log(this.width);66 const clickX = e.offsetX;67 const duration = audio.duration;68 audio.currentTime = (clickX / width) * duration;69}70// Event listeners71playBtn.addEventListener('click', () => {72 const isPlaying = musicContainer.classList.contains('play');73 if (isPlaying) {74 pauseSong();75 } else {76 playSong();77 }78});79// Change song80prevBtn.addEventListener('click', prevSong);81nextBtn.addEventListener('click', nextSong);82// Time/song update83audio.addEventListener('timeupdate', updateProgress);84// Click on progress bar85progressContainer.addEventListener('click', setProgress);86// Song ends...
SongContainer.js
Source:SongContainer.js
1import React, { Component } from 'react';2import PropTypes from 'prop-types';3import { connect } from 'react-redux';4import Song from './Song';5import { isSongIdPlaying, getListenerCount } from './song.selector';6import { playSongId, pauseSongId } from './song.actions';7class SongContainer extends Component {8 static propTypes = {9 data: PropTypes.shape({10 id: PropTypes.string.isRequired,11 title: PropTypes.string.isRequired,12 singer: PropTypes.string.isRequired,13 art: PropTypes.string.isRequired,14 }).isRequired,15 isSongIdPlaying: PropTypes.func.isRequired,16 playSongId: PropTypes.func.isRequired,17 pauseSongId: PropTypes.func.isRequired,18 getListenerCount: PropTypes.func.isRequired,19 };20 constructor(props) {21 super(props);22 this.audio = new Audio();23 // setting preload to none as we don't want to pre-download all the songs on the page24 this.audio.preload = 'none';25 const url = `${process.env.REACT_APP_API_HOST}/song/${props.data.id}.mp3`;26 this.audio.src = url;27 // call pause when the audio ends28 this.audio.onended = this.onPlayPauseClick;29 }30 componentWillReceiveProps(nextProps) {31 const { data: song } = nextProps;32 const isPlaying = nextProps.isSongIdPlaying(song.id);33 if (isPlaying) this.audio.play();34 else this.audio.pause();35 }36 onPlayPauseClick = () => {37 const { data: song } = this.props;38 const isPlaying = this.props.isSongIdPlaying(song.id);39 if (isPlaying) this.props.pauseSongId(song.id);40 else this.props.playSongId(song.id);41 };42 render() {43 const { data: song } = this.props;44 const isPlaying = this.props.isSongIdPlaying(song.id);45 const listenerCount = this.props.getListenerCount(song.id);46 return <Song data={song} onClick={this.onPlayPauseClick} isPlaying={isPlaying} listenerCount={listenerCount} />;47 }48}49const mapStateToProps = state => ({50 isSongIdPlaying: isSongIdPlaying(state),51 getListenerCount: getListenerCount(state),52});53const mapDispatchToProps = {54 playSongId,55 pauseSongId,56};...
songinmem.js
Source:songinmem.js
1var should = require('chai').should();2var Song = require('../lib/songinmem');3describe('#songinmem', function() {4 it("should save a song without error",function(done){5 var song = new Song({6 username:"guest",7 title: "title",8 artist: "artist",9 text: "{t:title}"10 })11 should.not.exist(song._id);12 song.save(function(err,theSong) {13 should.not.exist(err);14 should.exist(theSong._id);15 done();16 });17 });18 it("should find a saved song",function(done){19 var song = new Song({20 username:"guest2",21 title: "title2",22 artist: "artist2",23 text: "{t:title2}"24 })25 song.save(function(err,theSong) {26 should.exist(theSong._id);27 theSong.findById(theSong._id, function(err2, theSong2) {28 should.not.exist(err2);29 theSong2.title.should.equal("title2");30 done();31 });32 });33 });34 it("should return error finding an invalid id",function(done){35 var song = new Song({36 username:"",37 title: "",38 artist: "",39 text: ""40 })41 song.findById(267, function(err, song) {42 should.exist(err);43 done();44 });45 });46 it("should update a song",function(done){47 var song = new Song({48 username:"guest2",49 title: "title2",50 artist: "artist2",51 text: "{t:title2}"52 })53 song.save(function(err,theSong) {54 should.exist(theSong._id);55 theSong.findById(theSong._id, function(err2, theSong2) {56 should.not.exist(err2);57 theSong2.title.should.equal("title2");58 theSong2.title = "title3";59 theSong2.save(function(err,theSong) {60 should.exist(theSong._id);61 theSong.findById(theSong._id, function(err2, theSong2) {...
Library.jsx
Source:Library.jsx
1import LibrarySong from "./LibrarySong";2const Library = ({libraryStatus, songs, setSongs, currentSong, setCurrentSong, audioRef, isPlaying}) => {3 //! States:4 //! Event Handlers:5 //! Render:6 return (7 <div className={`library ${libraryStatus ? `library-active mobile-active` : ``}`}>8 <h2>Library</h2>9 <ul>10 {songs.map((song) => (11 <LibrarySong 12 active={song.active} //? This is the active state of the song13 artist={song.artist} //? This is the artist of the song14 audioRef={audioRef} //? This is the audioRef of the song15 cover={song.cover} //? This is the cover of the song16 currentSong={currentSong} //? This is the current song that is being passed in17 setCurrentSong={setCurrentSong} //? This is the function to change the current song to something else18 id={song.id} //? This is the id of the song19 isPlaying={isPlaying} //? This is the isPlaying state of the song20 key={song.id.toString()} //? This is a unique key for each song that React requires21 name={song.name} //? This is the name of the song22 song={song} //? This is the individual song and their information23 songs={songs} //? This is the array of songs that is being passed in24 setSongs={setSongs} //? This is the function that is being passed in25 />26 ))}27 </ul>28 </div>29 )30}...
Using AI Code Generation
1var Song = require('stryker-parent');2var song = new Song();3song.play();4var Song = require('stryker-parent');5var song = new Song();6song.play();7var Song = require('stryker-parent');8var song = new Song();9song.play();10var Song = require('stryker-parent');11var song = new Song();12song.play();13var Song = require('stryker-parent');14var song = new Song();15song.play();16var Song = require('stryker-parent');17var song = new Song();18song.play();19var Song = require('stryker-parent');20var song = new Song();21song.play();22var Song = require('stryker-parent');23var song = new Song();24song.play();25var Song = require('stryker-parent');26var song = new Song();27song.play();28var Song = require('stryker-parent');29var song = new Song();30song.play();31var Song = require('stryker-parent');32var song = new Song();33song.play();34var Song = require('stryker-parent');35var song = new Song();36song.play();37var Song = require('stryker-parent');38var song = new Song();39song.play();40var Song = require('stryker-parent');41var song = new Song();42song.play();
Using AI Code Generation
1const Song = require('stryker-parent');2const Song = require('stryker-child');3const Song = require('stryker-parent');4const Song = require('stryker-child');5const Song = require('stryker-parent');6const Song = require('stryker-child');7const Song = require('stryker-parent');8const Song = require('stryker-child');9const Song = require('stryker-parent');10const Song = require('stryker-child');11const Song = require('stryker-parent');12const Song = require('stryker-child');13const Song = require('stryker-parent');14const Song = require('stryker-child');15const Song = require('stryker-parent');16const Song = require('stryker-child');17const Song = require('stryker-parent');18const Song = require('stryker-child');19const Song = require('stryker-parent');20const Song = require('stryker-child');
Using AI Code Generation
1var Song = require('stryker-parent').Song;2var song = new Song('A', 'B');3song.play();4var Song = require('stryker-parent').Song;5var song = new Song('A', 'B');6song.play();7var Song = require('stryker-parent').Song;8var song = new Song('A', 'B');9song.play();10var Song = require('stryker-parent').Song;11var song = new Song('A', 'B');12song.play();13var Song = require('stryker-parent').Song;14var song = new Song('A', 'B');15song.play();16var Song = require('stryker-parent').Song;17var song = new Song('A', 'B');18song.play();19var Song = require('stryker-parent').Song;20var song = new Song('A', 'B');21song.play();22var Song = require('stryker-parent').Song;23var song = new Song('A', 'B');24song.play();25var Song = require('stryker-parent').Song;26var song = new Song('A', 'B');27song.play();28var Song = require('stryker-parent').Song;29var song = new Song('A', 'B');30song.play();31var Song = require('stryker-parent').Song;32var song = new Song('A', 'B');33song.play();34var Song = require('stryker-parent').Song;35var song = new Song('A', 'B');36song.play();
Using AI Code Generation
1var Song = require('stryker-parent');2var song = new Song('The best song ever');3console.log(song.toString());4{5 "dependencies": {6 }7}8module.exports = function(config) {9 config.set({10 });11};12var Song = require('stryker-parent');13var song = new Song('The best song ever');14console.log(song.toString());15module.exports = Song;16function Song(title) {17 this.title = title;18}19Song.prototype.toString = function() {20 return this.title;21};22module.exports = Song;23{24}
Using AI Code Generation
1const Song = require('stryker-parent').Song;2let song = new Song('Thriller', 'Michael Jackson', 1982);3console.log(song);4const Movie = require('stryker-parent').Movie;5let movie = new Movie('The Dark Knight', 2008);6console.log(movie);7const Book = require('stryker-parent').Book;8let book = new Book('The Lord of the Rings', 'J.R.R. Tolkien', 1954);9console.log(book);10const Game = require('stryker-parent').Game;11let game = new Game('The Legend of Zelda: Ocarina of Time', 1998);12console.log(game);13const Album = require('stryker-parent').Album;14let album = new Album('The Dark Side of the Moon', 'Pink Floyd', 1973);15console.log(album);16const Musician = require('stryker-parent').Musician;17let musician = new Musician('John Lennon');18console.log(musician);19const Artist = require('stryker-parent').Artist;20let artist = new Artist('Leonardo da Vinci');21console.log(artist);22const Actor = require('stryker-parent').Actor;23let actor = new Actor('Morgan Freeman');24console.log(actor);25const Director = require('stryker-parent').Director;26let director = new Director('Christopher Nolan');27console.log(director);28const Author = require('stryker-parent').Author;29let author = new Author('J.K. Rowling');30console.log(author);31const GameCreator = require('stryker-parent').GameCreator;32let gameCreator = new GameCreator('Shigeru Miyamoto');33console.log(gameCreator);34const GameConsole = require('stryker-parent').GameConsole;35let gameConsole = new GameConsole('Nintendo Switch');36console.log(gameConsole);
Using AI Code Generation
1const Song = require('stryker-parent-module').Song;2let song = new Song('Stairway To Heaven');3const Song = require('stryker-parent-module').Song;4let song = new Song('Stairway To Heaven');5const Song = require('stryker-parent-module').Song;6let song = new Song('Stairway To Heaven');7const Song = require('stryker-parent-module').Song;8let song = new Song('Stairway To Heaven');9const Song = require('stryker-parent-module').Song;10let song = new Song('Stairway To Heaven');11const Song = require('stryker-parent-module').Song;12let song = new Song('Stairway To Heaven');13const Song = require('stryker-parent-module').Song;14let song = new Song('Stairway To Heaven');15const Song = require('stryker-parent-module').Song;16let song = new Song('Stairway To
Using AI Code Generation
1var song = new Song();2var song = new ChildSong();3function Song() {4 this.name = "song";5}6Song.prototype.getName = function() {7 return this.name;8}9function ChildSong() {10 Song.call(this);11}12ChildSong.prototype = Object.create(Song.prototype);13ChildSong.prototype.constructor = ChildSong;14function ChildSong() {15 Song.call(this);16}17ChildSong.prototype = Object.create(Song.prototype);18ChildSong.prototype.constructor = ChildSong;
Using AI Code Generation
1var Song = require('stryker-parent').Song;2var song = new Song('Stryker', 'Stryker is awesome');3song.play();4var Song = function(name, lyrics){5 this.name = name;6 this.lyrics = lyrics;7};8Song.prototype.play = function(){9 console.log(this.lyrics);10};11module.exports = {12};13{14 "dependencies": {15 }16}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!