utilitish 0.0.10 → 0.0.14

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/LICENSE.txt CHANGED
@@ -1,25 +1,25 @@
1
- GNU GENERAL PUBLIC LICENSE
2
- Version 3, 29 June 2007
3
-
4
- Copyright (C) 2025 Donovan Ferreira
5
-
6
- Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
7
-
8
- Preamble
9
-
10
- The GNU General Public License is a free, copyleft license for
11
- software and other kinds of works.
12
-
13
- The licenses for most software and other practical works are designed
14
- to take away your freedom to share and change the works. By contrast,
15
- the GNU General Public License is intended to guarantee your freedom to
16
- share and change all versions of a program--to make sure it remains free
17
- software for all its users. We, the Free Software Foundation, use the
18
- GNU General Public License for most of our software; it applies also to
19
- any other work released this way by its authors. You can apply it to
20
- your programs, too.
21
-
22
- [... contenu tronqué pour l’aperçu ...]
23
-
24
- You should have received a copy of the GNU General Public License
25
- along with this program. If not, see <https://www.gnu.org/licenses/>.
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2025 Donovan Ferreira
5
+
6
+ Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ The GNU General Public License is a free, copyleft license for
11
+ software and other kinds of works.
12
+
13
+ The licenses for most software and other practical works are designed
14
+ to take away your freedom to share and change the works. By contrast,
15
+ the GNU General Public License is intended to guarantee your freedom to
16
+ share and change all versions of a program--to make sure it remains free
17
+ software for all its users. We, the Free Software Foundation, use the
18
+ GNU General Public License for most of our software; it applies also to
19
+ any other work released this way by its authors. You can apply it to
20
+ your programs, too.
21
+
22
+ [... contenu tronqué pour l’aperçu ...]
23
+
24
+ You should have received a copy of the GNU General Public License
25
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
package/README.md CHANGED
@@ -1,65 +1,68 @@
1
- ## Licence
2
-
3
- Ce projet est distribué sous licence [GPL v3](https://www.gnu.org/licenses/gpl-3.0.html) © 2025 Donovan Ferreira.
4
-
5
- Ceci est une petite librairie qui ajoute plusieurs méthodes au prototype JavaScript.
6
-
7
- ## Configuration Slugify
8
-
9
- La méthode `slugify()` peut être personnalisée pour répondre à vos besoins spécifiques. Consultez la JSDoc dans votre IDE pour voir tous les exemples disponibles.
10
-
11
- ### Configuration globale
12
-
13
- Vous pouvez définir une configuration globale qui s'appliquera à tous les appels `slugify()` :
14
-
15
- ```typescript
16
- import { setSlugifyConfig } from 'utilitish';
17
-
18
- // Configuration pour remplacer les symboles de genre
19
- setSlugifyConfig({
20
- customReplacements: {
21
- '': 'feminin',
22
- '♂': 'masculin',
23
- },
24
- separator: '_',
25
- });
26
-
27
- 'Test ♀'.slugify(); // "test_feminin"
28
- 'User♂@domain.com'.slugify(); // "user_masculin_at_domain_com"
29
- ```
30
-
31
- ### Configuration par appel
32
-
33
- Vous pouvez aussi passer une configuration spécifique à chaque appel :
34
-
35
- ```typescript
36
- // Utilise la config globale
37
- 'Hello World'.slugify(); // "hello-world"
38
-
39
- // Override la config pour cet appel
40
- 'Hello World'.slugify({ separator: '_' }); // "hello_world"
41
- ```
42
-
43
- ### Options de configuration
44
-
45
- - **`customReplacements`**: Remplacer des caractères spécifiques (ex: "♀" → "feminin")
46
- - **`separator`**: Caractère de séparation (défaut: "-")
47
- - **`lowercase`**: Convertir en minuscules (défaut: true)
48
- - **`removeAccents`**: Supprimer les accents (défaut: true)
49
- - **`allowedChars`**: Regex des caractères autorisés (défaut: /[a-zA-Z0-9]/)
50
- - **`maxLength`**: Longueur maximale du slug
51
- - **`transformers`**: Fonctions de transformation personnalisées
52
-
53
- ### Gestion de la configuration
54
-
55
- ```typescript
56
- import { getSlugifyConfig, resetSlugifyConfig } from 'utilitish';
57
-
58
- // Obtenir la config actuelle
59
- const currentConfig = getSlugifyConfig();
60
-
61
- // Réinitialiser aux valeurs par défaut
62
- resetSlugifyConfig();
63
- ```
64
-
65
- Pour plus d'exemples et cas d'usage avancés, consultez les JSDoc intégrées dans votre IDE.
1
+ ## Licence
2
+
3
+ Ce projet est distribué sous licence [GPL v3](https://www.gnu.org/licenses/gpl-3.0.html) © 2025 Donovan Ferreira.
4
+
5
+ Ceci est une petite librairie qui ajoute plusieurs méthodes au prototype JavaScript.
6
+
7
+ ## Configuration Slugify
8
+
9
+ La méthode `slugify()` peut être personnalisée pour répondre à vos besoins spécifiques. Consultez la JSDoc dans votre IDE pour voir tous les exemples disponibles.
10
+
11
+ ### Configuration globale
12
+
13
+ Vous pouvez définir une configuration globale qui s'appliquera à tous les appels `slugify()` :
14
+
15
+ ```typescript
16
+ import { setSlugifyConfig } from 'utilitish';
17
+
18
+ // Configuration pour remplacer les symboles de genre
19
+ setSlugifyConfig(
20
+ SlugifyConfig.builder()
21
+ .withSeparator('_')
22
+ .withCustomReplacements({
23
+ '♀': 'feminin',
24
+ '♂': 'masculin',
25
+ '@': 'at',
26
+ })
27
+ .build(),
28
+ );
29
+
30
+ 'Test ♀'.slugify(); // "test_feminin"
31
+ 'User♂@domain.com'.slugify(); // "usermasculinatdomain_com"
32
+ ```
33
+
34
+ ### Configuration par appel
35
+
36
+ Vous pouvez aussi passer une configuration spécifique à chaque appel :
37
+
38
+ ```typescript
39
+ // Utilise la config globale
40
+ 'Hello World'.slugify(); // "hello-world"
41
+
42
+ // Override la config pour cet appel
43
+ 'Hello World'.slugify(SlugifyConfig.builder().withSeparator('_').build()); // "hello_world"
44
+ ```
45
+
46
+ ### Options de configuration
47
+
48
+ - **`customReplacements`**: Remplacer des caractères spécifiques (ex: "♀" → "feminin")
49
+ - **`separator`**: Caractère de séparation (défaut: "-")
50
+ - **`lowercase`**: Convertir en minuscules (défaut: true)
51
+ - **`removeAccents`**: Supprimer les accents (défaut: true)
52
+ - **`allowedChars`**: Regex des caractères autorisés (défaut: /[a-zA-Z0-9]/)
53
+ - **`maxLength`**: Longueur maximale du slug
54
+ - **`transformers`**: Fonctions de transformation personnalisées
55
+
56
+ ### Gestion de la configuration
57
+
58
+ ```typescript
59
+ import { getSlugifyConfig, resetSlugifyConfig } from 'utilitish';
60
+
61
+ // Obtenir la config actuelle
62
+ const currentConfig = getSlugifyConfig();
63
+
64
+ // Réinitialiser aux valeurs par défaut
65
+ resetSlugifyConfig();
66
+ ```
67
+
68
+ Pour plus d'exemples et cas d'usage avancés, consultez les JSDoc intégrées dans votre IDE.
package/dist/test.html ADDED
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta
6
+ name="viewport"
7
+ content="width=device-width, initial-scale=1.0"
8
+ />
9
+ <script src="index.js"></script>
10
+ <title>Document</title>
11
+ </head>
12
+ <body></body>
13
+ </html>
@@ -10,6 +10,7 @@ export declare class SlugifyConfig {
10
10
  private readonly _allowedChars?;
11
11
  private readonly _maxLength?;
12
12
  private readonly _transformers;
13
+ private readonly _isValidated;
13
14
  private constructor();
14
15
  static builder(): SlugifyConfigBuilder;
15
16
  static default(): SlugifyConfig;
@@ -83,7 +84,7 @@ export declare function getDefaultSlugifyConfig(): SlugifyConfig;
83
84
  * );
84
85
  */
85
86
  export declare function assertCharClass(regex: RegExp): void;
86
- export declare function assertSlugifyConfig(builderOrConfig: SlugifyConfigBuilder | SlugifyConfig): void;
87
+ export declare function validateSlugifyConfig(builderOrConfig: SlugifyConfigBuilder | SlugifyConfig): void;
87
88
  export declare function setSlugifyConfig(config: SlugifyConfig): void;
88
89
  /**
89
90
  * Gets the current global slugify configuration.
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SlugifyConfigBuilder = exports.SlugifyConfig = void 0;
4
4
  exports.getDefaultSlugifyConfig = getDefaultSlugifyConfig;
5
5
  exports.assertCharClass = assertCharClass;
6
- exports.assertSlugifyConfig = assertSlugifyConfig;
6
+ exports.validateSlugifyConfig = validateSlugifyConfig;
7
7
  exports.setSlugifyConfig = setSlugifyConfig;
8
8
  exports.getSlugifyConfig = getSlugifyConfig;
9
9
  exports.resetSlugifyConfig = resetSlugifyConfig;
@@ -12,7 +12,7 @@ exports.resetSlugifyConfig = resetSlugifyConfig;
12
12
  * Provides comprehensive customization options for URL slug generation.
13
13
  */
14
14
  class SlugifyConfig {
15
- constructor(builder) {
15
+ constructor(builder, isValidated = false) {
16
16
  this._customReplacements = builder.customReplacements;
17
17
  this._separator = builder.separator;
18
18
  this._case = builder.case;
@@ -20,6 +20,7 @@ class SlugifyConfig {
20
20
  this._allowedChars = builder.allowedChars;
21
21
  this._maxLength = builder.maxLength;
22
22
  this._transformers = builder.transformers;
23
+ this._isValidated = isValidated;
23
24
  }
24
25
  static builder() {
25
26
  return new SlugifyConfigBuilder();
@@ -28,8 +29,8 @@ class SlugifyConfig {
28
29
  return SlugifyConfig.builder().build();
29
30
  }
30
31
  static create(builder) {
31
- assertSlugifyConfig(builder);
32
- const config = new SlugifyConfig(builder);
32
+ validateSlugifyConfig(builder);
33
+ const config = new SlugifyConfig(builder, true);
33
34
  return Object.freeze(config);
34
35
  }
35
36
  get customReplacements() {
@@ -216,7 +217,7 @@ function assertCharClass(regex) {
216
217
  throw new Error(`Invalid allowedChars: must be a character class like /[a-z]/, received ${regex}`);
217
218
  }
218
219
  }
219
- function assertSlugifyConfig(builderOrConfig) {
220
+ function validateSlugifyConfig(builderOrConfig) {
220
221
  const allowedChars = builderOrConfig.allowedChars;
221
222
  const separator = builderOrConfig.separator;
222
223
  const caseValue = builderOrConfig.case;
@@ -0,0 +1 @@
1
+ export declare const defineIfNotExists: <T extends object>(prototype: T, name: string, fn: Function) => void;
package/dist/utils.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineIfNotExists = void 0;
4
+ const defineIfNotExists = (prototype, name, fn) => {
5
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, name);
6
+ if (!descriptor || descriptor.writable || descriptor.configurable) {
7
+ Object.defineProperty(prototype, name, {
8
+ value: fn,
9
+ enumerable: false,
10
+ configurable: false,
11
+ writable: false,
12
+ });
13
+ }
14
+ };
15
+ exports.defineIfNotExists = defineIfNotExists;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utilitish",
3
- "version": "0.0.10",
3
+ "version": "0.0.14",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/FDonovan12/utilitish.git"
@@ -18,7 +18,8 @@
18
18
  "scripts": {
19
19
  "build": "tsc",
20
20
  "test": "jest",
21
- "docs": "typedoc"
21
+ "docs": "typedoc",
22
+ "release": "npm version patch && git push --follow-tags && npm publish"
22
23
  },
23
24
  "keywords": [
24
25
  "typescript",
@@ -31,6 +32,7 @@
31
32
  "@types/jest": "^29.5.14",
32
33
  "jest": "^29.7.0",
33
34
  "ts-jest": "^29.3.4",
35
+ "ts-node": "^10.9.2",
34
36
  "typedoc": "^0.28.10",
35
37
  "typescript": "^5.8.3"
36
38
  }