csec-form-validator 0.0.0-stage → 1.0.0

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.

Potentially problematic release.


This version of csec-form-validator might be problematic. Click here for more details.

Files changed (3) hide show
  1. package/index.js +44 -0
  2. package/package.json +10 -4
  3. package/README.md +0 -3
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 CHANGED
@@ -1,6 +1,12 @@
1
1
  {
2
2
  "name": "csec-form-validator",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
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.1"
11
+ }
12
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.