From b0c22a222e09ef8008a1ef7cf79e28b73961560a Mon Sep 17 00:00:00 2001 From: August Skare Date: Tue, 20 Nov 2018 15:15:17 +0100 Subject: use lodash.map insted of array.map --- .../dev-tools-pages/ts/components/compiler.tsx | 3 +- packages/dev-tools-pages/ts/components/footer.tsx | 3 +- packages/dev-tools-pages/ts/components/list.tsx | 3 +- packages/dev-tools-pages/ts/highlight.tsx | 36 ++++++++++------------ 4 files changed, 23 insertions(+), 22 deletions(-) (limited to 'packages') diff --git a/packages/dev-tools-pages/ts/components/compiler.tsx b/packages/dev-tools-pages/ts/components/compiler.tsx index c535795aa..d576e3b72 100644 --- a/packages/dev-tools-pages/ts/components/compiler.tsx +++ b/packages/dev-tools-pages/ts/components/compiler.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import styled from 'styled-components'; +import * as _ from 'lodash'; import { colors, media } from 'ts/variables'; @@ -75,7 +76,7 @@ const Compiler: React.StatelessComponent<{}> = () => ( - {cards.map(card => ( + {_.map(cards, card => (
{card.title}
{card.body}
diff --git a/packages/dev-tools-pages/ts/components/footer.tsx b/packages/dev-tools-pages/ts/components/footer.tsx index 110d21443..4b911ce35 100644 --- a/packages/dev-tools-pages/ts/components/footer.tsx +++ b/packages/dev-tools-pages/ts/components/footer.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import styled from 'styled-components'; +import * as _ from 'lodash'; import { context as compiler } from 'ts/context/compiler'; import { context as cov } from 'ts/context/cov'; @@ -19,7 +20,7 @@ const Footer: React.StatelessComponent<{}> = () => ( Other tools by 0x - {tools.map(({ title, subtitle, icon }) => ( + {_.map(tools, ({ title, subtitle, icon }) => ( diff --git a/packages/dev-tools-pages/ts/components/list.tsx b/packages/dev-tools-pages/ts/components/list.tsx index 12d5d67a9..6d4839e88 100644 --- a/packages/dev-tools-pages/ts/components/list.tsx +++ b/packages/dev-tools-pages/ts/components/list.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import styled from 'styled-components'; +import * as _ from 'lodash'; import { media } from 'ts/variables'; @@ -42,7 +43,7 @@ const List: React.StatelessComponent = props => ( {props.children !== undefined ? props.children - : props.items.map((bullet, index) => {bullet})} + : _.map(props.items, (bullet, index) => {bullet})} ); 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 `${ - hljs.highlight(language, currentLine).value - }`; - }) - .join('\n'); + return `${ + hljs.highlight(language, currentLine).value + }`; + }).join('\n'); } interface HighlightProps { -- cgit v1.2.3