lesca-validate 0.0.2 → 0.0.3
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/lib/index.d.ts +2 -0
- package/lib/index.js +15 -2
- package/lib/misc.d.ts +2 -0
- package/lib/misc.js +25 -0
- package/package.json +29 -29
- package/readme.md +10 -1
- package/src/docs/pages/demo.js +26 -1
- package/src/lib/index.ts +14 -0
- package/src/lib/misc.ts +19 -0
- package/lib/style.css +0 -0
package/lib/index.d.ts
CHANGED
|
@@ -2,10 +2,12 @@ export declare const ValidateEmail: (email: string) => boolean;
|
|
|
2
2
|
export declare const ValidatePhone: (phone: string) => boolean;
|
|
3
3
|
export declare const ValidateURL: (str: string) => boolean;
|
|
4
4
|
export declare const ValidateYoutubeURL: (url: string) => string | false;
|
|
5
|
+
export declare const ValiDateInvoice: (value: String) => boolean;
|
|
5
6
|
declare const Validate: {
|
|
6
7
|
email: (email: string) => boolean;
|
|
7
8
|
phone: (phone: string) => boolean;
|
|
8
9
|
url: (str: string) => boolean;
|
|
9
10
|
youtubeID: (url: string) => string | false;
|
|
11
|
+
invoice: (value: String) => boolean;
|
|
10
12
|
};
|
|
11
13
|
export default Validate;
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports["default"] = exports.ValidateYoutubeURL = exports.ValidateURL = exports.ValidatePhone = exports.ValidateEmail = void 0;
|
|
6
|
+
exports["default"] = exports.ValidateYoutubeURL = exports.ValidateURL = exports.ValidatePhone = exports.ValidateEmail = exports.ValiDateInvoice = void 0;
|
|
7
|
+
var _misc = require("./misc");
|
|
7
8
|
var ValidateEmail = function ValidateEmail(email) {
|
|
8
9
|
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
|
};
|
|
@@ -24,11 +25,23 @@ var ValidateYoutubeURL = function ValidateYoutubeURL(url) {
|
|
|
24
25
|
return false;
|
|
25
26
|
};
|
|
26
27
|
exports.ValidateYoutubeURL = ValidateYoutubeURL;
|
|
28
|
+
var ValiDateInvoice = function ValiDateInvoice(value) {
|
|
29
|
+
var currentValue = String(value);
|
|
30
|
+
var length = currentValue.length;
|
|
31
|
+
if (length !== 10) return false;
|
|
32
|
+
var code = (0, _misc.isEnglish)(currentValue.slice(0, 2));
|
|
33
|
+
if (!code) return false;
|
|
34
|
+
var num = (0, _misc.isNumber)(currentValue.slice(2));
|
|
35
|
+
if (!num) return false;
|
|
36
|
+
return true;
|
|
37
|
+
};
|
|
38
|
+
exports.ValiDateInvoice = ValiDateInvoice;
|
|
27
39
|
var Validate = {
|
|
28
40
|
email: ValidateEmail,
|
|
29
41
|
phone: ValidatePhone,
|
|
30
42
|
url: ValidateURL,
|
|
31
|
-
youtubeID: ValidateYoutubeURL
|
|
43
|
+
youtubeID: ValidateYoutubeURL,
|
|
44
|
+
invoice: ValiDateInvoice
|
|
32
45
|
};
|
|
33
46
|
var _default = Validate;
|
|
34
47
|
exports["default"] = _default;
|
package/lib/misc.d.ts
ADDED
package/lib/misc.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isEnglish = isEnglish;
|
|
7
|
+
exports.isNumber = isNumber;
|
|
8
|
+
function isEnglish(s) {
|
|
9
|
+
var i, charCode;
|
|
10
|
+
var result = true;
|
|
11
|
+
for (i = s.length; i--;) {
|
|
12
|
+
charCode = s.charCodeAt(i);
|
|
13
|
+
if (charCode < 65 || charCode > 122) result = false;
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
function isNumber(s) {
|
|
18
|
+
var i, charCode;
|
|
19
|
+
var result = true;
|
|
20
|
+
for (i = s.length; i--;) {
|
|
21
|
+
charCode = s.charCodeAt(i);
|
|
22
|
+
if (charCode < 48 || charCode > 57) result = false;
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lesca-validate",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "check email, phone number, url format.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,42 +20,42 @@
|
|
|
20
20
|
],
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@babel/cli": "^7.
|
|
24
|
-
"@babel/core": "^7.
|
|
23
|
+
"@babel/cli": "^7.22.10",
|
|
24
|
+
"@babel/core": "^7.22.10",
|
|
25
25
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
26
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.20.
|
|
27
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
28
|
-
"@babel/preset-env": "^7.
|
|
29
|
-
"@babel/preset-react": "^7.
|
|
30
|
-
"@babel/preset-typescript": "^7.
|
|
31
|
-
"@emotion/react": "^11.
|
|
32
|
-
"@emotion/styled": "^11.
|
|
33
|
-
"@mui/icons-material": "^5.
|
|
34
|
-
"@mui/material": "^5.
|
|
35
|
-
"autoprefixer": "^10.4.
|
|
36
|
-
"babel-loader": "^9.1.
|
|
37
|
-
"concurrently": "^
|
|
26
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
27
|
+
"@babel/plugin-transform-runtime": "^7.22.10",
|
|
28
|
+
"@babel/preset-env": "^7.22.10",
|
|
29
|
+
"@babel/preset-react": "^7.22.5",
|
|
30
|
+
"@babel/preset-typescript": "^7.22.5",
|
|
31
|
+
"@emotion/react": "^11.11.1",
|
|
32
|
+
"@emotion/styled": "^11.11.0",
|
|
33
|
+
"@mui/icons-material": "^5.14.3",
|
|
34
|
+
"@mui/material": "^5.14.5",
|
|
35
|
+
"autoprefixer": "^10.4.15",
|
|
36
|
+
"babel-loader": "^9.1.3",
|
|
37
|
+
"concurrently": "^8.2.0",
|
|
38
38
|
"copy-and-watch": "^0.1.6",
|
|
39
|
-
"css-loader": "^6.
|
|
39
|
+
"css-loader": "^6.8.1",
|
|
40
40
|
"file-loader": "^6.2.0",
|
|
41
|
-
"gh-pages": "^
|
|
42
|
-
"html-react-parser": "^
|
|
43
|
-
"html-webpack-plugin": "^5.5.
|
|
44
|
-
"less": "^4.
|
|
45
|
-
"less-loader": "^11.1.
|
|
41
|
+
"gh-pages": "^6.0.0",
|
|
42
|
+
"html-react-parser": "^4.2.1",
|
|
43
|
+
"html-webpack-plugin": "^5.5.3",
|
|
44
|
+
"less": "^4.2.0",
|
|
45
|
+
"less-loader": "^11.1.3",
|
|
46
46
|
"less-vars-to-js": "^1.3.0",
|
|
47
47
|
"less-watch-compiler": "^1.16.3",
|
|
48
|
-
"postcss": "^8.4.
|
|
49
|
-
"postcss-loader": "^7.
|
|
48
|
+
"postcss": "^8.4.28",
|
|
49
|
+
"postcss-loader": "^7.3.3",
|
|
50
50
|
"prismjs": "^1.29.0",
|
|
51
51
|
"react": "^18.2.0",
|
|
52
52
|
"react-dom": "^18.2.0",
|
|
53
|
-
"style-loader": "^3.3.
|
|
54
|
-
"ts-loader": "^9.4.
|
|
55
|
-
"typescript": "^
|
|
56
|
-
"webpack": "^5.
|
|
57
|
-
"webpack-cli": "^5.
|
|
58
|
-
"webpack-dev-server": "^4.
|
|
53
|
+
"style-loader": "^3.3.3",
|
|
54
|
+
"ts-loader": "^9.4.4",
|
|
55
|
+
"typescript": "^5.1.6",
|
|
56
|
+
"webpack": "^5.88.2",
|
|
57
|
+
"webpack-cli": "^5.1.4",
|
|
58
|
+
"webpack-dev-server": "^4.15.1"
|
|
59
59
|
},
|
|
60
60
|
"author": "jamehsu1125 <jameshsu1125@gmail.com>",
|
|
61
61
|
"homepage": "https://jameshsu1125.github.io/lesca-validate/",
|
package/readme.md
CHANGED
|
@@ -24,7 +24,13 @@ npm install lesca-validate --save
|
|
|
24
24
|
As a Node module:
|
|
25
25
|
|
|
26
26
|
```javascript
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
ValidateEmail,
|
|
29
|
+
ValidatePhone,
|
|
30
|
+
ValidateURL,
|
|
31
|
+
ValidateYoutubeURL,
|
|
32
|
+
ValiDateInvoice,
|
|
33
|
+
} from 'lesca-validate';
|
|
28
34
|
|
|
29
35
|
const email = 'username@host.com';
|
|
30
36
|
ValidateEmail(email); // true
|
|
@@ -37,6 +43,9 @@ ValidatePhone(url); // true
|
|
|
37
43
|
|
|
38
44
|
const youtubeURL = 'https://www.youtube.com/watch?v=09839DpTctU';
|
|
39
45
|
ValidateYoutubeURL(youtubeURL); // '09839DpTctU';
|
|
46
|
+
|
|
47
|
+
const invoiceNumber = 'XS12345678';
|
|
48
|
+
ValiDateInvoice(invoiceNumber); // 'true';
|
|
40
49
|
```
|
|
41
50
|
|
|
42
51
|
### Features
|
package/src/docs/pages/demo.js
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import { Button, ButtonGroup, TextField } from '@mui/material';
|
|
2
2
|
import { useRef, useState } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ValidateEmail,
|
|
5
|
+
ValidatePhone,
|
|
6
|
+
ValidateURL,
|
|
7
|
+
ValidateYoutubeURL,
|
|
8
|
+
ValiDateInvoice,
|
|
9
|
+
} from '../../lib';
|
|
4
10
|
|
|
5
11
|
const Demo = () => {
|
|
6
12
|
const emailRef = useRef();
|
|
7
13
|
const phoneRef = useRef();
|
|
8
14
|
const urlRef = useRef();
|
|
9
15
|
const youtubeRef = useRef();
|
|
16
|
+
const invoiceRef = useRef();
|
|
10
17
|
|
|
11
18
|
const [emailResult, setEmailResult] = useState();
|
|
12
19
|
const [phoneResult, setPhoneResult] = useState();
|
|
13
20
|
const [urlResult, setUrlResult] = useState();
|
|
14
21
|
const [youtubeResult, setYoutubeResult] = useState();
|
|
22
|
+
const [invoiceResult, setInvoiceResult] = useState();
|
|
15
23
|
|
|
16
24
|
return (
|
|
17
25
|
<div className='Demo'>
|
|
@@ -89,6 +97,23 @@ const Demo = () => {
|
|
|
89
97
|
click
|
|
90
98
|
</Button>
|
|
91
99
|
</ButtonGroup>
|
|
100
|
+
|
|
101
|
+
<h2>Validate Invoice Number</h2>
|
|
102
|
+
<TextField inputRef={invoiceRef} defaultValue='XS12345678' label='Invoice number' fullWidth />
|
|
103
|
+
<pre>
|
|
104
|
+
<code>{JSON.stringify(invoiceResult ?? 'no result')}</code>
|
|
105
|
+
</pre>
|
|
106
|
+
<ButtonGroup variant='contained'>
|
|
107
|
+
<Button
|
|
108
|
+
onClick={() => {
|
|
109
|
+
const { value } = invoiceRef.current;
|
|
110
|
+
console.log(ValiDateInvoice(value));
|
|
111
|
+
setInvoiceResult(ValiDateInvoice(value));
|
|
112
|
+
}}
|
|
113
|
+
>
|
|
114
|
+
click
|
|
115
|
+
</Button>
|
|
116
|
+
</ButtonGroup>
|
|
92
117
|
</div>
|
|
93
118
|
);
|
|
94
119
|
};
|
package/src/lib/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isEnglish, isNumber } from './misc';
|
|
2
|
+
|
|
1
3
|
export const ValidateEmail = (email: string) => {
|
|
2
4
|
return (
|
|
3
5
|
String(email)
|
|
@@ -33,11 +35,23 @@ export const ValidateYoutubeURL = (url: string) => {
|
|
|
33
35
|
return false;
|
|
34
36
|
};
|
|
35
37
|
|
|
38
|
+
export const ValiDateInvoice = (value: String) => {
|
|
39
|
+
const currentValue = String(value);
|
|
40
|
+
const { length } = currentValue;
|
|
41
|
+
if (length !== 10) return false;
|
|
42
|
+
const code = isEnglish(currentValue.slice(0, 2));
|
|
43
|
+
if (!code) return false;
|
|
44
|
+
const num = isNumber(currentValue.slice(2));
|
|
45
|
+
if (!num) return false;
|
|
46
|
+
return true;
|
|
47
|
+
};
|
|
48
|
+
|
|
36
49
|
const Validate = {
|
|
37
50
|
email: ValidateEmail,
|
|
38
51
|
phone: ValidatePhone,
|
|
39
52
|
url: ValidateURL,
|
|
40
53
|
youtubeID: ValidateYoutubeURL,
|
|
54
|
+
invoice: ValiDateInvoice,
|
|
41
55
|
};
|
|
42
56
|
|
|
43
57
|
export default Validate;
|
package/src/lib/misc.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function isEnglish(s: String) {
|
|
2
|
+
let i, charCode;
|
|
3
|
+
let result = true;
|
|
4
|
+
for (i = s.length; i--; ) {
|
|
5
|
+
charCode = s.charCodeAt(i);
|
|
6
|
+
if (charCode < 65 || charCode > 122) result = false;
|
|
7
|
+
}
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isNumber(s: String) {
|
|
12
|
+
let i, charCode;
|
|
13
|
+
let result = true;
|
|
14
|
+
for (i = s.length; i--; ) {
|
|
15
|
+
charCode = s.charCodeAt(i);
|
|
16
|
+
if (charCode < 48 || charCode > 57) result = false;
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
package/lib/style.css
DELETED
|
File without changes
|