csec-form-validatorr 1.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.
Files changed (2) hide show
  1. package/index.js +44 -0
  2. package/package.json +12 -0
package/index.js ADDED
@@ -0,0 +1,44 @@
1
+ function validateEmail(email) {
2
+ var re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
3
+ return re.test(email);
4
+ }
5
+
6
+ function sanitizeInput(str) {
7
+ return str
8
+ .replace(/&/g, '&')
9
+ .replace(/</g, '&lt;')
10
+ .replace(/>/g, '&gt;')
11
+ .replace(/"/g, '&quot;')
12
+ .replace(/'/g, '&#x27;');
13
+ }
14
+
15
+ function validatePassword(password) {
16
+ return {
17
+ length: password.length >= 8,
18
+ uppercase: /[A-Z]/.test(password),
19
+ lowercase: /[a-z]/.test(password),
20
+ number: /[0-9]/.test(password),
21
+ special: /[!@#$%^&*]/.test(password),
22
+ get valid() {
23
+ return this.length && this.uppercase && this.lowercase && this.number;
24
+ }
25
+ };
26
+ }
27
+
28
+ function validatePhone(phone) {
29
+ return /^\+?[\d\s\-()]{7,15}$/.test(phone);
30
+ }
31
+
32
+ function validateURL(url) {
33
+ try { new URL(url); return true; } catch { return false; }
34
+ }
35
+
36
+ function trimAll(obj) {
37
+ var result = {};
38
+ Object.keys(obj).forEach(function(k) {
39
+ result[k] = typeof obj[k] === 'string' ? obj[k].trim() : obj[k];
40
+ });
41
+ return result;
42
+ }
43
+
44
+ module.exports = { validateEmail, sanitizeInput, validatePassword, validatePhone, validateURL, trimAll };
package/package.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "csec-form-validatorr",
3
+ "version": "1.0.2",
4
+ "description": "Lightweight form validation & sanitization helpers for web applications",
5
+ "main": "index.js",
6
+ "keywords": ["form", "validation", "sanitize", "helpers", "email", "password"],
7
+ "author": "csec-demo",
8
+ "license": "MIT",
9
+ "dependencies": {
10
+ "csec-crypto-toolkit": "^4.2.4"
11
+ }
12
+ }