lesca-validate 0.0.2 → 0.0.4

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 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,32 +3,39 @@
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;
7
- var ValidateEmail = function ValidateEmail(email) {
6
+ exports["default"] = exports.ValidateYoutubeURL = exports.ValidateURL = exports.ValidatePhone = exports.ValidateEmail = exports.ValiDateInvoice = void 0;
7
+ var _misc = require("./misc");
8
+ var ValidateEmail = exports.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
  };
10
- exports.ValidateEmail = ValidateEmail;
11
- var ValidatePhone = function ValidatePhone(phone) {
11
+ var ValidatePhone = exports.ValidatePhone = function ValidatePhone(phone) {
12
12
  return phone !== '' && phone.length === 10 && phone.slice(0, 2) === '09';
13
13
  };
14
- exports.ValidatePhone = ValidatePhone;
15
- var ValidateURL = function ValidateURL(str) {
14
+ var ValidateURL = exports.ValidateURL = function ValidateURL(str) {
16
15
  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
16
  return !!pattern.test(str);
18
17
  };
19
- exports.ValidateURL = ValidateURL;
20
- var ValidateYoutubeURL = function ValidateYoutubeURL(url) {
18
+ var ValidateYoutubeURL = exports.ValidateYoutubeURL = function ValidateYoutubeURL(url) {
21
19
  var pattern = /^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?v(?:i)?=|\&v(?:i)?=))([^#\&\?]*).*/;
22
20
  var result = url.match(pattern);
23
21
  if (result) return result[1];
24
22
  return false;
25
23
  };
26
- exports.ValidateYoutubeURL = ValidateYoutubeURL;
24
+ var ValiDateInvoice = exports.ValiDateInvoice = function ValiDateInvoice(value) {
25
+ var currentValue = String(value);
26
+ var length = currentValue.length;
27
+ if (length !== 10) return false;
28
+ var code = (0, _misc.isEnglish)(currentValue.slice(0, 2));
29
+ if (!code) return false;
30
+ var num = (0, _misc.isNumber)(currentValue.slice(2));
31
+ if (!num) return false;
32
+ return true;
33
+ };
27
34
  var Validate = {
28
35
  email: ValidateEmail,
29
36
  phone: ValidatePhone,
30
37
  url: ValidateURL,
31
- youtubeID: ValidateYoutubeURL
38
+ youtubeID: ValidateYoutubeURL,
39
+ invoice: ValiDateInvoice
32
40
  };
33
- var _default = Validate;
34
- exports["default"] = _default;
41
+ var _default = exports["default"] = Validate;
package/lib/misc.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function isEnglish(s: String): boolean;
2
+ export declare function isNumber(s: String): boolean;
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.2",
3
+ "version": "0.0.4",
4
4
  "description": "check email, phone number, url format.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -20,47 +20,50 @@
20
20
  ],
21
21
  "license": "MIT",
22
22
  "devDependencies": {
23
- "@babel/cli": "^7.19.3",
24
- "@babel/core": "^7.20.5",
23
+ "@babel/cli": "^7.23.0",
24
+ "@babel/core": "^7.23.2",
25
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",
26
+ "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
27
+ "@babel/plugin-transform-runtime": "^7.23.2",
28
+ "@babel/preset-env": "^7.23.2",
29
+ "@babel/preset-react": "^7.22.15",
30
+ "@babel/preset-typescript": "^7.23.2",
31
+ "@emotion/react": "^11.11.1",
32
+ "@emotion/styled": "^11.11.0",
33
+ "@mui/icons-material": "^5.14.13",
34
+ "@mui/material": "^5.14.13",
35
+ "autoprefixer": "^10.4.16",
36
+ "babel-loader": "^9.1.3",
37
+ "concurrently": "^8.2.1",
38
38
  "copy-and-watch": "^0.1.6",
39
- "css-loader": "^6.7.3",
39
+ "css-loader": "^6.8.1",
40
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",
41
+ "gh-pages": "^6.0.0",
42
+ "html-react-parser": "^4.2.5",
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.20",
49
- "postcss-loader": "^7.0.2",
48
+ "postcss": "^8.4.31",
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.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"
53
+ "style-loader": "^3.3.3",
54
+ "ts-loader": "^9.5.0",
55
+ "typescript": "^5.2.2",
56
+ "webpack": "^5.89.0",
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/",
62
62
  "repository": {
63
63
  "type": "git",
64
64
  "url": "git@github.com:jameshsu1125/lesca-validate.git"
65
+ },
66
+ "dependencies": {
67
+ "@babel/runtime": "^7.23.2"
65
68
  }
66
69
  }
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 { ValidateEmail, ValidatePhone, ValidateURL, ValidateYoutubeURL } from 'lesca-validate';
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
@@ -1,17 +1,25 @@
1
1
  import { Button, ButtonGroup, TextField } from '@mui/material';
2
2
  import { useRef, useState } from 'react';
3
- import { ValidateEmail, ValidatePhone, ValidateURL, ValidateYoutubeURL } from '../../lib';
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;
@@ -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