lesca-validate 0.0.1 → 0.0.2
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 +10 -2
- package/package.json +1 -1
- package/readme.md +4 -1
- package/src/docs/components/navigation.js +1 -3
- package/src/docs/pages/demo.js +26 -1
- package/src/lib/index.ts +9 -0
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
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
|
+
export declare const ValidateYoutubeURL: (url: string) => string | false;
|
|
4
5
|
declare const Validate: {
|
|
5
6
|
email: (email: string) => boolean;
|
|
6
7
|
phone: (phone: string) => boolean;
|
|
7
8
|
url: (str: string) => boolean;
|
|
9
|
+
youtubeID: (url: string) => string | false;
|
|
8
10
|
};
|
|
9
11
|
export default Validate;
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports["default"] = exports.ValidateURL = exports.ValidatePhone = exports.ValidateEmail = void 0;
|
|
6
|
+
exports["default"] = exports.ValidateYoutubeURL = exports.ValidateURL = exports.ValidatePhone = exports.ValidateEmail = void 0;
|
|
7
7
|
var ValidateEmail = function ValidateEmail(email) {
|
|
8
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
9
|
};
|
|
@@ -17,10 +17,18 @@ var ValidateURL = function ValidateURL(str) {
|
|
|
17
17
|
return !!pattern.test(str);
|
|
18
18
|
};
|
|
19
19
|
exports.ValidateURL = ValidateURL;
|
|
20
|
+
var ValidateYoutubeURL = function ValidateYoutubeURL(url) {
|
|
21
|
+
var pattern = /^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?v(?:i)?=|\&v(?:i)?=))([^#\&\?]*).*/;
|
|
22
|
+
var result = url.match(pattern);
|
|
23
|
+
if (result) return result[1];
|
|
24
|
+
return false;
|
|
25
|
+
};
|
|
26
|
+
exports.ValidateYoutubeURL = ValidateYoutubeURL;
|
|
20
27
|
var Validate = {
|
|
21
28
|
email: ValidateEmail,
|
|
22
29
|
phone: ValidatePhone,
|
|
23
|
-
url: ValidateURL
|
|
30
|
+
url: ValidateURL,
|
|
31
|
+
youtubeID: ValidateYoutubeURL
|
|
24
32
|
};
|
|
25
33
|
var _default = Validate;
|
|
26
34
|
exports["default"] = _default;
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -24,7 +24,7 @@ npm install lesca-validate --save
|
|
|
24
24
|
As a Node module:
|
|
25
25
|
|
|
26
26
|
```javascript
|
|
27
|
-
import { ValidateEmail, ValidatePhone, ValidateURL } from 'lesca-validate';
|
|
27
|
+
import { ValidateEmail, ValidatePhone, ValidateURL, ValidateYoutubeURL } from 'lesca-validate';
|
|
28
28
|
|
|
29
29
|
const email = 'username@host.com';
|
|
30
30
|
ValidateEmail(email); // true
|
|
@@ -34,6 +34,9 @@ ValidatePhone(phone); // true
|
|
|
34
34
|
|
|
35
35
|
const url = 'https://google.com';
|
|
36
36
|
ValidatePhone(url); // true
|
|
37
|
+
|
|
38
|
+
const youtubeURL = 'https://www.youtube.com/watch?v=09839DpTctU';
|
|
39
|
+
ValidateYoutubeURL(youtubeURL); // '09839DpTctU';
|
|
37
40
|
```
|
|
38
41
|
|
|
39
42
|
### Features
|
|
@@ -27,9 +27,7 @@ const Menu = ({ setState, state }) => (
|
|
|
27
27
|
const Navigation = ({ setState, state }) => (
|
|
28
28
|
<div className='Navigation'>
|
|
29
29
|
<div className='logo'>{name}</div>
|
|
30
|
-
<div className='menu'>
|
|
31
|
-
<Menu setState={setState} state={state} />
|
|
32
|
-
</div>
|
|
30
|
+
<div className='menu'>{/* <Menu setState={setState} state={state} /> */}</div>
|
|
33
31
|
</div>
|
|
34
32
|
);
|
|
35
33
|
export default Navigation;
|
package/src/docs/pages/demo.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { Button, ButtonGroup, TextField } from '@mui/material';
|
|
2
2
|
import { useRef, useState } from 'react';
|
|
3
|
-
import { ValidateEmail, ValidatePhone, ValidateURL } from '../../lib';
|
|
3
|
+
import { ValidateEmail, ValidatePhone, ValidateURL, ValidateYoutubeURL } from '../../lib';
|
|
4
4
|
|
|
5
5
|
const Demo = () => {
|
|
6
6
|
const emailRef = useRef();
|
|
7
7
|
const phoneRef = useRef();
|
|
8
8
|
const urlRef = useRef();
|
|
9
|
+
const youtubeRef = useRef();
|
|
9
10
|
|
|
10
11
|
const [emailResult, setEmailResult] = useState();
|
|
11
12
|
const [phoneResult, setPhoneResult] = useState();
|
|
12
13
|
const [urlResult, setUrlResult] = useState();
|
|
14
|
+
const [youtubeResult, setYoutubeResult] = useState();
|
|
13
15
|
|
|
14
16
|
return (
|
|
15
17
|
<div className='Demo'>
|
|
@@ -64,6 +66,29 @@ const Demo = () => {
|
|
|
64
66
|
click
|
|
65
67
|
</Button>
|
|
66
68
|
</ButtonGroup>
|
|
69
|
+
|
|
70
|
+
<hr style={{ margin: '10px 0' }} />
|
|
71
|
+
|
|
72
|
+
<h2>Validate YouTube URL Address</h2>
|
|
73
|
+
<TextField
|
|
74
|
+
inputRef={youtubeRef}
|
|
75
|
+
defaultValue='https://www.youtube.com/watch?v=09839DpTctU'
|
|
76
|
+
label='YouTube URL'
|
|
77
|
+
fullWidth
|
|
78
|
+
/>
|
|
79
|
+
<pre>
|
|
80
|
+
<code>{JSON.stringify(youtubeResult ?? 'no result')}</code>
|
|
81
|
+
</pre>
|
|
82
|
+
<ButtonGroup variant='contained'>
|
|
83
|
+
<Button
|
|
84
|
+
onClick={() => {
|
|
85
|
+
const { value } = youtubeRef.current;
|
|
86
|
+
setYoutubeResult(ValidateYoutubeURL(value));
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
click
|
|
90
|
+
</Button>
|
|
91
|
+
</ButtonGroup>
|
|
67
92
|
</div>
|
|
68
93
|
);
|
|
69
94
|
};
|
package/src/lib/index.ts
CHANGED
|
@@ -25,10 +25,19 @@ export const ValidateURL = (str: string) => {
|
|
|
25
25
|
return !!pattern.test(str);
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
+
export const ValidateYoutubeURL = (url: string) => {
|
|
29
|
+
const pattern =
|
|
30
|
+
/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?v(?:i)?=|\&v(?:i)?=))([^#\&\?]*).*/;
|
|
31
|
+
const result = url.match(pattern);
|
|
32
|
+
if (result) return result[1];
|
|
33
|
+
return false;
|
|
34
|
+
};
|
|
35
|
+
|
|
28
36
|
const Validate = {
|
|
29
37
|
email: ValidateEmail,
|
|
30
38
|
phone: ValidatePhone,
|
|
31
39
|
url: ValidateURL,
|
|
40
|
+
youtubeID: ValidateYoutubeURL,
|
|
32
41
|
};
|
|
33
42
|
|
|
34
43
|
export default Validate;
|