frontacles 0.2.1 → 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,12 +8,28 @@ 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
+
13
+ ## v0.2.2 (2025-03-01)
14
+
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`.
12
24
 
13
25
  ## v0.2.1 (2025-02-28)
14
26
 
15
27
  Compare with [previous version](https://github.com/frontacles/frontacles/compare/0.2.0...0.2.1).
16
28
 
29
+ ### Breaking
30
+
31
+ - Rename `Email.host` into `Email.hostname` to better match `URL`.
32
+
17
33
  ### Improved
18
34
 
19
35
  - `Email` is now a couple of bytes lighter.
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. It’s only [222 B compressed](https://bundlejs.com/?q=frontacles&treeshake=[{Email}]&config={%22compression%22%3A%22brotli%22}&bundle).
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 hostname separately.
20
+ Get or set the username and the hostname separately.
21
21
 
22
22
  ```js
23
23
  email.username // 'someone'
24
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontacles",
3
- "version": "0.2.1",
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,24 +12,6 @@ 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 hostname() {
22
- return super.hostname
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
16
  return this.toString()
36
17
  }
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 hostname(): 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