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 +25 -25
- package/README.md +68 -65
- package/dist/test.html +13 -0
- package/dist/utils/slugify.config.d.ts +2 -1
- package/dist/utils/slugify.config.js +6 -5
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +15 -0
- package/package.json +4 -2
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
|
-
|
|
21
|
-
'
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
//
|
|
40
|
-
'Hello World'.slugify(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
- **`
|
|
49
|
-
- **`
|
|
50
|
-
- **`
|
|
51
|
-
- **`
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
@@ -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
|
|
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.
|
|
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
|
-
|
|
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
|
|
220
|
+
function validateSlugifyConfig(builderOrConfig) {
|
|
220
221
|
const allowedChars = builderOrConfig.allowedChars;
|
|
221
222
|
const separator = builderOrConfig.separator;
|
|
222
223
|
const caseValue = builderOrConfig.case;
|
package/dist/utils.d.ts
ADDED
|
@@ -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.
|
|
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
|
}
|