How to use intervalId method in testing-library-react-hooks

Best JavaScript code snippet using testing-library-react-hooks

Model.presets.ts

Source:Model.presets.ts Github

copy

Full Screen

1import ArrayUtils from "../general/Array.utils";2import { ChordId, IModelConfig, IntervalId, IPod, ModelId, ModelType, NoteId, ScaleId, Tag } from "./Model.constants";3import { getExtensionInversionId } from "./Pod.static";4// Helpers5const formatPreset = (modelType: ModelType, modelId: ModelId, name: string, value: any, tags = [], aliases = [], isList = false): IModelConfig => {6 return {7 modelType,8 modelId,9 name,10 // @ts-ignore11 valueIds: value,12 value: Object.freeze(isList ? value.map(id => {13 const isExtended = id.includes('9') || id.includes('11') || id.includes('13');14 let term = id;15 if (isExtended) {16 term = getExtensionInversionId(id);17 }18 return INTERVAL_PRESET_MAP.get(term).value19 }) : value), aliases,20 tags21 }22};23const formatNotePreset = (modelId: ModelId, name: string, value: IPod, tags = [], aliases = []): IModelConfig =>24 formatPreset(ModelType.Note, modelId, name, value, tags, aliases);25const formatIntervalPreset = (modelId: ModelId, name: string, value: IPod, tags = [], aliases = []): IModelConfig =>26 formatPreset(ModelType.Interval, modelId, name, value, tags, aliases);27const formatChordPreset = (modelId: ModelId, name: string, value: IntervalId[], tags = [], aliases = []): IModelConfig =>28 formatPreset(ModelType.Chord, modelId, name, value, tags, aliases, true);29const formatScalePreset = (modelId: ModelId, name: string, value: IntervalId[], tags = [], aliases = []): IModelConfig =>30 formatPreset(ModelType.Scale, modelId, name, value, tags, aliases, true);31const podToPodList = (podPresets: IModelConfig[]): IModelConfig[] =>32 podPresets.map(preset => ({ ...preset, value: [preset.value] as any }));33// Definition maps34export const NOTE_PRESET_MAP = new Map<NoteId, IModelConfig>([35 [NoteId.C, formatNotePreset(NoteId.C, 'C', [0, 0])],36 [NoteId.Cs, formatNotePreset(NoteId.Cs, 'C#', [1, 0])],37 [NoteId.Db, formatNotePreset(NoteId.Db, 'Db', [1, 1])],38 [NoteId.D, formatNotePreset(NoteId.D, 'D', [2, 1])],39 [NoteId.Ds, formatNotePreset(NoteId.Ds, 'D#', [3, 1])],40 [NoteId.Eb, formatNotePreset(NoteId.Eb, 'Eb', [3, 2])],41 [NoteId.E, formatNotePreset(NoteId.E, 'E', [4, 2])],42 [NoteId.Es, formatNotePreset(NoteId.Es, 'E#', [5, 2])],43 [NoteId.Fb, formatNotePreset(NoteId.Fb, 'Fb', [4, 3])],44 [NoteId.F, formatNotePreset(NoteId.F, 'F', [5, 3])],45 [NoteId.Fs, formatNotePreset(NoteId.Fs, 'F#', [6, 3])],46 [NoteId.Gb, formatNotePreset(NoteId.Gb, 'Gb', [6, 4])],47 [NoteId.G, formatNotePreset(NoteId.G, 'G', [7, 4])],48 [NoteId.Gs, formatNotePreset(NoteId.Gs, 'G#', [8, 4])],49 [NoteId.Ab, formatNotePreset(NoteId.Ab, 'Ab', [8, 5])],50 [NoteId.A, formatNotePreset(NoteId.A, 'A', [9, 5])],51 [NoteId.As, formatNotePreset(NoteId.As, 'A#', [10, 5])],52 [NoteId.Bb, formatNotePreset(NoteId.Bb, 'Bb', [10, 6])],53 [NoteId.B, formatNotePreset(NoteId.B, 'B', [11, 6])],54 [NoteId.Bs, formatNotePreset(NoteId.Bs, 'B#', [0, 6])],55 [NoteId.Cb, formatNotePreset(NoteId.Cb, 'Cb', [11, 0])]56]);57export const INTERVAL_PRESET_MAP = new Map<IntervalId, IModelConfig>([58 [IntervalId.P1, formatIntervalPreset(59 IntervalId.P1,60 'Perfect Unison',61 [0, 0],62 [Tag.Perfect]63 )],64 [IntervalId.m2, formatIntervalPreset(65 IntervalId.m2,66 'Minor 2nd',67 [1, 1],68 [Tag.Second, Tag.Minor]69 )],70 [IntervalId.M2, formatIntervalPreset(71 IntervalId.M2,72 'Major 2nd',73 [2, 1],74 [Tag.Second, Tag.Major]75 )],76 [IntervalId.A2, formatIntervalPreset(77 IntervalId.A2,78 'Augmented 2nd',79 [3, 1],80 [Tag.Second, Tag.Augmented]81 )],82 [IntervalId.d3, formatIntervalPreset(83 IntervalId.d3,84 'Diminished 3rd',85 [2, 2],86 [Tag.Third, Tag.Diminished]87 )],88 [IntervalId.m3, formatIntervalPreset(89 IntervalId.m3,90 'Minor 3rd',91 [3, 2],92 [Tag.Third, Tag.Minor]93 )],94 [IntervalId.M3, formatIntervalPreset(95 IntervalId.M3,96 'Major 3rd',97 [4, 2],98 [Tag.Third, Tag.Major]99 )],100 [IntervalId.A3, formatIntervalPreset(101 IntervalId.A3,102 'Augmented 3rd',103 [5, 2],104 [Tag.Third, Tag.Augmented]105 )],106 [IntervalId.d4, formatIntervalPreset(107 IntervalId.d4,108 'Diminished 4th',109 [4, 3],110 [Tag.Fourth, Tag.Diminished]111 )],112 [IntervalId.P4, formatIntervalPreset(113 IntervalId.P4,114 'Perfect 4th',115 [5, 3],116 [Tag.Fourth, Tag.Perfect]117 )],118 [IntervalId.A4, formatIntervalPreset(119 IntervalId.A4,120 'Augmented 4th',121 [6, 3],122 [Tag.Fourth, Tag.Augmented]123 )],124 [IntervalId.d5, formatIntervalPreset(125 IntervalId.d5,126 'Diminished 5th',127 [6, 4],128 [Tag.Fifth, Tag.Diminished]129 )],130 [IntervalId.P5, formatIntervalPreset(131 IntervalId.P5,132 'Perfect 5th',133 [7, 4],134 [Tag.Fifth, Tag.Perfect]135 )],136 [IntervalId.A5, formatIntervalPreset(137 IntervalId.A5,138 'Augmented 5th',139 [8, 4],140 [Tag.Fifth, Tag.Augmented]141 )],142 [IntervalId.d6, formatIntervalPreset(143 IntervalId.d6,144 'Diminished 6th',145 [7, 5],146 [Tag.Sixth, Tag.Diminished]147 )],148 [IntervalId.m6, formatIntervalPreset(149 IntervalId.m6,150 'Minor 6th',151 [8, 5],152 [Tag.Sixth, Tag.Minor]153 )],154 [IntervalId.M6, formatIntervalPreset(155 IntervalId.M6,156 'Major 6th',157 [9, 5],158 [Tag.Sixth, Tag.Major]159 )],160 [IntervalId.A6, formatIntervalPreset(161 IntervalId.A6,162 'Augmented 6th',163 [10, 5],164 [Tag.Sixth, Tag.Augmented]165 )],166 [IntervalId.d7, formatIntervalPreset(167 IntervalId.d7,168 'Diminished 7th',169 [9, 6],170 [Tag.Seventh, Tag.Diminished]171 )],172 [IntervalId.m7, formatIntervalPreset(173 IntervalId.m7,174 'Minor 7th',175 [10, 6],176 [Tag.Seventh, Tag.Minor]177 )],178 [IntervalId.M7, formatIntervalPreset(179 IntervalId.M7,180 'Major 7th',181 [11, 6],182 [Tag.Seventh, Tag.Major]183 )],184 [IntervalId.P8, formatIntervalPreset(185 IntervalId.P8,186 'Octave',187 [12, 7],188 [Tag.Perfect]189 )],190 [IntervalId.b9, formatIntervalPreset(191 IntervalId.b9,192 'Flat Ninth',193 [13, 8],194 [Tag.Extended]195 )],196 [IntervalId.x9, formatIntervalPreset(197 IntervalId.x9,198 'Ninth',199 [14, 8],200 [Tag.Extended]201 )],202 [IntervalId.s9, formatIntervalPreset(203 IntervalId.s9,204 'Sharp Ninth',205 [15, 8],206 [Tag.Extended]207 )],208 [IntervalId.b11, formatIntervalPreset(209 IntervalId.b11,210 'Flat Eleventh',211 [16, 10],212 [Tag.Extended]213 )],214 [IntervalId.x11, formatIntervalPreset(215 IntervalId.x11,216 'Eleventh',217 [17, 10],218 [Tag.Extended]219 )],220 [IntervalId.s11, formatIntervalPreset(221 IntervalId.s11,222 'Sharp Eleventh',223 [18, 10],224 [Tag.Extended]225 )],226 [IntervalId.b13, formatIntervalPreset(227 IntervalId.b13,228 'Flat Thirteenth',229 [20, 12],230 [Tag.Extended]231 )],232 [IntervalId.x13, formatIntervalPreset(233 IntervalId.x13,234 'Thirteenth',235 [21, 12],236 [Tag.Extended]237 )],238 [IntervalId.s13, formatIntervalPreset(239 IntervalId.s13,240 'Sharp Thirteenth',241 [22, 12],242 [Tag.Extended]243 )]244]);245export const CHORD_PRESET_MAP = new Map<ChordId, IModelConfig>([246 // Triads247 [ChordId.MajTriad, formatChordPreset(248 ChordId.MajTriad,249 'Major Triad',250 [IntervalId.P1, IntervalId.M3, IntervalId.P5],251 [Tag.Major, Tag.Triad]252 )],253 [ChordId.MinTriad, formatChordPreset(254 ChordId.MinTriad,255 'Minor Triad',256 [IntervalId.P1, IntervalId.m3, IntervalId.P5],257 [Tag.Minor, Tag.Triad]258 )],259 [ChordId.AugTriad, formatChordPreset(260 ChordId.AugTriad,261 'Augmented Triad',262 [IntervalId.P1, IntervalId.M3, IntervalId.A5],263 [Tag.Augmented, Tag.Triad]264 )],265 [ChordId.DimTriad, formatChordPreset(266 ChordId.DimTriad,267 'Diminished Triad',268 [IntervalId.P1, IntervalId.m3, IntervalId.d5],269 [Tag.Diminished, Tag.Triad]270 )],271 // Sevenths272 [ChordId.Maj7, formatChordPreset(273 ChordId.Maj7,274 'Major 7th',275 [IntervalId.P1, IntervalId.M3, IntervalId.P5, IntervalId.M7],276 [Tag.Major, Tag.Seventh]277 )],278 [ChordId.Min7, formatChordPreset(279 ChordId.Min7,280 'Minor 7th',281 [IntervalId.P1, IntervalId.m3, IntervalId.P5, IntervalId.m7],282 [Tag.Minor, Tag.Seventh]283 )],284 [ChordId.Dom7, formatChordPreset(285 ChordId.Dom7,286 'Dominant 7th',287 [IntervalId.P1, IntervalId.M3, IntervalId.P5, IntervalId.m7],288 [Tag.Dominant, Tag.Seventh]289 )],290 [ChordId.MinMaj7, formatChordPreset(291 ChordId.MinMaj7,292 'Minor-Major 7th',293 [IntervalId.P1, IntervalId.m3, IntervalId.P5, IntervalId.M7],294 [Tag.Minor, Tag.Seventh]295 )],296 [ChordId.Dim7, formatChordPreset(297 ChordId.Dim7,298 'Diminished 7th',299 [IntervalId.P1, IntervalId.m3, IntervalId.d5, IntervalId.d7],300 [Tag.Diminished, Tag.Seventh]301 )],302 [ChordId.HalfDim7, formatChordPreset(303 ChordId.HalfDim7,304 'Half-Diminished 7th',305 [IntervalId.P1, IntervalId.m3, IntervalId.d5, IntervalId.m7],306 [Tag.Diminished, Tag.Seventh],307 ['Minor 7th Flat 5']308 )],309 [ChordId.Aug7, formatChordPreset(310 ChordId.Aug7,311 'Augmented 7th',312 [IntervalId.P1, IntervalId.M3, IntervalId.A5, IntervalId.m7],313 [Tag.Augmented, Tag.Seventh]314 )],315 [ChordId.AugMaj7, formatChordPreset(316 ChordId.AugMaj7,317 'Augmented Major 7th',318 [IntervalId.P1, IntervalId.M3, IntervalId.A5, IntervalId.M7],319 [Tag.Augmented, Tag.Seventh]320 )],321 // Sixths322 [ChordId.Maj6, formatChordPreset(323 ChordId.Maj6,324 'Major 6th',325 [IntervalId.P1, IntervalId.M3, IntervalId.P5, IntervalId.M6],326 [Tag.Major, Tag.Sixth]327 )],328 [ChordId.Min6, formatChordPreset(329 ChordId.Min6,330 'Minor 6th',331 [IntervalId.P1, IntervalId.m3, IntervalId.P5, IntervalId.M6],332 [Tag.Minor, Tag.Sixth]333 )],334 // Suspended335 [ChordId.Sus2, formatChordPreset(336 ChordId.Sus2,337 'Suspended 2nd',338 [IntervalId.P1, IntervalId.M2, IntervalId.P5],339 [Tag.Suspended, Tag.Triad]340 )],341 [ChordId.Sus4, formatChordPreset(342 ChordId.Sus4,343 'Suspended 4th',344 [IntervalId.P1, IntervalId.P4, IntervalId.P5],345 [Tag.Suspended, Tag.Triad]346 )]347]);348interface IExtendedChordConfig {349 chordId: ChordId,350 name: string,351 baseChordId: ChordId,352 extensions: IntervalId[]353}354const addExtendedChordPreset = (config: IExtendedChordConfig) => {355 const { chordId, name, baseChordId, extensions } = config;356 const basePreset = CHORD_PRESET_MAP.get(baseChordId);357 let baseIds = (basePreset as any).valueIds;358 const extensionPreset = formatChordPreset(chordId, name, [359 ...baseIds,360 ...extensions,361 ], [...basePreset.tags, Tag.Extended], basePreset.aliases);362 return CHORD_PRESET_MAP.set(chordId, extensionPreset);363};364const EXTENDED_CHORDS: IExtendedChordConfig[] = [365 {366 name: 'Dominant b9', chordId: ChordId.DomFlat9, baseChordId: ChordId.Dom7, extensions: [367 IntervalId.b9368 ]369 },370 {371 name: 'Dominant 9', chordId: ChordId.Dom9, baseChordId: ChordId.Dom7, extensions: [372 IntervalId.x9373 ]374 },375 {376 name: 'Dominant #9', chordId: ChordId.DomSharp9, baseChordId: ChordId.Dom7, extensions: [377 IntervalId.s9378 ]379 },380 {381 name: 'Dominant 11', chordId: ChordId.Dom11, baseChordId: ChordId.Dom7, extensions: [382 IntervalId.x11383 ]384 },385 {386 name: 'Dominant #11', chordId: ChordId.DomSharp11, baseChordId: ChordId.Dom7, extensions: [387 IntervalId.s11388 ]389 },390 {391 name: 'Dominant b13', chordId: ChordId.DomFlat13, baseChordId: ChordId.Dom7, extensions: [392 IntervalId.b13393 ]394 },395 {396 name: 'Dominant 13', chordId: ChordId.Dom13, baseChordId: ChordId.Dom7, extensions: [397 IntervalId.x13398 ]399 },400 /*{401 name: 'Dominant b5', chordId: ChordId.DomFlat5, baseChordId: ChordId.Dom7, extensions: [402 IntervalId.d9403 ]404 },405 {406 name: 'Dominant #5', chordId: ChordId.DomSharp5, baseChordId: ChordId.Dom7, extensions: [407 IntervalId.A5408 ]409 },*/410 {411 name: 'Minor b9', chordId: ChordId.MinFlat9, baseChordId: ChordId.Min7, extensions: [412 IntervalId.b9413 ]414 },415 {416 name: 'Minor 9', chordId: ChordId.Min9, baseChordId: ChordId.Min7, extensions: [417 IntervalId.x9418 ]419 },420 {421 name: 'Minor 11', chordId: ChordId.Min11, baseChordId: ChordId.Min7, extensions: [422 IntervalId.x11423 ]424 },425 {426 name: 'Minor 13', chordId: ChordId.Min13, baseChordId: ChordId.Min7, extensions: [427 IntervalId.x13428 ]429 },430 {431 name: 'Major 9', chordId: ChordId.Maj9, baseChordId: ChordId.Maj7, extensions: [432 IntervalId.x9433 ]434 },435 {436 name: 'Major 11', chordId: ChordId.Maj11, baseChordId: ChordId.Maj7, extensions: [437 IntervalId.x11438 ]439 },440 {441 name: 'Major #11', chordId: ChordId.MajSharp11, baseChordId: ChordId.Maj7, extensions: [442 IntervalId.s11443 ]444 },445 {446 name: 'Major 13', chordId: ChordId.Maj13, baseChordId: ChordId.Maj7, extensions: [447 IntervalId.x13448 ]449 },450 /*{451 name: 'Major #5', chordId: ChordId.MajSharp5, baseChordId: ChordId.Maj7, extensions: [452 IntervalId.x9453 ]454 }*/455];456EXTENDED_CHORDS.forEach(chord => addExtendedChordPreset(chord));457export const SCALE_PRESET_MAP = new Map<ScaleId, IModelConfig>([458 // Diatonic459 [ScaleId.Ionian, formatScalePreset(460 ScaleId.Ionian, 'Ionian',461 [IntervalId.P1, IntervalId.M2, IntervalId.M3, IntervalId.P4, IntervalId.P5, IntervalId.M6, IntervalId.M7],462 [Tag.Heptatonic, Tag.Diatonic, Tag.Major],463 ['Major', 'Diatonic']464 )],465 [ScaleId.Dorian, formatScalePreset(466 ScaleId.Dorian, 'Dorian',467 [IntervalId.P1, IntervalId.M2, IntervalId.m3, IntervalId.P4, IntervalId.P5, IntervalId.M6, IntervalId.m7],468 [Tag.Heptatonic, Tag.Diatonic, Tag.Minor]469 )],470 [ScaleId.Phrygian, formatScalePreset(471 ScaleId.Phrygian, 'Phrygian',472 [IntervalId.P1, IntervalId.m2, IntervalId.m3, IntervalId.P4, IntervalId.P5, IntervalId.m6, IntervalId.m7],473 [Tag.Heptatonic, Tag.Diatonic, Tag.Minor]474 )],475 [ScaleId.Lydian, formatScalePreset(476 ScaleId.Lydian, 'Lydian',477 [IntervalId.P1, IntervalId.M2, IntervalId.M3, IntervalId.A4, IntervalId.P5, IntervalId.M6, IntervalId.M7],478 [Tag.Heptatonic, Tag.Diatonic, Tag.Major]479 )],480 [ScaleId.Mixolydian, formatScalePreset(481 ScaleId.Mixolydian, 'Mixolydian',482 [IntervalId.P1, IntervalId.M2, IntervalId.M3, IntervalId.P4, IntervalId.P5, IntervalId.M6, IntervalId.m7],483 [Tag.Heptatonic, Tag.Diatonic, Tag.Major, Tag.Dominant]484 )],485 [ScaleId.Aeolian, formatScalePreset(486 ScaleId.Aeolian, 'Aeolian',487 [IntervalId.P1, IntervalId.M2, IntervalId.m3, IntervalId.P4, IntervalId.P5, IntervalId.m6, IntervalId.m7],488 [Tag.Heptatonic, Tag.Diatonic, Tag.Minor],489 ['Minor', 'Natural Minor']490 )],491 [ScaleId.Locrian, formatScalePreset(492 ScaleId.Locrian, 'Locrian',493 [IntervalId.P1, IntervalId.m2, IntervalId.m3, IntervalId.P4, IntervalId.d5, IntervalId.m6, IntervalId.m7],494 [Tag.Heptatonic, Tag.Diatonic, Tag.Minor]495 )],496 // Harmonic Minor497 [ScaleId.HarmonicMinor, formatScalePreset(498 ScaleId.HarmonicMinor, 'Harmonic Minor',499 [IntervalId.P1, IntervalId.M2, IntervalId.m3, IntervalId.P4, IntervalId.P5, IntervalId.m6, IntervalId.M7],500 [Tag.Heptatonic, Tag.Minor, Tag.HarmonicMode]501 )],502 [ScaleId.Locrian6, formatScalePreset(503 ScaleId.Locrian6, 'Locrian 6',504 [IntervalId.P1, IntervalId.m2, IntervalId.m3, IntervalId.P4, IntervalId.d5, IntervalId.M6, IntervalId.m7],505 [Tag.Heptatonic, Tag.Exotic, Tag.HarmonicMode]506 )],507 [ScaleId.IonianSharp5, formatScalePreset(508 ScaleId.IonianSharp5, 'Ionian #5',509 [IntervalId.P1, IntervalId.M2, IntervalId.M3, IntervalId.P4, IntervalId.A5, IntervalId.M6, IntervalId.M7],510 [Tag.Heptatonic, Tag.Exotic, Tag.HarmonicMode]511 )],512 [ScaleId.DorianSharp4, formatScalePreset(513 ScaleId.DorianSharp4, 'Dorian #4',514 [IntervalId.P1, IntervalId.M2, IntervalId.m3, IntervalId.A4, IntervalId.P5, IntervalId.M6, IntervalId.m7],515 [Tag.Heptatonic, Tag.Exotic, Tag.HarmonicMode]516 )],517 [ScaleId.PhrygianDominant, formatScalePreset(518 ScaleId.PhrygianDominant, 'Phrygian Dominant',519 [IntervalId.P1, IntervalId.m2, IntervalId.M3, IntervalId.P4, IntervalId.P5, IntervalId.m6, IntervalId.m7],520 [Tag.Heptatonic, Tag.Exotic, Tag.Dominant, Tag.HarmonicMode]521 )],522 [ScaleId.LydianSharp2, formatScalePreset(523 ScaleId.LydianSharp2, 'Lydian #2',524 [IntervalId.P1, IntervalId.A2, IntervalId.M3, IntervalId.A4, IntervalId.P5, IntervalId.M6, IntervalId.M7],525 [Tag.Heptatonic, Tag.Exotic, Tag.HarmonicMode]526 )],527 [ScaleId.SuperLocrianDoubleFlat7, formatScalePreset(528 ScaleId.SuperLocrianDoubleFlat7, 'Super Locrian bb7',529 [IntervalId.P1, IntervalId.m2, IntervalId.m3, IntervalId.d4, IntervalId.d5, IntervalId.m6, IntervalId.d7],530 [Tag.Heptatonic, Tag.Exotic, Tag.HarmonicMode]531 )],532 // Melodic Minor533 [ScaleId.MelodicMinor, formatScalePreset(534 ScaleId.MelodicMinor, 'Melodic Minor',535 [IntervalId.P1, IntervalId.M2, IntervalId.m3, IntervalId.P4, IntervalId.P5, IntervalId.M6, IntervalId.M7],536 [Tag.Heptatonic, Tag.Minor, Tag.MelodicMode]537 )],538 [ScaleId.DorianFlat2, formatScalePreset(539 ScaleId.DorianFlat2, 'Dorian b2',540 [IntervalId.P1, IntervalId.m2, IntervalId.m3, IntervalId.P4, IntervalId.P5, IntervalId.M6, IntervalId.m7],541 [Tag.Heptatonic, Tag.Exotic, Tag.MelodicMode]542 )],543 [ScaleId.LydianSharp5, formatScalePreset(544 ScaleId.LydianSharp5, 'Lydian #5',545 [IntervalId.P1, IntervalId.M2, IntervalId.M3, IntervalId.A4, IntervalId.A5, IntervalId.M6, IntervalId.M7],546 [Tag.Heptatonic, Tag.Exotic, Tag.MelodicMode]547 )],548 [ScaleId.LydianDominiant, formatScalePreset(549 ScaleId.LydianDominiant, 'Lydian Dominant',550 [IntervalId.P1, IntervalId.M2, IntervalId.M3, IntervalId.A4, IntervalId.P5, IntervalId.M6, IntervalId.m7],551 [Tag.Heptatonic, Tag.Exotic, Tag.Dominant, Tag.MelodicMode]552 )],553 [ScaleId.MixolydianFlatSix, formatScalePreset(554 ScaleId.MixolydianFlatSix, 'Mixolydian b6',555 [IntervalId.P1, IntervalId.M2, IntervalId.M3, IntervalId.P4, IntervalId.P5, IntervalId.m6, IntervalId.m7],556 [Tag.Heptatonic, Tag.Exotic, Tag.MelodicMode]557 )],558 [ScaleId.AeolianFlat5, formatScalePreset(559 ScaleId.AeolianFlat5, 'Aeolian b5',560 [IntervalId.P1, IntervalId.M2, IntervalId.m3, IntervalId.P4, IntervalId.d5, IntervalId.m6, IntervalId.m7],561 [Tag.Heptatonic, Tag.Exotic, Tag.MelodicMode]562 )],563 [ScaleId.SuperLocrian, formatScalePreset(564 ScaleId.SuperLocrian, 'Super Locrian',565 [IntervalId.P1, IntervalId.m2, IntervalId.m3, IntervalId.d4, IntervalId.d5, IntervalId.m6, IntervalId.m7],566 [Tag.Heptatonic, Tag.Exotic, Tag.MelodicMode],567 ['Altered']568 )],569 // Pentatonic570 [ScaleId.MajorPentatonic, formatScalePreset(571 ScaleId.MajorPentatonic, 'Major Pentatonic',572 [IntervalId.P1, IntervalId.M2, IntervalId.M3, IntervalId.P5, IntervalId.M6],573 [Tag.Pentatonic, Tag.Major]574 )],575 [ScaleId.Egyptian, formatScalePreset(576 ScaleId.Egyptian, 'Egyptian',577 [IntervalId.P1, IntervalId.M2, IntervalId.P4, IntervalId.P5, IntervalId.m7],578 [Tag.Pentatonic, Tag.Exotic]579 )],580 [ScaleId.ManGong, formatScalePreset(581 ScaleId.ManGong, 'Man Gong',582 [IntervalId.P1, IntervalId.m3, IntervalId.P4, IntervalId.m6, IntervalId.m7],583 [Tag.Pentatonic, Tag.Exotic]584 )],585 [ScaleId.Ritusen, formatScalePreset(586 ScaleId.Ritusen, 'Ritusen',587 [IntervalId.P1, IntervalId.M2, IntervalId.P4, IntervalId.P5, IntervalId.M6],588 [Tag.Pentatonic, Tag.Exotic]589 )],590 [ScaleId.MinorPentatonic, formatScalePreset(591 ScaleId.MinorPentatonic, 'Minor Pentatonic',592 [IntervalId.P1, IntervalId.m3, IntervalId.P4, IntervalId.P5, IntervalId.m7],593 [Tag.Pentatonic, Tag.Minor]594 )],595 // Blues596 [ScaleId.MajorBlues, formatScalePreset(597 ScaleId.MajorBlues, 'Major Blues',598 [IntervalId.P1, IntervalId.M2, IntervalId.m3, IntervalId.M3, IntervalId.P5, IntervalId.M6],599 [Tag.Hexatonic, Tag.Blues, Tag.Major]600 )],601 [ScaleId.MinorBlues, formatScalePreset(602 ScaleId.MinorBlues, 'Minor Blues',603 [IntervalId.P1, IntervalId.m3, IntervalId.P4, IntervalId.d5, IntervalId.P5, IntervalId.m7],604 [Tag.Hexatonic, Tag.Blues, Tag.Minor]605 )],606 // Bebop607 [ScaleId.DominantBebop, formatScalePreset(608 ScaleId.DominantBebop, 'Dominant Bebob',609 [IntervalId.P1, IntervalId.M2, IntervalId.M3, IntervalId.P4, IntervalId.P5, IntervalId.M6, IntervalId.m7, IntervalId.M7],610 [Tag.Octatonic, Tag.Bebop, Tag.Major, Tag.Dominant]611 )],612 [ScaleId.MajorBebop, formatScalePreset(613 ScaleId.MajorBebop, 'Major Bebob',614 [IntervalId.P1, IntervalId.M2, IntervalId.M3, IntervalId.P4, IntervalId.P5, IntervalId.m6, IntervalId.M6, IntervalId.M7],615 [Tag.Octatonic, Tag.Bebop, Tag.Major]616 )]617]);618// Definition arrays619export const NOTE_PRESETS = ArrayUtils.mapToArray(NOTE_PRESET_MAP);620export const SCALE_PRESETS = ArrayUtils.mapToArray(SCALE_PRESET_MAP);621export const CHORD_PRESETS = ArrayUtils.mapToArray(CHORD_PRESET_MAP);622export const INTERVAL_PRESETS = ArrayUtils.mapToArray(INTERVAL_PRESET_MAP);623export const ALL_PRESETS = [...CHORD_PRESETS, ...SCALE_PRESETS];624// Definition groupings625export const CORE_INTERVALS = [626 [INTERVAL_PRESET_MAP.get(IntervalId.P1)],627 [INTERVAL_PRESET_MAP.get(IntervalId.m2), INTERVAL_PRESET_MAP.get(IntervalId.M2)],628 [INTERVAL_PRESET_MAP.get(IntervalId.m3), INTERVAL_PRESET_MAP.get(IntervalId.M3)],629 [INTERVAL_PRESET_MAP.get(IntervalId.P4)],630 [INTERVAL_PRESET_MAP.get(IntervalId.P5)],631 [INTERVAL_PRESET_MAP.get(IntervalId.m6), INTERVAL_PRESET_MAP.get(IntervalId.M6)],632 [INTERVAL_PRESET_MAP.get(IntervalId.m7), INTERVAL_PRESET_MAP.get(IntervalId.M7)]633];634// console.log('pw-presets', NOTE_PRESETS, INTERVAL_PRESETS, CHORD_PRESETS, SCALE_PRESETS);635export const logPresetJson = () => {636 console.log('pw-presets notes', JSON.stringify(NOTE_PRESETS));637 console.log('pw-presets intervals', JSON.stringify(INTERVAL_PRESETS));638 console.log('pw-presets chords', JSON.stringify(CHORD_PRESETS));639 console.log('pw-presets scales', JSON.stringify(SCALE_PRESETS));...

