frontacles 0.2.0 → 0.2.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/CHANGELOG.md CHANGED
@@ -8,11 +8,35 @@ Nothing for now.
8
8
 
9
9
  <!-- ⚠️ Before a new release, make sure the documentation doesn't contain any **unreleased** mention. -->
10
10
 
11
- Compare with [last published version](https://github.com/frontacles/frontacles/compare/0.2.0...main).
11
+ Compare with [last published version](https://github.com/frontacles/frontacles/compare/0.2.2...main).
12
12
 
13
- ## v1.4.0 (2025-02-28)
13
+ ## v0.2.2 (2025-03-01)
14
14
 
15
- Compare with [previous version](https://github.com/frontacles/frontacles/compare/dda10c3...0.2).
15
+ Compare with [last published version](https://github.com/frontacles/frontacles/compare/0.2.1...0.2.2).
16
+
17
+ ### Breaking
18
+
19
+ - Make `Email.username` and `Email.hostname` mutable to follow `URL.username` and `URL.hostname` behavior.
20
+
21
+ ### Improved
22
+
23
+ - Override documentation inherited from `URL` for `Email.username` and `Email.hostname`.
24
+
25
+ ## v0.2.1 (2025-02-28)
26
+
27
+ Compare with [previous version](https://github.com/frontacles/frontacles/compare/0.2.0...0.2.1).
28
+
29
+ ### Breaking
30
+
31
+ - Rename `Email.host` into `Email.hostname` to better match `URL`.
32
+
33
+ ### Improved
34
+
35
+ - `Email` is now a couple of bytes lighter.
36
+
37
+ ## v0.2.0 (2025-02-28)
38
+
39
+ Compare with [previous version](https://github.com/frontacles/frontacles/compare/dda10c3...0.2.0).
16
40
 
17
41
  ### New
18
42
 
package/README.md CHANGED
@@ -7,7 +7,7 @@ Cool utilities for front-end development (and potentially for Node).
7
7
 
8
8
  ## Email
9
9
 
10
- A class to instantiate an `Email` object or validate emails.
10
+ A class to instantiate an `Email` object or validate emails. It’s only [221 B compressed](https://bundlejs.com/?q=frontacles&treeshake=[{Email}]&config={%22compression%22%3A%22brotli%22}&bundle).
11
11
 
12
12
  Unlike most libraries using [RegEx for emails](https://github.com/colinhacks/zod/blob/e2b9a5f9ac67d13ada61cd8e4b1385eb850c7592/src/types.ts#L648-L663) (and prone to [bugs](https://github.com/colinhacks/zod/issues/3913)), Frontacles `Email` class relies on the same mechanism as your browser to validate email addresses, making it robust, and very likely RFC compliant.
13
13
 
@@ -17,18 +17,23 @@ import { Email } from 'frontacles/url/email'
17
17
  const email = new Email('someone@domain.tld')
18
18
  ```
19
19
 
20
- Get the username and the host separately.
20
+ Get or set the username and the hostname separately.
21
21
 
22
22
  ```js
23
23
  email.username // 'someone'
24
- email.host // 'domain.tld'
24
+ email.hostname // 'domain.tld'
25
+
26
+ email.hostname = 'newdomain.tld' // ✅ domain migrated
27
+
28
+ // destructuring also works
29
+ const { username, hostname } = new Email('someone@domain.tld')
25
30
  ```
26
31
 
27
32
  Turn the email object into a string by using it along another string, or use `toString`.
28
33
 
29
34
  ```js
30
- console.log(`email: ${email}`) // 'email: someone@domain.tld'
31
- console.log(email.toString()) // 'someone@domain.tld'
35
+ console.log(`email: ${email}`) // 'email: someone@newdomain.tld'
36
+ console.log(email.toString()) // 'someone@newdomain.tld'
32
37
  ```
33
38
 
34
39
  Validate that a string is a valid email address. It passes the complete Zod test suites, and beyond.
@@ -53,3 +58,27 @@ const alsoEmail = new Email(email) // ✅ a new Email object!
53
58
 
54
59
  Email.canParse(email) // ✅ true
55
60
  ```
61
+
62
+ ## Changelog
63
+
64
+ See [CHANGELOG.md](https://github.com/frontacles/frontacles/blob/main/CHANGELOG.md) or the [releases](https://github.com/frontacles/frontacles/releases).
65
+
66
+ ## Browser and tooling support
67
+
68
+ `frontacles` is provided [as module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#browser_compatibility) for [modern browsers usage](https://github.com/frontacles/frontacles/blob/main/browserslist) with standard JavaScript syntax:
69
+ - it is up to you to transpile it for legacy browsers;
70
+ - you can’t import it using `require('frontacles')`.
71
+
72
+ [Read more about ESModules](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
73
+
74
+ ## Security
75
+
76
+ See the [security policy](https://github.com/frontacles/frontacles/blob/main/SECURITY.md).
77
+
78
+ ## Contributing
79
+
80
+ See the [contributing guidelines](https://github.com/frontacles/frontacles/blob/main/CONTRIBUTING.md).
81
+
82
+ ## License
83
+
84
+ The _datetime-attribute_ package is open-sourced software licensed under the [DWTFYWTPL](https://github.com/frontacles/frontacles/blob/main/LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontacles",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Front-end utilities for artisans",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -16,6 +16,7 @@
16
16
  },
17
17
  "scripts": {
18
18
  "types": "tsc && dts-bundle-generator --silent --no-banner=true -o types/index.d.ts types-transitive/index.d.ts",
19
+ "posttypes": "node scripts/inject-jsdoc.mjs",
19
20
  "test": "vitest run",
20
21
  "test:types": "npm exec tsd",
21
22
  "test:ui": "vitest --ui --coverage.enabled --coverage.exclude=types",
package/src/url/email.js CHANGED
@@ -2,7 +2,6 @@
2
2
  export class Email extends URL {
3
3
 
4
4
  /**
5
- *
6
5
  * @param {string|Email} address An email address like `someone@domain.tld`.
7
6
  */
8
7
  constructor(address) {
@@ -13,26 +12,8 @@ export class Email extends URL {
13
12
  }
14
13
  }
15
14
 
16
- /**
17
- * The domain name and extension of the email.
18
- *
19
- * In `username@domain.tld`, it is `domain.tld`.
20
- */
21
- get host() {
22
- return super.host
23
- }
24
-
25
- /**
26
- * The username of the email.
27
- *
28
- * In `username@domain.tld`, it is `username`.
29
- */
30
- get username() {
31
- return super.username
32
- }
33
-
34
15
  toJSON () {
35
- return `${this.username}@${this.host}`
16
+ return this.toString()
36
17
  }
37
18
 
38
19
  /**
@@ -41,18 +22,16 @@ export class Email extends URL {
41
22
  * situation where type casting to string is involved (`console.log`…).
42
23
  */
43
24
  toString () {
44
- return `${this.username}@${this.host}`
25
+ return `${this.username}@${this.hostname}`
45
26
  }
46
27
 
47
28
  /**
48
- * Recompose the email address and compare it to the input. We also make sure
49
- * there is no port since `someone@domain.tld:3000` is valid for the `URL`
50
- * constructor but adds `:{port}` to `this.host` (`domain.tld:3000`).
29
+ * Recompose the email address and compare it to the input.
51
30
  *
52
31
  * @param {string} address
53
32
  */
54
33
  #validate (address) {
55
- return `${this.username}@${this.host}` == address && !this.port
34
+ return this.toString() == address
56
35
  }
57
36
 
58
37
  /**
package/types/index.d.ts CHANGED
@@ -1,28 +1,27 @@
1
1
  export function round(number: number, precision?: number): number;
2
2
  export class Email extends URL {
3
3
  /**
4
- * Whether or not an email address is parsable and valid.
4
+ * The domain name and extension of the email.
5
5
  *
6
- * @param {any|Email} address
6
+ * In `username@domain.tld`, it is `domain.tld`.
7
7
  */
8
- static canParse(address: any | Email): boolean;
8
+ declare hostname: string;
9
9
  /**
10
+ * The username of the email.
10
11
  *
11
- * @param {string|Email} address An email address like `someone@domain.tld`.
12
+ * In `username@domain.tld`, it is `username`.
12
13
  */
13
- constructor(address: string | Email);
14
+ declare username: string;
14
15
  /**
15
- * The domain name and extension of the email.
16
+ * Whether or not an email address is parsable and valid.
16
17
  *
17
- * In `username@domain.tld`, it is `domain.tld`.
18
+ * @param {any|Email} address
18
19
  */
19
- get host(): string;
20
+ static canParse(address: any | Email): boolean;
20
21
  /**
21
- * The username of the email.
22
- *
23
- * In `username@domain.tld`, it is `username`.
22
+ * @param {string|Email} address An email address like `someone@domain.tld`.
24
23
  */
25
- get username(): string;
24
+ constructor(address: string | Email);
26
25
  #private;
27
26
  }
28
27