-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
'To Braille' and 'From Braille' operations added. Closes #255
- Loading branch information
Showing
5 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Braille resources. | ||
* | ||
* @author n1474335 [[email protected]] | ||
* @copyright Crown Copyright 2018 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
/** | ||
* Braille lookup table. | ||
*/ | ||
export const BRAILLE_LOOKUP = { | ||
ascii: " A1B'K2L@CIF/MSP\"E3H9O6R^DJG>NTQ,*5<-U8V.%[$+X!&;:4\\0Z7(_?W]#Y)=", | ||
dot6: "⠀⠁⠂⠃⠄⠅⠆⠇⠈⠉⠊⠋⠌⠍⠎⠏⠐⠑⠒⠓⠔⠕⠖⠗⠘⠙⠚⠛⠜⠝⠞⠟⠠⠡⠢⠣⠤⠥⠦⠧⠨⠩⠪⠫⠬⠭⠮⠯⠰⠱⠲⠳⠴⠵⠶⠷⠸⠹⠺⠻⠼⠽⠾⠿" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* @author n1474335 [[email protected]] | ||
* @copyright Crown Copyright 2018 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation"; | ||
import {BRAILLE_LOOKUP} from "../lib/Braille"; | ||
|
||
/** | ||
* From Braille operation | ||
*/ | ||
class FromBraille extends Operation { | ||
|
||
/** | ||
* FromBraille constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "From Braille"; | ||
this.module = "Default"; | ||
this.description = "Converts six-dot braille symbols to text."; | ||
this.infoURL = "https://wikipedia.org/wiki/Braille"; | ||
this.inputType = "string"; | ||
this.outputType = "string"; | ||
this.args = []; | ||
} | ||
|
||
/** | ||
* @param {string} input | ||
* @param {Object[]} args | ||
* @returns {string} | ||
*/ | ||
run(input, args) { | ||
return input.split("").map(b => { | ||
const idx = BRAILLE_LOOKUP.dot6.indexOf(b); | ||
return idx < 0 ? b : BRAILLE_LOOKUP.ascii[idx]; | ||
}).join(""); | ||
} | ||
|
||
/** | ||
* Highlight From Braille | ||
* | ||
* @param {Object[]} pos | ||
* @param {number} pos[].start | ||
* @param {number} pos[].end | ||
* @param {Object[]} args | ||
* @returns {Object[]} pos | ||
*/ | ||
highlight(pos, args) { | ||
return pos; | ||
} | ||
|
||
/** | ||
* Highlight From Braille in reverse | ||
* | ||
* @param {Object[]} pos | ||
* @param {number} pos[].start | ||
* @param {number} pos[].end | ||
* @param {Object[]} args | ||
* @returns {Object[]} pos | ||
*/ | ||
highlightReverse(pos, args) { | ||
return pos; | ||
} | ||
|
||
} | ||
|
||
export default FromBraille; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* @author n1474335 [[email protected]] | ||
* @copyright Crown Copyright 2018 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation"; | ||
import {BRAILLE_LOOKUP} from "../lib/Braille"; | ||
|
||
/** | ||
* To Braille operation | ||
*/ | ||
class ToBraille extends Operation { | ||
|
||
/** | ||
* ToBraille constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "To Braille"; | ||
this.module = "Default"; | ||
this.description = "Converts text to six-dot braille symbols."; | ||
this.infoURL = "https://wikipedia.org/wiki/Braille"; | ||
this.inputType = "string"; | ||
this.outputType = "string"; | ||
this.args = []; | ||
} | ||
|
||
/** | ||
* @param {string} input | ||
* @param {Object[]} args | ||
* @returns {string} | ||
*/ | ||
run(input, args) { | ||
return input.split("").map(c => { | ||
const idx = BRAILLE_LOOKUP.ascii.indexOf(c.toUpperCase()); | ||
return idx < 0 ? c : BRAILLE_LOOKUP.dot6[idx]; | ||
}).join(""); | ||
} | ||
|
||
/** | ||
* Highlight To Braille | ||
* | ||
* @param {Object[]} pos | ||
* @param {number} pos[].start | ||
* @param {number} pos[].end | ||
* @param {Object[]} args | ||
* @returns {Object[]} pos | ||
*/ | ||
highlight(pos, args) { | ||
return pos; | ||
} | ||
|
||
/** | ||
* Highlight To Braille in reverse | ||
* | ||
* @param {Object[]} pos | ||
* @param {number} pos[].start | ||
* @param {number} pos[].end | ||
* @param {Object[]} args | ||
* @returns {Object[]} pos | ||
*/ | ||
highlightReverse(pos, args) { | ||
return pos; | ||
} | ||
|
||
} | ||
|
||
export default ToBraille; |