Skip to content

Commit

Permalink
chore: Cleanup and prettify
Browse files Browse the repository at this point in the history
  • Loading branch information
henningmu committed Nov 30, 2021
1 parent e75ffd1 commit 1f01072
Show file tree
Hide file tree
Showing 26 changed files with 1,823 additions and 5,514 deletions.
22 changes: 22 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"plugins": ["import"],
"extends": [
"eslint:recommended",
"plugin:prettier/recommended",
"plugin:import/recommended",
"@doist/eslint-config/react"
],
"env": {
"browser": true,
"jest": true
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true,
"impliedStrict": true
},
"sourceType": "module"
},
"parser": "@babel/eslint-parser",
"settings": { "react": { "version": "detect" } }
}
35 changes: 0 additions & 35 deletions .eslintrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
with:
node-version: ${{ steps.nvmrc.outputs.NODE_VERSION }}
registry-url: https://npm.pkg.github.com/
scope: "@doist"
scope: '@doist'
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
Expand All @@ -47,7 +47,7 @@ jobs:
with:
node-version: ${{ steps.nvmrc.outputs.NODE_VERSION }}
registry-url: https://registry.npmjs.org/
scope: "@doist"
scope: '@doist'
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.env
dist
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/**
9 changes: 0 additions & 9 deletions .prettierrc.json

This file was deleted.

5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

One core goal this library is to deliver a lightweight solution. Therefore, it comes to critically when it comes to user of dependencies and also polyfill usage.

- `react` should be its only dependencies.
- No polyfill.

- `react` should be its only dependencies.
- No polyfill.
34 changes: 16 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
A string interpolation component that formats and interpolates a template string in a safe way.

```jsx
import Interpolate from "@doist/react-interpolate"
import Interpolate from '@doist/react-interpolate'

function Greeting() {
return (
<Interpolate
string="<h1>Hello {name}. Here is <a>your order info</a></h1>"
mapping={{
name: "William",
a: <a href="https://orderinfo.com" />
name: 'William',
a: <a href="https://orderinfo.com" />,
}}
/>
)
Expand All @@ -23,9 +23,7 @@ function Greeting() {
Would render the following HTML

```html
<h1>
Hello William. Here is <a href="https://orderinfo.com">your order info</a>
</h1>
<h1>Hello William. Here is <a href="https://orderinfo.com">your order info</a></h1>
```

## Component API
Expand All @@ -51,14 +49,14 @@ An object that defines the values to be injected for placeholder and tags define
Please contact <supportLink>support</supportLink> for help"
mapping={{
// you can map placholder and self-closing tag to any valid element value
name: "William",
name: 'William',
hr: <hr className="break" />,

// you can map open & close tag to a rendering function
orderLink: text => <a href="https://orderinfo.com">{text}</a>,
orderLink: (text) => <a href="https://orderinfo.com">{text}</a>,

// or you can map open & close tag to an element
supportLink: <a href="https://orderinfo.com" />
supportLink: <a href="https://orderinfo.com" />,
}}
/>
```
Expand All @@ -85,21 +83,21 @@ Here is interpolation syntax you can use in your `string`.
#### Placeholder

```jsx
"hello {user_name}"
'hello {user_name}'
```

Placeholder name should be alphanumeric (`[A-Za-z0-9_]`). Placeholders could be mapped to any valid element value.

#### Open & close tags

```jsx
"Here is <a>your order info</a>"
'Here is <a>your order info</a>'

// tag name could be any alphanumeric string
"Here is <link>your order info</link>"
'Here is <link>your order info</link>'

// you can nest tag and placeholder
"Here is <a><b>you order info {name}</b></a>"
'Here is <a><b>you order info {name}</b></a>'
```

Tag name should be alphanumeric (`[A-Za-z0-9_]`).
Expand Down Expand Up @@ -135,12 +133,12 @@ Open & close tag could be mapped to a rendering function, which would take a sin
<Interpolate
string="Here is <a>your order info</a>"
mapping={{
a: text => (
a: (text) => (
<a href="https://orderinfo.com">
<b>{text}</b>
<br />
</a>
)
),
}}
/>
```
Expand All @@ -149,16 +147,16 @@ Unclosed tag or incorrect nesting of tag would result in syntax error.

```js
// bad: no close tag
"Here is <a>your order info"
'Here is <a>your order info'

// bad: incorrect tag structure
"Here is <a><b>your order info</a></b>"
'Here is <a><b>your order info</a></b>'
```

#### Self closing tag

```js
"Hello.<br/>Here is your order"
'Hello.<br/>Here is your order'
```

Tag name should be alphanumeric (`[A-Za-z0-9_]`). Self closing tags could be mapped to any valid element value.
Expand Down
Loading

0 comments on commit 1f01072

Please sign in to comment.