lesca-validate 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +17 -0
- package/.gitattributes +2 -0
- package/.prettierignore +11 -0
- package/.prettierrc +8 -0
- package/LICENSE +21 -0
- package/less-watch-compiler.config.json +5 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +26 -0
- package/lib/style.css +0 -0
- package/package.json +66 -0
- package/postcss.config.js +3 -0
- package/readme.md +54 -0
- package/src/docs/components/code.js +19 -0
- package/src/docs/components/code.less +7 -0
- package/src/docs/components/navigation.js +35 -0
- package/src/docs/components/navigation.less +28 -0
- package/src/docs/config.js +4 -0
- package/src/docs/index.js +35 -0
- package/src/docs/module/lessVarsLoader.js +5 -0
- package/src/docs/pages/demo.js +70 -0
- package/src/docs/pages/usage.js +25 -0
- package/src/docs/styles.less +16 -0
- package/src/docs/theme.js +22 -0
- package/src/docs/theme.less +6 -0
- package/src/lib/index.ts +34 -0
- package/template/template.html +38 -0
- package/template/template.meta.js +6 -0
- package/tsconfig.json +21 -0
- package/webpack.config.js +61 -0
package/.babelrc
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"presets": [
|
|
3
|
+
"@babel/preset-env",
|
|
4
|
+
[
|
|
5
|
+
"@babel/preset-react",
|
|
6
|
+
{
|
|
7
|
+
"runtime": "automatic"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
10
|
+
"@babel/preset-typescript"
|
|
11
|
+
],
|
|
12
|
+
"plugins": [
|
|
13
|
+
"@babel/plugin-proposal-object-rest-spread",
|
|
14
|
+
"@babel/plugin-proposal-class-properties",
|
|
15
|
+
"@babel/transform-runtime"
|
|
16
|
+
]
|
|
17
|
+
}
|
package/.gitattributes
ADDED
package/.prettierignore
ADDED
package/.prettierrc
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 James Hsu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const ValidateEmail: (email: string) => boolean;
|
|
2
|
+
export declare const ValidatePhone: (phone: string) => boolean;
|
|
3
|
+
export declare const ValidateURL: (str: string) => boolean;
|
|
4
|
+
declare const Validate: {
|
|
5
|
+
email: (email: string) => boolean;
|
|
6
|
+
phone: (phone: string) => boolean;
|
|
7
|
+
url: (str: string) => boolean;
|
|
8
|
+
};
|
|
9
|
+
export default Validate;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = exports.ValidateURL = exports.ValidatePhone = exports.ValidateEmail = void 0;
|
|
7
|
+
var ValidateEmail = function ValidateEmail(email) {
|
|
8
|
+
return String(email).toLowerCase().match(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/) !== null;
|
|
9
|
+
};
|
|
10
|
+
exports.ValidateEmail = ValidateEmail;
|
|
11
|
+
var ValidatePhone = function ValidatePhone(phone) {
|
|
12
|
+
return phone !== '' && phone.length === 10 && phone.slice(0, 2) === '09';
|
|
13
|
+
};
|
|
14
|
+
exports.ValidatePhone = ValidatePhone;
|
|
15
|
+
var ValidateURL = function ValidateURL(str) {
|
|
16
|
+
var pattern = new RegExp('^(https?:\\/\\/)?' + '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + '((\\d{1,3}\\.){3}\\d{1,3}))' + '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + '(\\?[;&a-z\\d%_.~+=-]*)?' + '(\\#[-a-z\\d_]*)?$', 'i');
|
|
17
|
+
return !!pattern.test(str);
|
|
18
|
+
};
|
|
19
|
+
exports.ValidateURL = ValidateURL;
|
|
20
|
+
var Validate = {
|
|
21
|
+
email: ValidateEmail,
|
|
22
|
+
phone: ValidatePhone,
|
|
23
|
+
url: ValidateURL
|
|
24
|
+
};
|
|
25
|
+
var _default = Validate;
|
|
26
|
+
exports["default"] = _default;
|
package/lib/style.css
ADDED
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lesca-validate",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "check email, phone number, url format.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "webpack-dev-server --mode development",
|
|
8
|
+
"watch": "babel --watch src/lib --out-dir lib --extensions '.ts,.tsx'",
|
|
9
|
+
"build": "NODE_ENV=production webpack",
|
|
10
|
+
"less": "less-watch-compiler",
|
|
11
|
+
"css": "copy-and-watch --watch src/lib/*.css lib/",
|
|
12
|
+
"deploy": "gh-pages -d dist",
|
|
13
|
+
"tsc": "npx tsc --watch",
|
|
14
|
+
"dev": "concurrently \"npm run tsc\" \"npm run less\" \"npm run css\" \"npm run watch\" \"npm run start\"",
|
|
15
|
+
"rm": "rm -rf node_modules/ package-lock.json",
|
|
16
|
+
"op": "babel src/lib -d lib --copy-files"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"lesca"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@babel/cli": "^7.19.3",
|
|
24
|
+
"@babel/core": "^7.20.5",
|
|
25
|
+
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
26
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.20.2",
|
|
27
|
+
"@babel/plugin-transform-runtime": "^7.19.6",
|
|
28
|
+
"@babel/preset-env": "^7.20.2",
|
|
29
|
+
"@babel/preset-react": "^7.18.6",
|
|
30
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
31
|
+
"@emotion/react": "^11.10.5",
|
|
32
|
+
"@emotion/styled": "^11.10.5",
|
|
33
|
+
"@mui/icons-material": "^5.11.0",
|
|
34
|
+
"@mui/material": "^5.11.0",
|
|
35
|
+
"autoprefixer": "^10.4.13",
|
|
36
|
+
"babel-loader": "^9.1.0",
|
|
37
|
+
"concurrently": "^7.6.0",
|
|
38
|
+
"copy-and-watch": "^0.1.6",
|
|
39
|
+
"css-loader": "^6.7.3",
|
|
40
|
+
"file-loader": "^6.2.0",
|
|
41
|
+
"gh-pages": "^4.0.0",
|
|
42
|
+
"html-react-parser": "^3.0.4",
|
|
43
|
+
"html-webpack-plugin": "^5.5.0",
|
|
44
|
+
"less": "^4.1.3",
|
|
45
|
+
"less-loader": "^11.1.0",
|
|
46
|
+
"less-vars-to-js": "^1.3.0",
|
|
47
|
+
"less-watch-compiler": "^1.16.3",
|
|
48
|
+
"postcss": "^8.4.20",
|
|
49
|
+
"postcss-loader": "^7.0.2",
|
|
50
|
+
"prismjs": "^1.29.0",
|
|
51
|
+
"react": "^18.2.0",
|
|
52
|
+
"react-dom": "^18.2.0",
|
|
53
|
+
"style-loader": "^3.3.1",
|
|
54
|
+
"ts-loader": "^9.4.2",
|
|
55
|
+
"typescript": "^4.9.4",
|
|
56
|
+
"webpack": "^5.75.0",
|
|
57
|
+
"webpack-cli": "^5.0.1",
|
|
58
|
+
"webpack-dev-server": "^4.11.1"
|
|
59
|
+
},
|
|
60
|
+
"author": "jamehsu1125 <jameshsu1125@gmail.com>",
|
|
61
|
+
"homepage": "https://jameshsu1125.github.io/lesca-validate/",
|
|
62
|
+
"repository": {
|
|
63
|
+
"type": "git",
|
|
64
|
+
"url": "git@github.com:jameshsu1125/lesca-validate.git"
|
|
65
|
+
}
|
|
66
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
[](https://zh-hant.reactjs.org/)
|
|
2
|
+
[](https://lesscss.org/)
|
|
3
|
+
[](https://www.typescriptlang.org/)
|
|
4
|
+
[](https://www.w3schools.com/html/)
|
|
5
|
+
[](https://www.w3schools.com/css/)
|
|
6
|
+
[](https://www.npmjs.com/)
|
|
7
|
+
[](https://nodejs.org/en/)
|
|
8
|
+
[](https://www.npmjs.com/~jameshsu1125)
|
|
9
|
+
|
|
10
|
+
# Why use it?
|
|
11
|
+
|
|
12
|
+
check is validate email, phone number and url format.
|
|
13
|
+
|
|
14
|
+
#### [Live Demo](https://jameshsu1125.github.io/lesca-validate/)
|
|
15
|
+
|
|
16
|
+
# Installation
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install lesca-validate --save
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
As a Node module:
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
import { ValidateEmail, ValidatePhone, ValidateURL } from 'lesca-validate';
|
|
28
|
+
|
|
29
|
+
const email = 'username@host.com';
|
|
30
|
+
ValidateEmail(email); // true
|
|
31
|
+
|
|
32
|
+
const phone = '0912345678';
|
|
33
|
+
ValidatePhone(phone); // true
|
|
34
|
+
|
|
35
|
+
const url = 'https://google.com';
|
|
36
|
+
ValidatePhone(url); // true
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Features
|
|
40
|
+
|
|
41
|
+
- maintain if necessary
|
|
42
|
+
|
|
43
|
+
[ci-badge]: https://github.com/executablebooks/markdown-it-plugin-template/workflows/CI/badge.svg
|
|
44
|
+
[ci-link]: https://github.com/executablebooks/markdown-it--plugin-template/actions
|
|
45
|
+
[npm-badge]: https://img.shields.io/npm/v/markdown-it-plugin-template.svg
|
|
46
|
+
[npm-link]: https://www.npmjs.com/package/markdown-it-plugin-template
|
|
47
|
+
[github actions]: https://docs.github.com/en/actions
|
|
48
|
+
[github pages]: https://docs.github.com/en/pages
|
|
49
|
+
[prettier]: https://prettier.io/
|
|
50
|
+
[eslint]: https://eslint.org/
|
|
51
|
+
[jest]: https://facebook.github.io/jest/
|
|
52
|
+
[rollup]: https://rollupjs.org
|
|
53
|
+
[npm]: https://www.npmjs.com
|
|
54
|
+
[unpkg]: https://unpkg.com/
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import HTMLReactParser from 'html-react-parser';
|
|
2
|
+
import Prism from 'prismjs';
|
|
3
|
+
import 'prismjs/themes/prism.css';
|
|
4
|
+
import './code.less';
|
|
5
|
+
|
|
6
|
+
const Code = ({ code, theme }) => {
|
|
7
|
+
return (
|
|
8
|
+
<pre>
|
|
9
|
+
<code>{HTMLReactParser(Prism.highlight(code, Prism.languages[theme], theme))}</code>
|
|
10
|
+
</pre>
|
|
11
|
+
);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
Code.defaultProps = {
|
|
15
|
+
code: `import { useState } from 'react';`,
|
|
16
|
+
theme: 'javascript',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default Code;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Button, ButtonGroup } from '@mui/material';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { name } from '../config';
|
|
4
|
+
import './navigation.less';
|
|
5
|
+
|
|
6
|
+
const Menu = ({ setState, state }) => (
|
|
7
|
+
<ButtonGroup variant='contained' size='small' color='success'>
|
|
8
|
+
<Button
|
|
9
|
+
onClick={() => {
|
|
10
|
+
setState('demo');
|
|
11
|
+
}}
|
|
12
|
+
disabled={state === 'demo'}
|
|
13
|
+
>
|
|
14
|
+
Demo
|
|
15
|
+
</Button>
|
|
16
|
+
<Button
|
|
17
|
+
onClick={() => {
|
|
18
|
+
setState('usage');
|
|
19
|
+
}}
|
|
20
|
+
disabled={state === 'usage'}
|
|
21
|
+
>
|
|
22
|
+
Usage
|
|
23
|
+
</Button>
|
|
24
|
+
</ButtonGroup>
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const Navigation = ({ setState, state }) => (
|
|
28
|
+
<div className='Navigation'>
|
|
29
|
+
<div className='logo'>{name}</div>
|
|
30
|
+
<div className='menu'>
|
|
31
|
+
<Menu setState={setState} state={state} />
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
export default Navigation;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
@import url('../theme.less');
|
|
2
|
+
|
|
3
|
+
.Navigation {
|
|
4
|
+
position: fixed;
|
|
5
|
+
box-sizing: border-box;
|
|
6
|
+
padding: 0 20px;
|
|
7
|
+
width: 100%;
|
|
8
|
+
height: 70px;
|
|
9
|
+
background-color: @C2;
|
|
10
|
+
|
|
11
|
+
.logo {
|
|
12
|
+
float: left;
|
|
13
|
+
height: 100%;
|
|
14
|
+
color: #fff;
|
|
15
|
+
font-size: 30px;
|
|
16
|
+
font-family: 'Titillium Web', sans-serif;
|
|
17
|
+
line-height: 70px;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.menu {
|
|
21
|
+
display: flex;
|
|
22
|
+
float: right;
|
|
23
|
+
align-items: center;
|
|
24
|
+
flex-direction: column;
|
|
25
|
+
justify-content: center;
|
|
26
|
+
height: 100%;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Container } from '@mui/material';
|
|
2
|
+
import { ThemeProvider } from '@mui/material/styles';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { createRoot } from 'react-dom/client';
|
|
5
|
+
import Navigation from './components/navigation';
|
|
6
|
+
import Demo from './pages/demo';
|
|
7
|
+
import Usage from './pages/usage';
|
|
8
|
+
import './styles.less';
|
|
9
|
+
import { theme } from './theme';
|
|
10
|
+
|
|
11
|
+
const App = () => {
|
|
12
|
+
const [state, setState] = useState('demo');
|
|
13
|
+
|
|
14
|
+
const appendPage = () => {
|
|
15
|
+
switch (state) {
|
|
16
|
+
default:
|
|
17
|
+
case 'demo':
|
|
18
|
+
return <Demo />;
|
|
19
|
+
|
|
20
|
+
case 'usage':
|
|
21
|
+
return <Usage />;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<ThemeProvider theme={theme}>
|
|
27
|
+
<Navigation setState={setState} state={state} />
|
|
28
|
+
<Container style={{ paddingTop: '70px' }} maxWidth='lg'>
|
|
29
|
+
{appendPage()}
|
|
30
|
+
</Container>
|
|
31
|
+
</ThemeProvider>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
createRoot(document.getElementById('app')).render(<App />);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Button, ButtonGroup, TextField } from '@mui/material';
|
|
2
|
+
import { useRef, useState } from 'react';
|
|
3
|
+
import { ValidateEmail, ValidatePhone, ValidateURL } from '../../lib';
|
|
4
|
+
|
|
5
|
+
const Demo = () => {
|
|
6
|
+
const emailRef = useRef();
|
|
7
|
+
const phoneRef = useRef();
|
|
8
|
+
const urlRef = useRef();
|
|
9
|
+
|
|
10
|
+
const [emailResult, setEmailResult] = useState();
|
|
11
|
+
const [phoneResult, setPhoneResult] = useState();
|
|
12
|
+
const [urlResult, setUrlResult] = useState();
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<div className='Demo'>
|
|
16
|
+
<h2>Validate Email</h2>
|
|
17
|
+
<TextField inputRef={emailRef} defaultValue='username@host.com' label='email' fullWidth />
|
|
18
|
+
<pre>
|
|
19
|
+
<code>{JSON.stringify(emailResult ?? 'no result')}</code>
|
|
20
|
+
</pre>
|
|
21
|
+
<ButtonGroup variant='contained'>
|
|
22
|
+
<Button
|
|
23
|
+
onClick={() => {
|
|
24
|
+
const { value } = emailRef.current;
|
|
25
|
+
setEmailResult(ValidateEmail(value));
|
|
26
|
+
}}
|
|
27
|
+
>
|
|
28
|
+
click
|
|
29
|
+
</Button>
|
|
30
|
+
</ButtonGroup>
|
|
31
|
+
|
|
32
|
+
<hr style={{ margin: '10px 0' }} />
|
|
33
|
+
|
|
34
|
+
<h2>Validate Phone[Taiwan only]</h2>
|
|
35
|
+
<TextField inputRef={phoneRef} defaultValue='0912345678' label='phone' fullWidth />
|
|
36
|
+
<pre>
|
|
37
|
+
<code>{JSON.stringify(phoneResult ?? 'no result')}</code>
|
|
38
|
+
</pre>
|
|
39
|
+
<ButtonGroup variant='contained'>
|
|
40
|
+
<Button
|
|
41
|
+
onClick={() => {
|
|
42
|
+
const { value } = phoneRef.current;
|
|
43
|
+
setPhoneResult(ValidatePhone(value));
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
click
|
|
47
|
+
</Button>
|
|
48
|
+
</ButtonGroup>
|
|
49
|
+
|
|
50
|
+
<hr style={{ margin: '10px 0' }} />
|
|
51
|
+
|
|
52
|
+
<h2>Validate URL Address</h2>
|
|
53
|
+
<TextField inputRef={urlRef} defaultValue='https://www.google.com/' label='URL' fullWidth />
|
|
54
|
+
<pre>
|
|
55
|
+
<code>{JSON.stringify(urlResult ?? 'no result')}</code>
|
|
56
|
+
</pre>
|
|
57
|
+
<ButtonGroup variant='contained'>
|
|
58
|
+
<Button
|
|
59
|
+
onClick={() => {
|
|
60
|
+
const { value } = urlRef.current;
|
|
61
|
+
setUrlResult(ValidateURL(value));
|
|
62
|
+
}}
|
|
63
|
+
>
|
|
64
|
+
click
|
|
65
|
+
</Button>
|
|
66
|
+
</ButtonGroup>
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
export default Demo;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Button, ButtonGroup } from '@mui/material';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import Code from '../components/code';
|
|
4
|
+
import { name } from '../config';
|
|
5
|
+
|
|
6
|
+
const codes = [{ title: '1. Installation', code: `npm install ${name} --save`, type: 'text' }];
|
|
7
|
+
|
|
8
|
+
const Usage = () => {
|
|
9
|
+
useEffect(() => {}, []);
|
|
10
|
+
return (
|
|
11
|
+
<div className='Usage'>
|
|
12
|
+
<h2>Usage</h2>
|
|
13
|
+
{codes.map((e) => (
|
|
14
|
+
<div key={e.title}>
|
|
15
|
+
<h3>{e.title}</h3>
|
|
16
|
+
<Code code={e.code} theme={e.type} />
|
|
17
|
+
</div>
|
|
18
|
+
))}
|
|
19
|
+
<ButtonGroup variant='contained'>
|
|
20
|
+
<Button>click</Button>
|
|
21
|
+
</ButtonGroup>
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
export default Usage;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
@import url('https://fonts.googleapis.com/css2?family=Sora&display=swap&css');
|
|
2
|
+
@import url('https://fonts.googleapis.com/css2?family=Titillium+Web&display=swap&css');
|
|
3
|
+
@import url('./theme.less');
|
|
4
|
+
|
|
5
|
+
body {
|
|
6
|
+
margin: 0;
|
|
7
|
+
background-color: @C4;
|
|
8
|
+
color: @C5;
|
|
9
|
+
font-family: 'Titillium Web', sans-serif;
|
|
10
|
+
|
|
11
|
+
overscroll-behavior: none;
|
|
12
|
+
|
|
13
|
+
.Demo > * {
|
|
14
|
+
margin: 5px 0;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createTheme } from '@mui/material/styles';
|
|
2
|
+
import * as styles from '!!./module/lessVarsLoader!./theme.less';
|
|
3
|
+
|
|
4
|
+
export const theme = createTheme({
|
|
5
|
+
palette: {
|
|
6
|
+
primary: {
|
|
7
|
+
main: styles['@C1'],
|
|
8
|
+
},
|
|
9
|
+
secondary: {
|
|
10
|
+
main: styles['@C2'],
|
|
11
|
+
},
|
|
12
|
+
error: {
|
|
13
|
+
main: styles['@C3'],
|
|
14
|
+
},
|
|
15
|
+
success: {
|
|
16
|
+
main: styles['@C4'],
|
|
17
|
+
},
|
|
18
|
+
warning: {
|
|
19
|
+
main: styles['@C5'],
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const ValidateEmail = (email: string) => {
|
|
2
|
+
return (
|
|
3
|
+
String(email)
|
|
4
|
+
.toLowerCase()
|
|
5
|
+
.match(
|
|
6
|
+
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
|
7
|
+
) !== null
|
|
8
|
+
);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const ValidatePhone = (phone: string) => {
|
|
12
|
+
return phone !== '' && phone.length === 10 && phone.slice(0, 2) === '09';
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const ValidateURL = (str: string) => {
|
|
16
|
+
var pattern = new RegExp(
|
|
17
|
+
'^(https?:\\/\\/)?' +
|
|
18
|
+
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' +
|
|
19
|
+
'((\\d{1,3}\\.){3}\\d{1,3}))' +
|
|
20
|
+
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' +
|
|
21
|
+
'(\\?[;&a-z\\d%_.~+=-]*)?' +
|
|
22
|
+
'(\\#[-a-z\\d_]*)?$',
|
|
23
|
+
'i',
|
|
24
|
+
);
|
|
25
|
+
return !!pattern.test(str);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const Validate = {
|
|
29
|
+
email: ValidateEmail,
|
|
30
|
+
phone: ValidatePhone,
|
|
31
|
+
url: ValidateURL,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default Validate;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-tw">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width,user-scalable=0" />
|
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
|
7
|
+
<title><%= htmlWebpackPlugin.options.title %></title>
|
|
8
|
+
<meta property="og:description" content="<%= htmlWebpackPlugin.options.description %>" />
|
|
9
|
+
<meta property="og:title" content="<%= htmlWebpackPlugin.options.title %>" />
|
|
10
|
+
<meta property="og:image" content="<%= htmlWebpackPlugin.options.url %>img/meta-img.jpg" />
|
|
11
|
+
<meta property="og:image:width" content="1280" />
|
|
12
|
+
<meta property="og:image:height" content="720" />
|
|
13
|
+
<meta property="og:url" content="<%= htmlWebpackPlugin.options.url %>" />
|
|
14
|
+
<meta property="og:type" content="website" />
|
|
15
|
+
<meta property="fb:app_id" content="171368189560011" />
|
|
16
|
+
<meta property="og:site_name" content="<%= htmlWebpackPlugin.options.title %>" />
|
|
17
|
+
<link
|
|
18
|
+
rel="apple-touch-icon"
|
|
19
|
+
href="<%= htmlWebpackPlugin.options.url %>img/apple-touch-icon.jpg"
|
|
20
|
+
/>
|
|
21
|
+
<link rel="image_src" href="<%= htmlWebpackPlugin.options.url %>img/meta-img.jpg" />
|
|
22
|
+
<link
|
|
23
|
+
href="<%= htmlWebpackPlugin.options.url %>img/favicon.ico"
|
|
24
|
+
rel="icon"
|
|
25
|
+
type="image/x-icon"
|
|
26
|
+
/>
|
|
27
|
+
<link
|
|
28
|
+
rel="stylesheet"
|
|
29
|
+
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
|
|
30
|
+
/>
|
|
31
|
+
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
|
|
32
|
+
<meta name="apple-mobile-web-app-capable" content="no" />
|
|
33
|
+
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
|
34
|
+
</head>
|
|
35
|
+
<body>
|
|
36
|
+
<div id="app"></div>
|
|
37
|
+
</body>
|
|
38
|
+
</html>
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compileOnSave": true,
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "./lib/",
|
|
5
|
+
"target": "es5",
|
|
6
|
+
"module": "AMD",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"jsx": "react-jsx",
|
|
13
|
+
"moduleResolution": "node",
|
|
14
|
+
"allowJs": true,
|
|
15
|
+
"noImplicitThis": false,
|
|
16
|
+
"paths": {
|
|
17
|
+
"*": ["./lib/*"]
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"include": ["src/lib"]
|
|
21
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
3
|
+
const template = './template/template.meta';
|
|
4
|
+
const Meta = require(template);
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
entry: path.join(__dirname, 'src/docs'),
|
|
8
|
+
output: {
|
|
9
|
+
path: path.join(__dirname, 'dist'),
|
|
10
|
+
filename: 'bundle.js',
|
|
11
|
+
},
|
|
12
|
+
module: {
|
|
13
|
+
rules: [
|
|
14
|
+
{
|
|
15
|
+
test: /\.(js|jsx)$/,
|
|
16
|
+
use: 'babel-loader',
|
|
17
|
+
exclude: /node_modules/,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
test: /\.tsx?$/,
|
|
21
|
+
use: ['babel-loader', 'ts-loader'],
|
|
22
|
+
exclude: /node_modules/,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
test: /\.(less|css)$/,
|
|
26
|
+
use: [
|
|
27
|
+
'style-loader',
|
|
28
|
+
{
|
|
29
|
+
loader: 'css-loader',
|
|
30
|
+
options: {
|
|
31
|
+
esModule: false,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
'postcss-loader',
|
|
35
|
+
'less-loader',
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
test: /\.(png|jpg|gif|svg)$/,
|
|
40
|
+
use: [
|
|
41
|
+
{
|
|
42
|
+
loader: 'file-loader',
|
|
43
|
+
options: { name: 'img/[path][name].[ext]', context: 'src/docs' },
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
plugins: [
|
|
50
|
+
new HtmlWebpackPlugin({
|
|
51
|
+
...Meta,
|
|
52
|
+
template: 'template/template.html',
|
|
53
|
+
}),
|
|
54
|
+
],
|
|
55
|
+
resolve: {
|
|
56
|
+
extensions: ['.tsx', '.ts', '.js', '.jsx'],
|
|
57
|
+
},
|
|
58
|
+
devServer: {
|
|
59
|
+
port: 8000,
|
|
60
|
+
},
|
|
61
|
+
};
|