Skip to content

Commit

Permalink
style: $ npm run format
Browse files Browse the repository at this point in the history
  • Loading branch information
progfay committed Jun 13, 2020
1 parent 6e0d516 commit e1e5d49
Show file tree
Hide file tree
Showing 44 changed files with 414 additions and 231 deletions.
5 changes: 1 addition & 4 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
"@babel/preset-env",
{
"targets": {
"browsers": [
"last 2 versions",
"Safari 10"
]
"browsers": ["last 2 versions", "Safari 10"]
},
"useBuiltIns": "usage",
"corejs": 3
Expand Down
34 changes: 14 additions & 20 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
module.exports = {
'env': {
"jest/globals": true,
'browser': true,
'es6': true
env: {
'jest/globals': true,
browser: true,
es6: true
},
'extends': [
'standard',
'standard-with-typescript'
],
'globals': {
'Atomics': 'readonly',
'SharedArrayBuffer': 'readonly'
extends: ['standard', 'standard-with-typescript'],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly'
},
'parser': '@typescript-eslint/parser',
'parserOptions': {
'ecmaVersion': 2018,
'sourceType': 'module',
'project': './tsconfig.eslint.json'
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
project: './tsconfig.eslint.json'
},
'plugins': [
'@typescript-eslint',
'jest'
]
plugins: ['@typescript-eslint', 'jest']
}
26 changes: 13 additions & 13 deletions .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ appearance, race, religion, or sexual identity and orientation.
Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
- The use of sexualized language or imagery and unwelcome sexual attention or
advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic
address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Expand Down
18 changes: 10 additions & 8 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand All @@ -24,15 +24,17 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
3 changes: 0 additions & 3 deletions .github/ISSUE_TEMPLATE/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@ about: Describe this issue template's purpose here.
title: ''
labels: ''
assignees: ''

---


1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
Expand Down
3 changes: 1 addition & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
## Proposed Changes

-

-
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ parse Scrapbox notation to JavaScript Object
$ npm i @progfay/scrapbox-parser
```


## Usage

```js
Expand All @@ -21,7 +20,6 @@ const PROJECT_NAME = 'help'
const PAGE_NAME = 'syntax'

fetch(`https://scrapbox.io/api/pages/${PROJECT_NAME}/${PAGE_NAME}/text`)
.then(response => response.text())
.then(text => parse(text))
.then((response) => response.text())
.then((text) => parse(text))
```

17 changes: 4 additions & 13 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
module.exports = {
moduleFileExtensions: [
'ts',
'js'
],
moduleFileExtensions: ['ts', 'js'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest'
},
Expand All @@ -11,13 +8,7 @@ module.exports = {
tsConfig: 'tsconfig.json'
}
},
collectCoverageFrom: [
'src/**/*.ts'
],
setupFilesAfterEnv: [
'./tests/jest-setup.ts'
],
testMatch: [
'**/tests/**/*.test.ts'
]
collectCoverageFrom: ['src/**/*.ts'],
setupFilesAfterEnv: ['./tests/jest-setup.ts'],
testMatch: ['**/tests/**/*.test.ts']
}
4 changes: 1 addition & 3 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"extends": [
"config:base"
]
"extends": ["config:base"]
}
3 changes: 1 addition & 2 deletions src/block/BlockComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ export const convertToBlockComponent = (block: string): BlockComponent => ({
text: block
})

export const convertToBlockComponents = (blocks: string): BlockComponent[] => (
export const convertToBlockComponents = (blocks: string): BlockComponent[] =>
blocks.split('\n').map(convertToBlockComponent)
)
13 changes: 9 additions & 4 deletions src/block/CodeBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ export interface CodeBlock {
content: string
}

export const isCodeBlockComponent = (packedBlockComponent: PackedBlockComponent): packedBlockComponent is CodeBlockComponent => (
export const isCodeBlockComponent = (
packedBlockComponent: PackedBlockComponent
): packedBlockComponent is CodeBlockComponent =>
packedBlockComponent.type === 'codeBlock'
)

export const convertToCodeBlock = (blockComponent: CodeBlockComponent): CodeBlock => {
export const convertToCodeBlock = (
blockComponent: CodeBlockComponent
): CodeBlock => {
const { components } = blockComponent
const [head, ...body] = components
const { indent, text } = head
Expand All @@ -28,7 +31,9 @@ export const convertToCodeBlock = (blockComponent: CodeBlockComponent): CodeBloc
type: 'codeBlock',
fileName,
content: body
.map((component: BlockComponent): string => component.text.substring(indent + 1))
.map((component: BlockComponent): string =>
component.text.substring(indent + 1)
)
.join('\n')
}
}
25 changes: 16 additions & 9 deletions src/block/PackedBlockComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ import type { CodeBlockComponent } from './CodeBlock'
import type { TableComponent } from './Table'
import type { LineComponent } from './Line'

export type PackedBlockComponent = TitleComponent | CodeBlockComponent | TableComponent | LineComponent
export type PackedBlockComponent =
| TitleComponent
| CodeBlockComponent
| TableComponent
| LineComponent

export const packBlockComponents = (blockComponents: BlockComponent[], { hasTitle }: ParserOption): PackedBlockComponent[] => {
export const packBlockComponents = (
blockComponents: BlockComponent[],
{ hasTitle }: ParserOption
): PackedBlockComponent[] => {
if (hasTitle) {
const [title, ...body] = blockComponents
return [
Expand All @@ -20,7 +27,9 @@ export const packBlockComponents = (blockComponents: BlockComponent[], { hasTitl
}

const packedBlockComponents: PackedBlockComponent[] = []
let packingComponent: ((CodeBlockComponent | TableComponent) & { indent: number }) | null = null
let packingComponent:
| ((CodeBlockComponent | TableComponent) & { indent: number })
| null = null

for (const blockComponent of blockComponents) {
const { indent, text } = blockComponent
Expand All @@ -43,12 +52,10 @@ export const packBlockComponents = (blockComponents: BlockComponent[], { hasTitl
indent
}
} else {
packedBlockComponents.push(
{
type: 'line',
component: blockComponent
}
)
packedBlockComponents.push({
type: 'line',
component: blockComponent
})
}
}

Expand Down
19 changes: 12 additions & 7 deletions src/block/Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export interface Table {
cells: LineNode[][][]
}

export const isTableComponent = (component: PackedBlockComponent): component is TableComponent => (
component.type === 'table'
)
export const isTableComponent = (
component: PackedBlockComponent
): component is TableComponent => component.type === 'table'

export const convertToTable = (tableComponent: TableComponent): Table => {
const { components } = tableComponent
Expand All @@ -31,10 +31,15 @@ export const convertToTable = (tableComponent: TableComponent): Table => {
type: 'table',
fileName,
cells: body
.map((blockComponent: BlockComponent): string => blockComponent.text.substring(indent + 1))
.map((text: string): LineNode[][] => text
.split('\t')
.map((block: string): LineNode[] => convertToLineNodes(block, { nested: true, quoted: false }))
.map((blockComponent: BlockComponent): string =>
blockComponent.text.substring(indent + 1)
)
.map((text: string): LineNode[][] =>
text
.split('\t')
.map((block: string): LineNode[] =>
convertToLineNodes(block, { nested: true, quoted: false })
)
)
}
}
6 changes: 3 additions & 3 deletions src/block/Title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export interface Title {
text: string
}

export const isTitleComponent = (component: PackedBlockComponent): component is TitleComponent => (
component.type === 'title'
)
export const isTitleComponent = (
component: PackedBlockComponent
): component is TitleComponent => component.type === 'title'

export const convertToTitle = (blockComponent: TitleComponent): Title => {
return {
Expand Down
10 changes: 6 additions & 4 deletions src/block/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import type { Line } from './Line'

export type Block = Title | CodeBlock | Table | Line

export const convertToBlock = (packedBlockComponent: PackedBlockComponent): Block => {
if (isTitleComponent(packedBlockComponent)) return convertToTitle(packedBlockComponent)
if (isCodeBlockComponent(packedBlockComponent)) return convertToCodeBlock(packedBlockComponent)
if (isTableComponent(packedBlockComponent)) return convertToTable(packedBlockComponent)
export const convertToBlock = (
packedBlockComponent: PackedBlockComponent
): Block => {
if (isTitleComponent(packedBlockComponent)) { return convertToTitle(packedBlockComponent) }
if (isCodeBlockComponent(packedBlockComponent)) { return convertToCodeBlock(packedBlockComponent) }
if (isTableComponent(packedBlockComponent)) { return convertToTable(packedBlockComponent) }
return convertToLine(packedBlockComponent)
}
Loading

0 comments on commit e1e5d49

Please sign in to comment.