aboutsummaryrefslogtreecommitdiffstats
path: root/packages/dev-tools-pages/ts/highlight.tsx
diff options
context:
space:
mode:
authorAugust Skare <post@augustskare.no>2018-11-20 22:15:17 +0800
committerAugust Skare <post@augustskare.no>2018-11-20 22:15:17 +0800
commitb0c22a222e09ef8008a1ef7cf79e28b73961560a (patch)
treefb98563e385620607b962f1ef0726676fd2c29dd /packages/dev-tools-pages/ts/highlight.tsx
parentea1805058924e12a18bcc4f9de712bfade64c595 (diff)
downloaddexon-sol-tools-b0c22a222e09ef8008a1ef7cf79e28b73961560a.tar
dexon-sol-tools-b0c22a222e09ef8008a1ef7cf79e28b73961560a.tar.gz
dexon-sol-tools-b0c22a222e09ef8008a1ef7cf79e28b73961560a.tar.bz2
dexon-sol-tools-b0c22a222e09ef8008a1ef7cf79e28b73961560a.tar.lz
dexon-sol-tools-b0c22a222e09ef8008a1ef7cf79e28b73961560a.tar.xz
dexon-sol-tools-b0c22a222e09ef8008a1ef7cf79e28b73961560a.tar.zst
dexon-sol-tools-b0c22a222e09ef8008a1ef7cf79e28b73961560a.zip
use lodash.map insted of array.map
Diffstat (limited to 'packages/dev-tools-pages/ts/highlight.tsx')
-rw-r--r--packages/dev-tools-pages/ts/highlight.tsx36
1 files changed, 17 insertions, 19 deletions
diff --git a/packages/dev-tools-pages/ts/highlight.tsx b/packages/dev-tools-pages/ts/highlight.tsx
index cef03904a..02f4a753e 100644
--- a/packages/dev-tools-pages/ts/highlight.tsx
+++ b/packages/dev-tools-pages/ts/highlight.tsx
@@ -1,6 +1,7 @@
import * as hljs from 'highlight.js/lib/highlight';
import * as javascript from 'highlight.js/lib/languages/javascript';
import * as json from 'highlight.js/lib/languages/json';
+import * as _ from 'lodash';
hljs.registerLanguage('javascript', javascript);
hljs.registerLanguage('json', json);
@@ -16,28 +17,25 @@ const PATCH_TYPES: PatchInterface = {
};
function diffHighlight(language: string, code: any, gutter: any): string {
- return code
- .split(/\r?\n/g)
- .map((line: string, index: number) => {
- let type;
- let currentLine = line;
+ return _.map(code.split(/\r?\n/g), (line: string, index: number) => {
+ let type;
+ let currentLine = line;
- if (/^-{3} [^-]+ -{4}$|^\*{3} [^*]+ \*{4}$|^@@ [^@]+ @@$/.test(currentLine)) {
- type = 'chunk';
- } else if (/^Index: |^[+\-*]{3}|^[*=]{5,}$/.test(currentLine)) {
- type = 'header';
- } else {
- type = PATCH_TYPES[currentLine[0]] || 'null';
- currentLine = currentLine.replace(/^[+\-! ]/, '');
- }
+ if (/^-{3} [^-]+ -{4}$|^\*{3} [^*]+ \*{4}$|^@@ [^@]+ @@$/.test(currentLine)) {
+ type = 'chunk';
+ } else if (/^Index: |^[+\-*]{3}|^[*=]{5,}$/.test(currentLine)) {
+ type = 'header';
+ } else {
+ type = PATCH_TYPES[currentLine[0]] || 'null';
+ currentLine = currentLine.replace(/^[+\-! ]/, '');
+ }
- const g = gutter[index];
+ const g = gutter[index];
- return `<span data-gutter="${g !== undefined ? `${g}x` : ''}" class="line-${type}">${
- hljs.highlight(language, currentLine).value
- }</span>`;
- })
- .join('\n');
+ return `<span data-gutter="${g !== undefined ? `${g}x` : ''}" class="line-${type}">${
+ hljs.highlight(language, currentLine).value
+ }</span>`;
+ }).join('\n');
}
interface HighlightProps {