Full Screen

Full Screen

data.js

Source:data.js Github

copy

Full Screen

1export const getTunesData = () => (2 {3 1: [4 {5 intervalId: 1,6 notes: [7 'C1',8 'С1',9 ],10 },11 {12 intervalId: 1,13 notes: [14 'C2',15 'C2',16 ],17 },18 {19 intervalId: 1,20 notes: [21 'D1',22 'D1',23 ],24 },25 {26 intervalId: 1,27 notes: [28 'D2',29 'D2',30 ],31 },32 {33 intervalId: 1,34 notes: [35 'E1',36 'E1',37 ],38 },39 {40 intervalId: 1,41 notes: [42 'E2',43 'E2',44 ],45 },46 {47 intervalId: 1,48 notes: [49 'F1',50 'F1',51 ],52 },53 {54 intervalId: 1,55 notes: [56 'F2',57 'F2',58 ],59 },60 {61 intervalId: 1,62 notes: [63 'G1',64 'G1',65 ],66 },67 {68 intervalId: 1,69 notes: [70 'G2',71 'G2',72 ],73 },74 {75 intervalId: 1,76 notes: [77 'A1',78 'A1',79 ],80 },81 {82 intervalId: 1,83 notes: [84 'A2',85 'A2',86 ],87 },88 {89 intervalId: 1,90 notes: [91 'B1',92 'B1',93 ],94 },95 {96 intervalId: 1,97 notes: [98 'B2',99 'B2',100 ],101 },102 {103 intervalId: 1,104 notes: [105 'Db1',106 'Db1',107 ],108 },109 {110 intervalId: 1,111 notes: [112 'Db2',113 'Db2',114 ],115 },116 {117 intervalId: 1,118 notes: [119 'Eb1',120 'Eb1',121 ],122 },123 {124 intervalId: 1,125 notes: [126 'Eb2',127 'Eb2',128 ],129 },130 {131 intervalId: 1,132 notes: [133 'Gb1',134 'Gb1',135 ],136 },137 {138 intervalId: 1,139 notes: [140 'Gb2',141 'Gb2',142 ],143 },144 {145 intervalId: 1,146 notes: [147 'Ab1',148 'Ab1',149 ],150 },151 {152 intervalId: 1,153 notes: [154 'Ab2',155 'Ab2',156 ],157 },158 {159 intervalId: 1,160 notes: [161 'Bb1',162 'Bb1',163 ],164 },165 {166 intervalId: 1,167 notes: [168 'Bb2',169 'Bb2',170 ],171 },172 ],173 2: [174 {175 intervalId: 2,176 notes: [177 'C1',178 'Db1',179 ],180 },181 {182 intervalId: 2,183 notes: [184 'D1',185 'Eb1',186 ],187 },188 {189 intervalId: 2,190 notes: [191 'E1',192 'F1',193 ],194 },195 {196 intervalId: 2,197 notes: [198 'F1',199 'Gb1',200 ],201 },202 {203 intervalId: 2,204 notes: [205 'G1',206 'Ab1',207 ],208 },209 {210 intervalId: 2,211 notes: [212 'A1',213 'Bb1',214 ],215 },216 {217 intervalId: 2,218 notes: [219 'B1',220 'C2',221 ],222 },223 {224 intervalId: 2,225 notes: [226 'Db1',227 'D1',228 ],229 },230 {231 intervalId: 2,232 notes: [233 'Eb1',234 'E1',235 ],236 },237 {238 intervalId: 2,239 notes: [240 'Gb1',241 'G1',242 ],243 },244 {245 intervalId: 2,246 notes: [247 'Ab1',248 'A1',249 ],250 },251 {252 intervalId: 2,253 notes: [254 'Bb1',255 'B1',256 ],257 },258 ],259 3: [260 {261 intervalId: 3,262 notes: [263 'C1',264 'D1',265 ],266 },267 {268 intervalId: 3,269 notes: [270 'D1',271 'E1',272 ],273 },274 {275 intervalId: 3,276 notes: [277 'E1',278 'Gb1',279 ],280 },281 {282 intervalId: 3,283 notes: [284 'F1',285 'G1',286 ],287 },288 {289 intervalId: 3,290 notes: [291 'G1',292 'A1',293 ],294 },295 {296 intervalId: 3,297 notes: [298 'A1',299 'B1',300 ],301 },302 {303 intervalId: 3,304 notes: [305 'B1',306 'Db2',307 ],308 },309 {310 intervalId: 3,311 notes: [312 'Db1',313 'Eb1',314 ],315 },316 {317 intervalId: 3,318 notes: [319 'Eb1',320 'F1',321 ],322 },323 {324 intervalId: 3,325 notes: [326 'Gb1',327 'Ab1',328 ],329 },330 {331 intervalId: 3,332 notes: [333 'Ab1',334 'Bb1',335 ],336 },337 {338 intervalId: 3,339 notes: [340 'Bb1',341 'C2',342 ],343 },344 ],345 4: [346 {347 intervalId: 4,348 notes: [349 'C1',350 'Eb1',351 ],352 },353 {354 intervalId: 4,355 notes: [356 'D1',357 'F1',358 ],359 },360 {361 intervalId: 4,362 notes: [363 'E1',364 'G1',365 ],366 },367 {368 intervalId: 4,369 notes: [370 'F1',371 'Ab1',372 ],373 },374 {375 intervalId: 4,376 notes: [377 'G1',378 'Bb1',379 ],380 },381 {382 intervalId: 4,383 notes: [384 'A1',385 'C2',386 ],387 },388 {389 intervalId: 4,390 notes: [391 'B1',392 'D2',393 ],394 },395 {396 intervalId: 4,397 notes: [398 'Db1',399 'E1',400 ],401 },402 {403 intervalId: 4,404 notes: [405 'Eb1',406 'Gb1',407 ],408 },409 {410 intervalId: 4,411 notes: [412 'Gb1',413 'A1',414 ],415 },416 {417 intervalId: 4,418 notes: [419 'Ab1',420 'B1',421 ],422 },423 {424 intervalId: 4,425 notes: [426 'Bb1',427 'Db2',428 ],429 },430 ],431 5: [432 {433 intervalId: 5,434 notes: [435 'C1',436 'E1',437 ],438 },439 {440 intervalId: 5,441 notes: [442 'D1',443 'Gb1',444 ],445 },446 {447 intervalId: 5,448 notes: [449 'E1',450 'Ab1',451 ],452 },453 {454 intervalId: 5,455 notes: [456 'F1',457 'A1',458 ],459 },460 {461 intervalId: 5,462 notes: [463 'G1',464 'B1',465 ],466 },467 {468 intervalId: 5,469 notes: [470 'A1',471 'Db2',472 ],473 },474 {475 intervalId: 5,476 notes: [477 'B1',478 'Eb2',479 ],480 },481 {482 intervalId: 5,483 notes: [484 'Db1',485 'F1',486 ],487 },488 {489 intervalId: 5,490 notes: [491 'Eb1',492 'G1',493 ],494 },495 {496 intervalId: 5,497 notes: [498 'Gb1',499 'Bb1',500 ],501 },502 {503 intervalId: 5,504 notes: [505 'Ab1',506 'C2',507 ],508 },509 {510 intervalId: 5,511 notes: [512 'Bb1',513 'D2',514 ],515 },516 ],517 6: [518 {519 intervalId: 6,520 notes: [521 'C1',522 'F1',523 ],524 },525 {526 intervalId: 6,527 notes: [528 'D1',529 'G1',530 ],531 },532 {533 intervalId: 6,534 notes: [535 'E1',536 'A1',537 ],538 },539 {540 intervalId: 6,541 notes: [542 'F1',543 'Bb1',544 ],545 },546 {547 intervalId: 6,548 notes: [549 'G1',550 'C2',551 ],552 },553 {554 intervalId: 6,555 notes: [556 'A1',557 'D2',558 ],559 },560 {561 intervalId: 6,562 notes: [563 'B1',564 'E2',565 ],566 },567 {568 intervalId: 6,569 notes: [570 'Db1',571 'Gb1',572 ],573 },574 {575 intervalId: 6,576 notes: [577 'Eb1',578 'Ab1',579 ],580 },581 {582 intervalId: 6,583 notes: [584 'Gb1',585 'B1',586 ],587 },588 {589 intervalId: 6,590 notes: [591 'Ab1',592 'Db2',593 ],594 },595 {596 intervalId: 6,597 notes: [598 'Bb1',599 'Eb2',600 ],601 },602 ],603 7: [604 {605 intervalId: 7,606 notes: [607 'C1',608 'Gb1',609 ],610 },611 {612 intervalId: 7,613 notes: [614 'D1',615 'Ab1',616 ],617 },618 {619 intervalId: 7,620 notes: [621 'E1',622 'Bb1',623 ],624 },625 {626 intervalId: 7,627 notes: [628 'F1',629 'B1',630 ],631 },632 {633 intervalId: 7,634 notes: [635 'G1',636 'Db2',637 ],638 },639 {640 intervalId: 7,641 notes: [642 'A1',643 'Eb2',644 ],645 },646 {647 intervalId: 7,648 notes: [649 'B1',650 'F2',651 ],652 },653 {654 intervalId: 7,655 notes: [656 'Db1',657 'G1',658 ],659 },660 {661 intervalId: 7,662 notes: [663 'Eb1',664 'A1',665 ],666 },667 {668 intervalId: 7,669 notes: [670 'Gb1',671 'C2',672 ],673 },674 {675 intervalId: 7,676 notes: [677 'Ab1',678 'D2',679 ],680 },681 {682 intervalId: 7,683 notes: [684 'Bb1',685 'E2',686 ],687 },688 ],689 8: [690 {691 intervalId: 8,692 notes: [693 'C1',694 'G1',695 ],696 },697 {698 intervalId: 8,699 notes: [700 'D1',701 'A1',702 ],703 },704 {705 intervalId: 8,706 notes: [707 'E1',708 'B1',709 ],710 },711 {712 intervalId: 8,713 notes: [714 'F1',715 'C2',716 ],717 },718 {719 intervalId: 8,720 notes: [721 'G1',722 'D2',723 ],724 },725 {726 intervalId: 8,727 notes: [728 'A1',729 'E2',730 ],731 },732 {733 intervalId: 8,734 notes: [735 'B1',736 'Gb2',737 ],738 },739 {740 intervalId: 8,741 notes: [742 'Db1',743 'Ab1',744 ],745 },746 {747 intervalId: 8,748 notes: [749 'Eb1',750 'Bb1',751 ],752 },753 {754 intervalId: 8,755 notes: [756 'Gb1',757 'Dfalt2',758 ],759 },760 {761 intervalId: 8,762 notes: [763 'Ab1',764 'Eb2',765 ],766 },767 {768 intervalId: 8,769 notes: [770 'Bb1',771 'F2',772 ],773 },774 ],775 9: [776 {777 intervalId: 9,778 notes: [779 'C1',780 'Ab1',781 ],782 },783 {784 intervalId: 9,785 notes: [786 'D1',787 'Bb1',788 ],789 },790 {791 intervalId: 9,792 notes: [793 'E1',794 'C2',795 ],796 },797 {798 intervalId: 9,799 notes: [800 'F1',801 'Db2',802 ],803 },804 {805 intervalId: 9,806 notes: [807 'G1',808 'Eb2',809 ],810 },811 {812 intervalId: 9,813 notes: [814 'A1',815 'F2',816 ],817 },818 {819 intervalId: 9,820 notes: [821 'B1',822 'G2',823 ],824 },825 {826 intervalId: 9,827 notes: [828 'Db1',829 'A1',830 ],831 },832 {833 intervalId: 9,834 notes: [835 'Eb1',836 'B1',837 ],838 },839 {840 intervalId: 9,841 notes: [842 'Gb1',843 'D2',844 ],845 },846 {847 intervalId: 9,848 notes: [849 'Ab1',850 'E2',851 ],852 },853 {854 intervalId: 9,855 notes: [856 'Bb1',857 'Gb2',858 ],859 },860 ],861 10: [862 {863 intervalId: 10,864 notes: [865 'C1',866 'A1',867 ],868 },869 {870 intervalId: 10,871 notes: [872 'D1',873 'B1',874 ],875 },876 {877 intervalId: 10,878 notes: [879 'E1',880 'Db2',881 ],882 },883 {884 intervalId: 10,885 notes: [886 'F1',887 'D2',888 ],889 },890 {891 intervalId: 10,892 notes: [893 'G1',894 'E2',895 ],896 },897 {898 intervalId: 10,899 notes: [900 'A1',901 'Gb2',902 ],903 },904 {905 intervalId: 10,906 notes: [907 'B1',908 'Ab2',909 ],910 },911 {912 intervalId: 10,913 notes: [914 'Db1',915 'Bb1',916 ],917 },918 {919 intervalId: 10,920 notes: [921 'Eb1',922 'C2',923 ],924 },925 {926 intervalId: 10,927 notes: [928 'Gb1',929 'Eb2',930 ],931 },932 {933 intervalId: 10,934 notes: [935 'Ab1',936 'F2',937 ],938 },939 {940 intervalId: 10,941 notes: [942 'Bb1',943 'G2',944 ],945 },946 ],947 11: [948 {949 intervalId: 11,950 notes: [951 'C1',952 'Bb1',953 ],954 },955 {956 intervalId: 11,957 notes: [958 'D1',959 'C2',960 ],961 },962 {963 intervalId: 11,964 notes: [965 'E1',966 'D2',967 ],968 },969 {970 intervalId: 11,971 notes: [972 'F1',973 'Eb2',974 ],975 },976 {977 intervalId: 11,978 notes: [979 'G1',980 'F2',981 ],982 },983 {984 intervalId: 11,985 notes: [986 'A1',987 'G2',988 ],989 },990 {991 intervalId: 11,992 notes: [993 'B1',994 'A2',995 ],996 },997 {998 intervalId: 11,999 notes: [1000 'Db1',1001 'B1',1002 ],1003 },1004 {1005 intervalId: 11,1006 notes: [1007 'Eb1',1008 'Db2',1009 ],1010 },1011 {1012 intervalId: 11,1013 notes: [1014 'Gb1',1015 'E2',1016 ],1017 },1018 {1019 intervalId: 11,1020 notes: [1021 'Ab1',1022 'Gb2',1023 ],1024 },1025 {1026 intervalId: 11,1027 notes: [1028 'Bb1',1029 'Ab2',1030 ],1031 },1032 ],1033 12: [1034 {1035 intervalId: 12,1036 notes: [1037 'C1',1038 'B1',1039 ],1040 },1041 {1042 intervalId: 12,1043 notes: [1044 'D1',1045 'Db2',1046 ],1047 },1048 {1049 intervalId: 12,1050 notes: [1051 'E1',1052 'Eb2',1053 ],1054 },1055 {1056 intervalId: 12,1057 notes: [1058 'F1',1059 'E2',1060 ],1061 },1062 {1063 intervalId: 12,1064 notes: [1065 'G1',1066 'Gb2',1067 ],1068 },1069 {1070 intervalId: 12,1071 notes: [1072 'A1',1073 'Ab2',1074 ],1075 },1076 {1077 intervalId: 12,1078 notes: [1079 'B1',1080 'Bb2',1081 ],1082 },1083 {1084 intervalId: 12,1085 notes: [1086 'Db1',1087 'C2',1088 ],1089 },1090 {1091 intervalId: 12,1092 notes: [1093 'Eb1',1094 'D2',1095 ],1096 },1097 {1098 intervalId: 12,1099 notes: [1100 'Gb1',1101 'F2',1102 ],1103 },1104 {1105 intervalId: 12,1106 notes: [1107 'Ab1',1108 'G2',1109 ],1110 },1111 {1112 intervalId: 12,1113 notes: [1114 'Bb1',1115 'A2',1116 ],1117 },1118 ],1119 13: [1120 {1121 intervalId: 13,1122 notes: [1123 'C1',1124 'C2',1125 ],1126 },1127 {1128 intervalId: 13,1129 notes: [1130 'D1',1131 'D2',1132 ],1133 },1134 {1135 intervalId: 13,1136 notes: [1137 'E1',1138 'E2',1139 ],1140 },1141 {1142 intervalId: 13,1143 notes: [1144 'F1',1145 'F2',1146 ],1147 },1148 {1149 intervalId: 13,1150 notes: [1151 'G1',1152 'G2',1153 ],1154 },1155 {1156 intervalId: 13,1157 notes: [1158 'A1',1159 'A2',1160 ],1161 },1162 {1163 intervalId: 13,1164 notes: [1165 'B1',1166 'B2',1167 ],1168 },1169 {1170 intervalId: 13,1171 notes: [1172 'Db1',1173 'Db2',1174 ],1175 },1176 {1177 intervalId: 13,1178 notes: [1179 'Eb1',1180 'Eb2',1181 ],1182 },1183 {1184 intervalId: 13,1185 notes: [1186 'Gb1',1187 'Gb2',1188 ],1189 },1190 {1191 intervalId: 13,1192 notes: [1193 'Ab1',1194 'Ab2',1195 ],1196 },1197 {1198 intervalId: 13,1199 notes: [1200 'Bb1',1201 'Bb2',1202 ],1203 },1204 ],1205 }...

Full Screen

Full Screen

script.js

Source:script.js Github

copy

Full Screen

1'use strict';2{ //3 $('.hand').on('click',function(event){ //ボタン押したときにイベント起こる4 event.preventDefault();5 const enemyHand = Math.floor(Math.random() * 3); //0~2のランダムな数を生成してenemyHandに代入6 console.log(enemyHand);78 const myHand = Number(event.currentTarget.value); //各ボタンに割り振ったvalueを取得して数値に変換9 console.log(myHand); 10 //setInterval mean 〇秒おきにこの処理を行う(今回は一回した後にクリアしてる)※今回はなぜかalertが先に出た為遅らせた11 if(enemyHand === 0){12 $('#bigimg').attr('src','images/janken_gu.png')13 if(myHand === 2){14 const intervalId = setInterval(function(){ 15 alert('勝ち!');16 $('#bigimg').attr('src','images/mark_question.png')17 clearInterval(intervalId);18 },200);19 }else if(myHand === 1){20 const intervalId = setInterval(function(){ 21 alert('負け!');22 $('#bigimg').attr('src','images/mark_question.png')23 clearInterval(intervalId);24 },200);25 }else{26 const intervalId = setInterval(function(){ 27 alert('引き分け!');28 $('#bigimg').attr('src','images/mark_question.png')29 clearInterval(intervalId);30 },200);31 }32 }else if(enemyHand === 1){33 $('#bigimg').attr('src','images/janken_choki.png')34 if(myHand === 0){35 const intervalId = setInterval(function(){ 36 alert('勝ち!');37 $('#bigimg').attr('src','images/mark_question.png')38 clearInterval(intervalId);39 },200);40 }else if(myHand === 2){41 const intervalId = setInterval(function(){ 42 alert('負け!');43 $('#bigimg').attr('src','images/mark_question.png')44 clearInterval(intervalId);45 },200);46 }else{47 const intervalId = setInterval(function(){ 48 alert('引き分け!');49 $('#bigimg').attr('src','images/mark_question.png')50 clearInterval(intervalId);51 },200);52 }53 }else if(enemyHand === 2){54 $('#bigimg').attr('src','images/janken_pa.png')55 if(myHand === 1){56 const intervalId = setInterval(function(){ 57 alert('勝ち!');58 $('#bigimg').attr('src','images/mark_question.png')59 clearInterval(intervalId);60 },200);61 }else if(myHand === 0){62 const intervalId = setInterval(function(){ 63 alert('負け!');64 $('#bigimg').attr('src','images/mark_question.png')65 clearInterval(intervalId);66 },200);67 }else{68 const intervalId = setInterval(function(){ 69 alert('引き分け!');70 $('#bigimg').attr('src','images/mark_question.png')71 clearInterval(intervalId);72 },200);73 }74 }75 }) ...

Full Screen

Full Screen

timer.js

Source:timer.js Github

copy

Full Screen

1/**2 * @author: myonov3 * @link: https://github.com/myonov/momentum4 */5(function () {6 var $momentum;7 function createWorker() {8 var containerFunction = function () {9 var idMap = {};10 self.onmessage = function (e) {11 if (e.data.type === 'setInterval') {12 idMap[e.data.id] = setInterval(function () {13 self.postMessage({14 type: 'fire',15 id: e.data.id16 });17 }, e.data.delay);18 } else if (e.data.type === 'clearInterval') {19 clearInterval(idMap[e.data.id]);20 delete idMap[e.data.id];21 } else if (e.data.type === 'setTimeout') {22 idMap[e.data.id] = setTimeout(function () {23 self.postMessage({24 type: 'fire',25 id: e.data.id26 });27 // remove reference to this timeout after is finished28 delete idMap[e.data.id];29 }, e.data.delay);30 } else if (e.data.type === 'clearCallback') {31 clearTimeout(idMap[e.data.id]);32 delete idMap[e.data.id];33 }34 };35 };36 return new Worker(URL.createObjectURL(new Blob([37 '(',38 containerFunction.toString(),39 ')();'40 ], {type: 'application/javascript'})));41 }42 $momentum = {43 worker: createWorker(),44 idToCallback: {},45 currentId: 046 };47 function generateId() {48 return $momentum.currentId++;49 }50 function patchedSetInterval(callback, delay) {51 var intervalId = generateId();52 $momentum.idToCallback[intervalId] = callback;53 $momentum.worker.postMessage({54 type: 'setInterval',55 delay: delay,56 id: intervalId57 });58 return intervalId;59 }60 function patchedClearInterval(intervalId) {61 $momentum.worker.postMessage({62 type: 'clearInterval',63 id: intervalId64 });65 delete $momentum.idToCallback[intervalId];66 }67 function patchedSetTimeout(callback, delay) {68 var intervalId = generateId();69 $momentum.idToCallback[intervalId] = function () {70 callback();71 delete $momentum.idToCallback[intervalId];72 };73 $momentum.worker.postMessage({74 type: 'setTimeout',75 delay: delay,76 id: intervalId77 });78 return intervalId;79 }80 function patchedClearTimeout(intervalId) {81 $momentum.worker.postMessage({82 type: 'clearInterval',83 id: intervalId84 });85 delete $momentum.idToCallback[intervalId];86 }87 $momentum.worker.onmessage = function (e) {88 if (e.data.type === 'fire') {89 $momentum.idToCallback[e.data.id]();90 }91 };92 window.$momentum = $momentum;93 window.setInterval = patchedSetInterval;94 window.clearInterval = patchedClearInterval;95 window.setTimeout = patchedSetTimeout;96 window.clearTimeout = patchedClearTimeout;...

Full Screen

Full Screen

momentum.js

Source:momentum.js Github

copy

Full Screen

1(function () {2 var $momentum;3 function createWorker() {4 var containerFunction = function () {5 var idMap = {};6 self.onmessage = function (e) {7 if (e.data.type === 'setInterval') {8 idMap[e.data.id] = setInterval(function () {9 self.postMessage({10 type: 'fire',11 id: e.data.id12 });13 }, e.data.delay);14 } else if (e.data.type === 'clearInterval') {15 clearInterval(idMap[e.data.id]);16 delete idMap[e.data.id];17 } else if (e.data.type === 'setTimeout') {18 idMap[e.data.id] = setTimeout(function () {19 self.postMessage({20 type: 'fire',21 id: e.data.id22 });23 // remove reference to this timeout after is finished24 delete idMap[e.data.id];25 }, e.data.delay);26 } else if (e.data.type === 'clearCallback') {27 clearTimeout(idMap[e.data.id]);28 delete idMap[e.data.id];29 }30 };31 };32 return new Worker(URL.createObjectURL(new Blob([33 '(',34 containerFunction.toString(),35 ')();'36 ], {type: 'application/javascript'})));37 }38 $momentum = {39 worker: createWorker(),40 idToCallback: {},41 currentId: 042 };43 function generateId() {44 return $momentum.currentId++;45 }46 function patchedSetInterval(callback, delay) {47 var intervalId = generateId();48 $momentum.idToCallback[intervalId] = callback;49 $momentum.worker.postMessage({50 type: 'setInterval',51 delay: delay,52 id: intervalId53 });54 return intervalId;55 }56 function patchedClearInterval(intervalId) {57 $momentum.worker.postMessage({58 type: 'clearInterval',59 id: intervalId60 });61 delete $momentum.idToCallback[intervalId];62 }63 function patchedSetTimeout(callback, delay) {64 var intervalId = generateId();65 $momentum.idToCallback[intervalId] = function () {66 callback();67 delete $momentum.idToCallback[intervalId];68 };69 $momentum.worker.postMessage({70 type: 'setTimeout',71 delay: delay,72 id: intervalId73 });74 return intervalId;75 }76 function patchedClearTimeout(intervalId) {77 $momentum.worker.postMessage({78 type: 'clearInterval',79 id: intervalId80 });81 delete $momentum.idToCallback[intervalId];82 }83 $momentum.worker.onmessage = function (e) {84 if (e.data.type === 'fire') {85 $momentum.idToCallback[e.data.id]();86 }87 };88 window.$momentum = $momentum;89 window.setInterval = patchedSetInterval;90 window.clearInterval = patchedClearInterval;91 window.setTimeout = patchedSetTimeout;92 window.clearTimeout = patchedClearTimeout;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { renderHook } from '@testing-library/react-hooks'2import useInterval from '../useInterval'3describe('useInterval', () => {4 it('should be defined', () => {5 expect(useInterval).toBeDefined()6 })7 it('should be a function', () => {8 expect(useInterval).toBeInstanceOf(Function)9 })10 it('should set interval', () => {11 const callback = jest.fn()12 const { result, unmount } = renderHook(() => useInterval(callback, 1000))13 expect(result.current).toBe(undefined)14 expect(callback).toHaveBeenCalledTimes(0)15 jest.advanceTimersByTime(1000)16 expect(callback).toHaveBeenCalledTimes(1)17 jest.advanceTimersByTime(1000)18 expect(callback).toHaveBeenCalledTimes(2)19 unmount()20 jest.advanceTimersByTime(1000)21 expect(callback).toHaveBeenCalledTimes(2)22 })23 it('should clear interval', () => {24 const callback = jest.fn()25 const { result, unmount } = renderHook(() => useInterval(callback, 1000))26 expect(result.current).toBe(undefined)27 expect(callback).toHaveBeenCalledTimes(0)28 jest.advanceTimersByTime(1000)29 expect(callback).toHaveBeenCalledTimes(1)30 unmount()31 jest.advanceTimersByTime(1000)32 expect(callback).toHaveBeenCalledTimes(1)33 })34})35import { useEffect, useRef } from 'react'36const useInterval = (callback, delay) => {37 const savedCallback = useRef()38 useEffect(() => {39 }, [callback])40 useEffect(() => {41 const tick = () => {42 savedCallback.current()43 }44 if (delay !== null) {45 const id = setInterval(tick, delay)46 return () => clearInterval(id)47 }48 }, [delay])49}50import { renderHook } from '@testing-library/react-hooks'51import useInterval from '../useInterval'52describe('useInterval', () => {53 it('should be defined', () => {54 expect(useInterval).toBeDefined()55 })56 it('should be a function', () => {57 expect(useInterval).toBeInstanceOf(Function)58 })59 it('should set interval', () => {60 const callback = jest.fn()61 const { result, unmount } = renderHook

Full Screen

Using AI Code Generation

copy

Full Screen

1import { renderHook, act } from '@testing-library/react-hooks'2import useCounter from './useCounter'3test('should increment counter', () => {4 const { result, rerender } = renderHook(() => useCounter())5 expect(result.current.count).toBe(0)6 act(() => {7 result.current.increment()8 })9 expect(result.current.count).toBe(1)10 rerender()11 expect(result.current.count).toBe(1)12})13import { useState } from 'react'14const useCounter = () => {15 const [count, setCount] = useState(0)16 const increment = () => {17 setCount(count + 1)18 }19 return {20 }21}22Then, you need to import the package in your tests and configure the adapter:23import Enzyme from 'enzyme'24import Adapter from 'enzyme-adapter-react-16'25import AdapterHooks from 'enzyme-adapter-react-hooks'26Enzyme.configure({ adapter: new Adapter() })27Enzyme.configure({ adapter: new AdapterHooks() })28import { shallow } from 'enzyme'29import useCounter from './useCounter'30describe('useCounter', () => {31 it('should increment counter', () => {32 const { result } = shallow(() => useCounter())33 expect(result.current.count).toBe(0)34 act(() => {35 result.current.increment()36 })

Full Screen

Using AI Code Generation

copy

Full Screen

1import { renderHook, act } from '@testing-library/react-hooks';2import { useInterval } from './useInterval';3test('should call callback every interval', () => {4 jest.useFakeTimers();5 const callback = jest.fn();6 const { result } = renderHook(() => useInterval(callback, 1000));7 act(() => {8 jest.advanceTimersByTime(1000);9 });10 expect(callback).toHaveBeenCalledTimes(1);11 act(() => {12 jest.advanceTimersByTime(1000);13 });14 expect(callback).toHaveBeenCalledTimes(2);15});16import { useEffect, useRef } from 'react';17export const useInterval = (callback, delay) => {18 const savedCallback = useRef();19 useEffect(() => {20 savedCallback.current = callback;21 }, [callback]);22 useEffect(() => {23 function tick() {24 savedCallback.current();25 }26 if (delay !== null) {27 let id = setInterval(tick, delay);28 return () => clearInterval(id);29 }30 }, [delay]);31};32export declare const useInterval: (callback: () => void, delay: number) => void;33{34 "compilerOptions": {35 },36}37{38 "dependencies": {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { renderHook, act } from '@testing-library/react-hooks';2import useInterval from './useInterval';3test('should set interval', () => {4 const { result, rerender } = renderHook(() => useInterval());5 const [intervalId] = result.current;6 expect(intervalId).toBeNull();7 rerender();8 expect(intervalId).toBeNull();9});10import { useState, useEffect } from 'react';11function useInterval() {12 const [intervalId, setIntervalId] = useState(null);13 useEffect(() => {14 setIntervalId(setInterval(() => {}, 1000));15 }, []);16 return [intervalId, setIntervalId];17}18export default useInterval;

Full Screen

Using AI Code Generation

copy

Full Screen

1import { renderHook } from "@testing-library/react-hooks";2import useInterval from "./useInterval";3describe("useInterval", () => {4 it("should call the callback after the specified delay", () => {5 jest.useFakeTimers();6 const callback = jest.fn();7 renderHook(() => useInterval(callback, 1000));8 expect(callback).not.toHaveBeenCalled();9 jest.advanceTimersByTime(1000);10 expect(callback).toHaveBeenCalledTimes(1);11 jest.advanceTimersByTime(1000);12 expect(callback).toHaveBeenCalledTimes(2);13 });14});15import { useEffect, useRef } from "react";16export default function useInterval(callback, delay) {17 const savedCallback = useRef();18 useEffect(() => {19 savedCallback.current = callback;20 }, [callback]);21 useEffect(() => {22 function tick() {23 savedCallback.current();24 }25 if (delay !== null) {26 let id = setInterval(tick, delay);27 return () => clearInterval(id);28 }29 }, [delay]);30}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { renderHook, act } from '@testing-library/react-hooks'2import useInterval from './useInterval'3test('useInterval', () => {4 const { result } = renderHook(() => useInterval())5 expect(result.current).toBe(0)6 act(() => {7 jest.advanceTimersByTime(1000)8 })9 expect(result.current).toBe(1)10 act(() => {11 jest.advanceTimersByTime(1000)12 })13 expect(result.current).toBe(2)14})15import { useState, useEffect, useRef } from 'react'16const useInterval = () => {17 const [count, setCount] = useState(0)18 const intervalId = useRef(null)19 useEffect(() => {20 intervalId.current = setInterval(() => {21 setCount(prevCount => prevCount + 1)22 }, 1000)23 return () => clearInterval(intervalId.current)24 }, [])25}26import { renderHook } from '@testing-library/react-hooks'27import useInterval from './useInterval'28test('useInterval', () => {29 const { result, rerender } = renderHook(() => useInterval())30 expect(result.current).toBe(0)31 rerender()32 expect(result.current).toBe(1)33 rerender()34 expect(result.current).toBe(2)35})36import { useState, useEffect, useRef } from 'react'37const useInterval = () => {38 const [count, setCount] = useState(0)39 const intervalId = useRef(null)40 useEffect(() => {41 intervalId.current = setInterval(() => {42 setCount(prevCount => prevCount + 1)43 }, 1000)44 return () => clearInterval(intervalId.current)45 }, [])46}47import { renderHook

Full Screen

Using AI Code Generation

copy

Full Screen

1import {renderHook, act} from '@testing-library/react-hooks';2import useInterval from './useInterval';3describe('useInterval', () => {4 const delay = 100;5 const callback = jest.fn();6 test('should call callback function after delay', () => {7 const {result} = renderHook(() => useInterval(callback, delay));8 expect(callback).toHaveBeenCalledTimes(1);9 act(() => {10 jest.advanceTimersByTime(delay);11 });12 expect(callback).toHaveBeenCalledTimes(2);13 });14 test('should not call callback function after delay if isRunning is false', () => {15 const {result} = renderHook(() => useInterval(callback, delay));16 expect(callback).toHaveBeenCalledTimes(1);17 act(() => {18 jest.advanceTimersByTime(delay);19 });20 expect(callback).toHaveBeenCalledTimes(2);21 act(() => {22 result.current.stop();23 });24 act(() => {25 jest.advanceTimersByTime(delay);26 });27 expect(callback).toHaveBeenCalledTimes(2);28 });29 test('should call callback function after delay if isRunning is true', () => {30 const {result} = renderHook(() => useInterval(callback, delay));31 expect(callback).toHaveBeenCalledTimes(1);32 act(() => {33 jest.advanceTimersByTime(delay);34 });35 expect(callback).toHaveBeenCalledTimes(2);36 act(() => {37 result.current.stop();38 });39 act(() => {40 jest.advanceTimersByTime(delay);41 });42 expect(callback).toHaveBeenCalledTimes(2);43 act(() => {44 result.current.start();45 });46 act(() => {47 jest.advanceTimersByTime(delay);48 });49 expect(callback).toHaveBeenCalledTimes(3);50 });51 test('should not call callback function after delay if isRunning is false', () => {52 const {result} = renderHook(() => useInterval(callback, delay));53 expect(callback).toHaveBeenCalledTimes(1);54 act(() => {55 jest.advanceTimersByTime(delay);56 });57 expect(callback).toHaveBeenCalledTimes(2);58 act(() => {59 result.current.stop();60 });61 act(() => {62 jest.advanceTimersByTime(delay);63 });64 expect(callback).toHaveBeenCalledTimes(2);65 act(() => {66 result.current.start();67 });68 act(() => {69 jest.advanceTimersByTime(delay);70 });71 expect(callback).toHaveBeenCalledTimes(3);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { renderHook, act } from "@testing-library/react-hooks";2import { useInterval } from "../useInterval";3describe("useInterval", () => {4 it("should call the callback function after the specified time", () => {5 jest.useFakeTimers();6 const callback = jest.fn();7 const { result } = renderHook(() => useInterval(callback, 1000));8 act(() => {9 jest.advanceTimersByTime(1000);10 });11 expect(callback).toHaveBeenCalledTimes(1);12 });13});14const useInterval = (callback, delay) => {15 const savedCallback = useRef();16 useEffect(() => {17 savedCallback.current = callback;18 }, [callback]);19 useEffect(() => {20 function tick() {21 savedCallback.current();22 }23 if (delay !== null) {24 let id = setInterval(tick, delay);25 return () => clearInterval(id);26 }27 }, [delay]);28};29export default useInterval;30import { renderHook, act } from "@testing-library/react-hooks";31import { useInterval } from "./useInterval";32describe("useInterval", () => {33 it("should call the callback function after the specified time", () => {34 jest.useFakeTimers();35 const callback = jest.fn();36 const { result } = renderHook(() => useInterval(callback, 1000));37 act(() => {38 jest.advanceTimersByTime(1000);39 });40 expect(callback).toHaveBeenCalledTimes(1);41 });42});43const useInterval = (callback, delay) => {44 const savedCallback = useRef();45 useEffect(() => {46 savedCallback.current = callback;47 }, [callback]);48 useEffect(() => {49 function tick() {50 savedCallback.current();51 }52 if (delay !== null) {53 let id = setInterval(tick, delay);54 return () => clearInterval(id);55 }56 }, [delay]);57};58export default useInterval;59import { renderHook, act } from "@testing-library/react-hooks";60import { useInterval } from "./useInterval";61describe("useInterval", () =>

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run testing-library-react-hooks automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful