morse-player
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -5,2 +5,3 @@ export declare function set(value: Record<string, any>): Record<string, any>; | ||
export declare function scramble(action: Record<string, any>): string[]; | ||
export declare function callsign(action: Record<string, any>): string; | ||
export declare function states(): string[]; | ||
@@ -10,2 +11,1 @@ export declare function letters(): string[]; | ||
export declare function alphanumeric(): string[]; | ||
export declare function callsign(min: number, max: number): string; |
@@ -1,6 +0,5 @@ | ||
import { scrambleList, randomEntry, toList, toNumber, countMap } from './utils'; | ||
import { scrambleList, randomEntry, randCallsign, toList, toNumber, countMap } from './utils'; | ||
import { states as stateList } from '../resources/states'; | ||
import { letters as letterList } from '../resources/letters'; | ||
import { numbers as numberList } from '../resources/numbers'; | ||
import { ALPHA, NUMERIC, CALLSIGN_FORMATS } from '../resources/lists'; | ||
export function set(value) { | ||
@@ -37,2 +36,7 @@ return value; | ||
} | ||
export function callsign(action) { | ||
const min = parseInt(action.min, 10) || 0; | ||
const max = parseInt(action.max, 10) || 0; | ||
return randCallsign(min, max); | ||
} | ||
export function states() { | ||
@@ -51,9 +55,1 @@ return stateList.map(state => state.value.toLowerCase()); | ||
} | ||
export function callsign(min, max) { | ||
return randomEntry(CALLSIGN_FORMATS.filter(format => format.length >= min && format.length <= max)) | ||
.split('') | ||
.map(format => randomEntry(format === 'L' | ||
? ALPHA | ||
: NUMERIC)) | ||
.join(''); | ||
} |
@@ -73,6 +73,9 @@ import { CALLSIGN_FORMATS, ALPHA, NUMERIC } from "../resources/lists"; | ||
} | ||
return randomEntry(CALLSIGN_FORMATS.filter(format => format.length >= min && format.length <= max)) | ||
return randomEntry(CALLSIGN_FORMATS.filter(format => format.length >= min | ||
&& format.length <= max)) | ||
.split('') | ||
.map(format => randomEntry(format === 'L' ? ALPHA : NUMERIC)) | ||
.map(format => randomEntry(format === 'L' | ||
? ALPHA : | ||
NUMERIC)) | ||
.join(''); | ||
} |
@@ -71,2 +71,14 @@ import { describe, expect, test } from '@jest/globals'; | ||
}); | ||
test('renders: [callsign min:? max:?]', () => { | ||
const v1 = render('[callsign min:3 max:6]').join(''); | ||
expect(v1.length).toBeGreaterThanOrEqual(3); | ||
expect(v1.length).toBeLessThanOrEqual(6); | ||
expect(v1).toMatch(/^[A-Z]{1,2}\d[A-Z]{1,3}$/); | ||
const v2 = render('[callsign min:3 max:3]').join(''); | ||
expect(v2.length).toEqual(3); | ||
expect(v2).toMatch(/^[A-Z]{1}\d[A-Z]{1}$/); | ||
const v3 = render('[callsign min:6 max:6]').join(''); | ||
expect(v3.length).toEqual(6); | ||
expect(v3).toMatch(/^[A-Z]{2}\d[A-Z]{3}$/); | ||
}); | ||
}); |
{ | ||
"name": "morse-player", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Browser morse code audio player", | ||
@@ -5,0 +5,0 @@ "author": "Andrew Bunker", |
239991
3531