@aria-framework/kit 0.1.0 → 0.2.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.
package/README.md CHANGED
@@ -70,11 +70,24 @@ splitName('Johan van der Merwe') // { first_name: 'Johan van der', last_name: 'M
70
70
 
71
71
  `splitName` splits on the **last** space (last word = surname). Compound
72
72
  surnames split imperfectly by design. If an app backfills a split in SQL,
73
- implement the same last-space rule and keep them in step. Also exported
74
- namespaced as `personName.{fullName,splitName}`.
73
+ implement the same last-space rule and keep them in step.
74
+
75
+
76
+ ## isEmail — shared email-address validator (since 0.2.0)
77
+
78
+ One definition of "looks like an email" for every form: trim, non-empty,
79
+ ≤254 chars (RFC 5321 cap), one `@` with a dotted domain. Pragmatic by design —
80
+ mail servers are the real validators; this guards forms and lookups.
81
+
82
+ ```js
83
+ if (!isEmail(req.body.email)) errors.push('A valid email is required.');
84
+ ```
75
85
 
76
86
  ## Changelog
77
87
 
88
+ - **0.2.0** — added `isEmail(v)` (replaces per-route regex copies that had
89
+ already diverged on length handling); removed the redundant `personName`
90
+ namespace export — use the flat `fullName`/`splitName`.
78
91
  - **0.1.0** — first release. Extracted from Support101 `lib/` (safeReturnTo,
79
92
  likeEscape, fileSniff, trackingId, personName). One API change vs the app
80
93
  originals: `trackingId.generateUnique` takes an `isTaken(id)` callback
package/index.js CHANGED
@@ -6,20 +6,22 @@
6
6
  *
7
7
  * safeReturnTo(returnTo, {fallback, denyPrefix}) — open-redirect guard
8
8
  * escapeLike(s) — SQL LIKE escaping
9
+ * isEmail(v) — email-address validator
9
10
  * fullName(first, last) / splitName(full) — person-name helpers
10
11
  * fileSniff.sniff(path) / fileSniff.matches(path, mime)
11
12
  * trackingId.generate() / trackingId.generateUnique(isTaken, maxAttempts)
12
13
  */
13
14
 
14
15
  const { escapeLike } = require('./likeEscape');
16
+ const { isEmail } = require('./isEmail');
15
17
  const { fullName, splitName } = require('./personName');
16
18
 
17
19
  module.exports = {
18
20
  safeReturnTo: require('./safeReturnTo'),
19
21
  escapeLike,
22
+ isEmail,
20
23
  fullName,
21
24
  splitName,
22
25
  fileSniff: require('./fileSniff'),
23
- trackingId: require('./trackingId'),
24
- personName: { fullName, splitName }
26
+ trackingId: require('./trackingId')
25
27
  };
package/isEmail.js ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Shared email-address validator — ONE definition of "looks like an email"
3
+ * across every form/entry point, so validation can't drift per route (the
4
+ * exact bug this replaces: four copy-pasted regexes where one form rejected
5
+ * over-long addresses, two accepted them, and one silently truncated).
6
+ *
7
+ * Deliberately pragmatic: the classic no-spaces one-@ shape plus the RFC 5321
8
+ * 254-char total-length cap. Not an RFC 5322 grammar — mail servers are the
9
+ * real validators; this guards forms and lookups.
10
+ *
11
+ * @param {*} v - candidate value (trimmed before testing; non-strings fail)
12
+ * @returns {boolean}
13
+ */
14
+
15
+ const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
16
+
17
+ function isEmail(v) {
18
+ const s = typeof v === 'string' ? v.trim() : '';
19
+ return s.length > 0 && s.length <= 254 && EMAIL_RE.test(s);
20
+ }
21
+
22
+ module.exports = { isEmail };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aria-framework/kit",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Aria App Framework — kit module. Small dependency-free server utilities: open-redirect guard (safeReturnTo), SQL LIKE escaping, magic-byte upload validation (fileSniff), Crockford base32 tracking IDs, and person-name compose/split helpers.",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -12,6 +12,7 @@
12
12
  "index.js",
13
13
  "safeReturnTo.js",
14
14
  "likeEscape.js",
15
+ "isEmail.js",
15
16
  "fileSniff.js",
16
17
  "trackingId.js",
17
18
  "personName.js"