Skip to content
This repository was archived by the owner on Dec 6, 2019. It is now read-only.

ci(all): upgrade to babel 7 and typescript #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": ["flow", "env"],
"presets": ["@babel/preset-typescript", "@babel/env"],
"plugins": [
["module-resolver", {
"root": ["./src"],
Expand Down
28 changes: 18 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
"author": "Felix Wu",
"license": "MIT",
"devDependencies": {
"babel-cli": "^6.26.0",
"@babel/cli": "^7.6.2",
"@babel/core": "^7.6.2",
"@babel/preset-env": "^7.6.2",
"@babel/preset-typescript": "^7.6.0",
"@types/jest": "^24.0.18",
"@types/node": "^12.7.11",
"babel-jest": "^24.9.0",
"babel-plugin-module-resolver": "^3.1.1",
"babel-preset-env": "^1.7.0",
"babel-preset-flow": "^6.23.0",
"flow-bin": "^0.77.0",
"jest": "^23.4.2"
"jest": "^24.9.0",
"ts-jest": "^24.1.0"
},
"keywords": [
"markdown",
Expand All @@ -25,19 +29,23 @@
],
"scripts": {
"build": "babel src/ -d lib/",
"test": "jest",
"flow": "flow check"
"test": "jest"
},
"jest": {
"verbose": true,
"testEnvironment": "node",
"testMatch": [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[jt]s?(x)"
],
"transform": {
"^.+\\.js$": "babel-jest"
"^.+\\.ts$": "babel-jest"
},
"globals": {
"NODE_ENV": "test"
},
"moduleFileExtensions": [
"ts",
"js"
],
"moduleDirectories": [
Expand All @@ -51,7 +59,7 @@
},
"husky": {
"hooks": {
"pre-push": "yarn flow && yarn test"
"pre-push": "yarn test"
}
}
}
}
13 changes: 6 additions & 7 deletions src/components/emphasis.js → src/components/emphasis.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
/**
* Markdown Emphasis utilities
* @flow
*/

import { surround } from '../util';
import {
EMPHASIS_ITALICS,
EMPHASIS_BOLD,
EMPHASIS_STRIKETHROUGH,
EMPHASIS_ITALICS,
EMPHASIS_BOLD,
EMPHASIS_STRIKETHROUGH
} from '../util/constants';

/**
* Produces italic text
* @param {string} text
* @param {string} text
*/
const i = (text: string): string => surround(EMPHASIS_ITALICS, text);

/**
* Produces bold text
* @param {string} text
* @param {string} text
*/
const b = (text: string): string => surround(EMPHASIS_BOLD, text);

/**
* Produces strikethroughed text
* @param {string} text
* @param {string} text
*/
const s = (text: string): string => surround(EMPHASIS_STRIKETHROUGH, text);

Expand Down
13 changes: 7 additions & 6 deletions src/components/headers.js → src/components/headers.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
/**
* Markdown Header utilities
* @flow
*/

import { HEADER_PREFIX, withPrefix, SECTION_LINE_BREAK } from '../util';

/**
* Header of specific level
* @param {number} headerLevel
* @param {string} text
* @param {number} headerLevel
* @param {string} text
*/
const hX = (headerLevel: number, text: string): string =>
headerLevel > 6
? h6(text)
: SECTION_LINE_BREAK + withPrefix(HEADER_PREFIX.repeat(headerLevel), text) + SECTION_LINE_BREAK;
headerLevel > 6
? h6(text)
: SECTION_LINE_BREAK +
withPrefix(HEADER_PREFIX.repeat(headerLevel), text) +
SECTION_LINE_BREAK;

const h1 = (text: string): string => hX(1, text);
const h2 = (text: string): string => hX(2, text);
Expand Down
File renamed without changes.
35 changes: 0 additions & 35 deletions src/components/lists.js

This file was deleted.

34 changes: 34 additions & 0 deletions src/components/lists.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Markdown Lists utilities
*/

import { UNORDERED_LIST_PREFIX, withPrefix } from '../util';

const ul = (items: Array<any>, callback: Function): string => {
let list = '';
for (let val of items) {
if (callback) {
list += withPrefix(UNORDERED_LIST_PREFIX, callback(val)) + '\n';
} else {
list += withPrefix(UNORDERED_LIST_PREFIX, val) + '\n';
}
}
return list;
};

const ol = (items: Array<any>, callback: Function): string => {
let list = '';
let counter = 1;

for (let val of items) {
if (callback) {
list += withPrefix(`${counter}.`, callback(val)) + '\n';
} else {
list += withPrefix(`${counter}.`, val) + '\n';
}
counter++;
}
return list;
};

export { ul, ol };
43 changes: 0 additions & 43 deletions src/components/misc.js

This file was deleted.

45 changes: 45 additions & 0 deletions src/components/misc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Misc
*/

import { HORIZONTAL_RULE, SECTION_LINE_BREAK, surround } from '../util';

const hr = () => surround(SECTION_LINE_BREAK, HORIZONTAL_RULE);

const collapsible = (summary: string, content: string) =>
SECTION_LINE_BREAK +
`
<details>
<summary>${summary}</summary>

${content}
</details>
`;

const anchor = (val: string) => {
const re = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g;
const replacement = '-';
const whitespace = /\s/g;

if (typeof val !== 'string') return '';
const anchor = val.replace(/[A-Z]+/g, str => str.toLowerCase());
return (
'#' +
anchor
.trim()
.replace(re, '')
.replace(whitespace, replacement)
);
};

const link = (title: string, url: string | null = null) => {
if (url === null) {
url = anchor(title);
}
return `[${title}](${url})`;
};

const image = (alt: string, url: string, title: string = '') =>
`![${alt}](${url}${title !== '' ? ` "${title}"` : ''})`;

export { hr, collapsible, anchor, link, image };
File renamed without changes.
17 changes: 8 additions & 9 deletions src/util/constants.js → src/util/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* Constants
* @flow
*/

const HEADER_PREFIX: string = '#';
Expand All @@ -17,12 +16,12 @@ const SECTION_LINE_BREAK = '\n';
const HORIZONTAL_RULE = '---';

export {
HEADER_PREFIX,
EMPHASIS_ITALICS,
EMPHASIS_BOLD,
EMPHASIS_STRIKETHROUGH,
UNORDERED_LIST_PREFIX,
LINE_BREAK,
SECTION_LINE_BREAK,
HORIZONTAL_RULE
HEADER_PREFIX,
EMPHASIS_ITALICS,
EMPHASIS_BOLD,
EMPHASIS_STRIKETHROUGH,
UNORDERED_LIST_PREFIX,
LINE_BREAK,
SECTION_LINE_BREAK,
HORIZONTAL_RULE
};
1 change: 0 additions & 1 deletion src/util/helpers.js → src/util/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* Utility functions & helpers
* @flow
*/

const withPrefix = (prefix: string, text: string) => prefix + ' ' + text;
Expand Down
File renamed without changes.
Loading