utilitish 0.0.18 → 0.0.20

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.
@@ -1,56 +1,54 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const logic_utils_1 = require("./logic.utils");
1
+ import { sortBy } from './logic.utils';
4
2
  describe('logic.utils', () => {
5
3
  describe('sortBy()', () => {
6
4
  describe('with primitive arrays', () => {
7
5
  it('should sort numbers in ascending order', () => {
8
- expect((0, logic_utils_1.sortBy)([3, 1, 2], 'asc')).toEqual([1, 2, 3]);
6
+ expect(sortBy([3, 1, 2], 'asc')).toEqual([1, 2, 3]);
9
7
  });
10
8
  it('should sort numbers in descending order', () => {
11
- expect((0, logic_utils_1.sortBy)([1, 3, 2], 'desc')).toEqual([3, 2, 1]);
9
+ expect(sortBy([1, 3, 2], 'desc')).toEqual([3, 2, 1]);
12
10
  });
13
11
  it('should sort strings in ascending order', () => {
14
- expect((0, logic_utils_1.sortBy)(['b', 'a', 'c'], 'asc')).toEqual(['a', 'b', 'c']);
12
+ expect(sortBy(['b', 'a', 'c'], 'asc')).toEqual(['a', 'b', 'c']);
15
13
  });
16
14
  it('should sort strings in descending order', () => {
17
- expect((0, logic_utils_1.sortBy)(['b', 'a', 'c'], 'desc')).toEqual(['c', 'b', 'a']);
15
+ expect(sortBy(['b', 'a', 'c'], 'desc')).toEqual(['c', 'b', 'a']);
18
16
  });
19
17
  it('should return empty array when input is empty', () => {
20
- expect((0, logic_utils_1.sortBy)([], 'asc')).toEqual([]);
18
+ expect(sortBy([], 'asc')).toEqual([]);
21
19
  });
22
20
  it('should not mutate the original array', () => {
23
21
  const arr = [3, 1, 2];
24
- (0, logic_utils_1.sortBy)(arr, 'asc');
22
+ sortBy(arr, 'asc');
25
23
  expect(arr).toEqual([3, 1, 2]);
26
24
  });
27
25
  });
28
26
  describe('with selector function', () => {
29
27
  it('should sort in ascending order using selector', () => {
30
28
  const arr = [{ v: 3 }, { v: 1 }, { v: 2 }];
31
- expect((0, logic_utils_1.sortBy)(arr, 'asc', (x) => x.v)).toEqual([{ v: 1 }, { v: 2 }, { v: 3 }]);
29
+ expect(sortBy(arr, 'asc', (x) => x.v)).toEqual([{ v: 1 }, { v: 2 }, { v: 3 }]);
32
30
  });
33
31
  it('should sort in descending order using selector', () => {
34
32
  const arr = [{ v: 1 }, { v: 3 }, { v: 2 }];
35
- expect((0, logic_utils_1.sortBy)(arr, 'desc', (x) => x.v)).toEqual([{ v: 3 }, { v: 2 }, { v: 1 }]);
33
+ expect(sortBy(arr, 'desc', (x) => x.v)).toEqual([{ v: 3 }, { v: 2 }, { v: 1 }]);
36
34
  });
37
35
  });
38
36
  describe('with selector string key', () => {
39
37
  it('should sort in ascending order using property key', () => {
40
38
  const arr = [{ v: 3 }, { v: 1 }, { v: 2 }];
41
- expect((0, logic_utils_1.sortBy)(arr, 'asc', 'v')).toEqual([{ v: 1 }, { v: 2 }, { v: 3 }]);
39
+ expect(sortBy(arr, 'asc', 'v')).toEqual([{ v: 1 }, { v: 2 }, { v: 3 }]);
42
40
  });
43
41
  it('should sort in descending order using property key', () => {
44
42
  const arr = [{ v: 1 }, { v: 3 }, { v: 2 }];
45
- expect((0, logic_utils_1.sortBy)(arr, 'desc', 'v')).toEqual([{ v: 3 }, { v: 2 }, { v: 1 }]);
43
+ expect(sortBy(arr, 'desc', 'v')).toEqual([{ v: 3 }, { v: 2 }, { v: 1 }]);
46
44
  });
47
45
  });
48
46
  describe('error handling', () => {
49
47
  it('should throw TypeError when elements are not sortable without selector', () => {
50
- expect(() => (0, logic_utils_1.sortBy)([{ v: 1 }], 'asc')).toThrow(TypeError);
48
+ expect(() => sortBy([{ v: 1 }], 'asc')).toThrow(TypeError);
51
49
  });
52
50
  it('should throw TypeError when selector returns non-sortable value', () => {
53
- expect(() => (0, logic_utils_1.sortBy)([{ v: {} }], 'asc', (x) => x.v)).toThrow(TypeError);
51
+ expect(() => sortBy([{ v: {} }], 'asc', (x) => x.v)).toThrow(TypeError);
54
52
  });
55
53
  });
56
54
  });
@@ -1,18 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SlugifyConfigBuilder = exports.SlugifyConfig = void 0;
4
- exports.getDefaultSlugifyConfig = getDefaultSlugifyConfig;
5
- exports.assertCharClass = assertCharClass;
6
- exports.assertSlugifyConfig = assertSlugifyConfig;
7
- exports.setSlugifyConfig = setSlugifyConfig;
8
- exports.getSlugifyConfig = getSlugifyConfig;
9
- exports.resetSlugifyConfig = resetSlugifyConfig;
10
- exports.slugifyString = slugifyString;
11
1
  /**
12
2
  * Configuration class for the slugify functionality.
13
3
  * Provides comprehensive customization options for URL slug generation.
14
4
  */
15
- class SlugifyConfig {
5
+ export class SlugifyConfig {
16
6
  constructor(builder) {
17
7
  this._customReplacements = builder.customReplacements;
18
8
  this._separator = builder.separator;
@@ -142,8 +132,7 @@ class SlugifyConfig {
142
132
  return config.slugify(str);
143
133
  }
144
134
  }
145
- exports.SlugifyConfig = SlugifyConfig;
146
- class SlugifyConfigBuilder {
135
+ export class SlugifyConfigBuilder {
147
136
  constructor() {
148
137
  this.customReplacements = {};
149
138
  this.separator = '-';
@@ -184,12 +173,11 @@ class SlugifyConfigBuilder {
184
173
  return config;
185
174
  }
186
175
  }
187
- exports.SlugifyConfigBuilder = SlugifyConfigBuilder;
188
176
  /**
189
177
  * Default configuration for slugify operations.
190
178
  * Provides sensible defaults that can be overridden by users.
191
179
  */
192
- function getDefaultSlugifyConfig() {
180
+ export function getDefaultSlugifyConfig() {
193
181
  return SlugifyConfig.default();
194
182
  }
195
183
  /**
@@ -211,13 +199,13 @@ let globalSlugifyConfig = getDefaultSlugifyConfig();
211
199
  * .build()
212
200
  * );
213
201
  */
214
- function assertCharClass(regex) {
202
+ export function assertCharClass(regex) {
215
203
  const src = regex.source;
216
204
  if (!src.startsWith('[') || !src.endsWith(']')) {
217
205
  throw new Error(`Invalid allowedChars: must be a character class like /[a-z]/, received ${regex}`);
218
206
  }
219
207
  }
220
- function assertSlugifyConfig(builderOrConfig) {
208
+ export function assertSlugifyConfig(builderOrConfig) {
221
209
  const allowedChars = builderOrConfig.allowedChars;
222
210
  const separator = builderOrConfig.separator;
223
211
  const caseValue = builderOrConfig.case;
@@ -252,7 +240,7 @@ function assertSlugifyConfig(builderOrConfig) {
252
240
  throw new TypeError(`Invalid transformers: expected an array of functions`);
253
241
  }
254
242
  }
255
- function setSlugifyConfig(config) {
243
+ export function setSlugifyConfig(config) {
256
244
  globalSlugifyConfig = config;
257
245
  }
258
246
  /**
@@ -261,13 +249,13 @@ function setSlugifyConfig(config) {
261
249
  *
262
250
  * @returns Current global configuration object
263
251
  */
264
- function getSlugifyConfig() {
252
+ export function getSlugifyConfig() {
265
253
  return globalSlugifyConfig;
266
254
  }
267
255
  /**
268
256
  * Resets the global slugify configuration to default values.
269
257
  */
270
- function resetSlugifyConfig() {
258
+ export function resetSlugifyConfig() {
271
259
  globalSlugifyConfig = getDefaultSlugifyConfig();
272
260
  }
273
261
  /**
@@ -278,7 +266,7 @@ function resetSlugifyConfig() {
278
266
  * @param config - Configuration object (uses global config if not provided)
279
267
  * @returns The slugified string
280
268
  */
281
- function slugifyString(str, config) {
269
+ export function slugifyString(str, config) {
282
270
  // Merge provided config with global config
283
271
  const globalConfig = getSlugifyConfig();
284
272
  const finalConfig = config ? globalConfig.merge(config) : globalConfig;
@@ -1,60 +1,58 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const slugify_config_1 = require("./slugify.config");
1
+ import { SlugifyConfig, assertCharClass, assertSlugifyConfig, getDefaultSlugifyConfig, getSlugifyConfig, resetSlugifyConfig, setSlugifyConfig, } from './slugify.config';
4
2
  describe('slugify.config', () => {
5
3
  afterEach(() => {
6
- (0, slugify_config_1.resetSlugifyConfig)();
4
+ resetSlugifyConfig();
7
5
  });
8
6
  describe('SlugifyConfig.default()', () => {
9
7
  it('should return a config with default separator', () => {
10
- expect((0, slugify_config_1.getDefaultSlugifyConfig)().separator).toBe('-');
8
+ expect(getDefaultSlugifyConfig().separator).toBe('-');
11
9
  });
12
10
  it('should return a config with lowercase case', () => {
13
- expect((0, slugify_config_1.getDefaultSlugifyConfig)().case).toBe('lower');
11
+ expect(getDefaultSlugifyConfig().case).toBe('lower');
14
12
  });
15
13
  it('should return a config with removeAccents enabled', () => {
16
- expect((0, slugify_config_1.getDefaultSlugifyConfig)().removeAccents).toBe(true);
14
+ expect(getDefaultSlugifyConfig().removeAccents).toBe(true);
17
15
  });
18
16
  });
19
17
  describe('SlugifyConfig.slugify()', () => {
20
18
  describe('with default config', () => {
21
19
  it('should convert to lowercase', () => {
22
- expect(slugify_config_1.SlugifyConfig.default().slugify('Hello World')).toBe('hello-world');
20
+ expect(SlugifyConfig.default().slugify('Hello World')).toBe('hello-world');
23
21
  });
24
22
  it('should replace spaces with separator', () => {
25
- expect(slugify_config_1.SlugifyConfig.default().slugify('foo bar')).toBe('foo-bar');
23
+ expect(SlugifyConfig.default().slugify('foo bar')).toBe('foo-bar');
26
24
  });
27
25
  it('should remove accents', () => {
28
- expect(slugify_config_1.SlugifyConfig.default().slugify('Héllo')).toBe('hello');
26
+ expect(SlugifyConfig.default().slugify('Héllo')).toBe('hello');
29
27
  });
30
28
  it('should collapse multiple separators', () => {
31
- expect(slugify_config_1.SlugifyConfig.default().slugify('foo bar')).toBe('foo-bar');
29
+ expect(SlugifyConfig.default().slugify('foo bar')).toBe('foo-bar');
32
30
  });
33
31
  it('should trim leading and trailing separators', () => {
34
- expect(slugify_config_1.SlugifyConfig.default().slugify(' foo ')).toBe('foo');
32
+ expect(SlugifyConfig.default().slugify(' foo ')).toBe('foo');
35
33
  });
36
34
  });
37
35
  describe('with custom separator', () => {
38
36
  it('should use custom separator', () => {
39
- const config = slugify_config_1.SlugifyConfig.builder().withSeparator('_').build();
37
+ const config = SlugifyConfig.builder().withSeparator('_').build();
40
38
  expect(config.slugify('hello world')).toBe('hello_world');
41
39
  });
42
40
  });
43
41
  describe('with maxLength', () => {
44
42
  it('should truncate to maxLength', () => {
45
- const config = slugify_config_1.SlugifyConfig.builder().withMaxLength(5).build();
43
+ const config = SlugifyConfig.builder().withMaxLength(5).build();
46
44
  expect(config.slugify('hello world').length).toBeLessThanOrEqual(5);
47
45
  });
48
46
  });
49
47
  describe('with custom replacements', () => {
50
48
  it('should apply custom replacements before slugifying', () => {
51
- const config = slugify_config_1.SlugifyConfig.builder().withCustomReplacements({ '&': 'and' }).build();
49
+ const config = SlugifyConfig.builder().withCustomReplacements({ '&': 'and' }).build();
52
50
  expect(config.slugify('cats & dogs')).toBe('cats-and-dogs');
53
51
  });
54
52
  });
55
53
  describe('with transformers', () => {
56
54
  it('should apply transformers before slugifying', () => {
57
- const config = slugify_config_1.SlugifyConfig.builder()
55
+ const config = SlugifyConfig.builder()
58
56
  .withTransformers([(s) => s.replace('foo', 'bar')])
59
57
  .build();
60
58
  expect(config.slugify('foo baz')).toBe('bar-baz');
@@ -63,82 +61,82 @@ describe('slugify.config', () => {
63
61
  });
64
62
  describe('SlugifyConfig.slugifyWith()', () => {
65
63
  it('should slugify with a temporary configuration', () => {
66
- const result = slugify_config_1.SlugifyConfig.slugifyWith('hello world', (b) => b.withSeparator('_'));
64
+ const result = SlugifyConfig.slugifyWith('hello world', (b) => b.withSeparator('_'));
67
65
  expect(result).toBe('hello_world');
68
66
  });
69
67
  });
70
68
  describe('SlugifyConfig.merge()', () => {
71
69
  it('should merge two configs with the other taking precedence', () => {
72
- const base = slugify_config_1.SlugifyConfig.builder().withSeparator('-').build();
73
- const other = slugify_config_1.SlugifyConfig.builder().withSeparator('_').build();
70
+ const base = SlugifyConfig.builder().withSeparator('-').build();
71
+ const other = SlugifyConfig.builder().withSeparator('_').build();
74
72
  expect(base.merge(other).separator).toBe('_');
75
73
  });
76
74
  });
77
75
  describe('assertCharClass()', () => {
78
76
  it('should not throw for a valid character class', () => {
79
- expect(() => (0, slugify_config_1.assertCharClass)(/[a-z]/)).not.toThrow();
77
+ expect(() => assertCharClass(/[a-z]/)).not.toThrow();
80
78
  });
81
79
  describe('error handling', () => {
82
80
  it('should throw Error for a regex that is not a character class', () => {
83
- expect(() => (0, slugify_config_1.assertCharClass)(/a-z/)).toThrow(Error);
81
+ expect(() => assertCharClass(/a-z/)).toThrow(Error);
84
82
  });
85
83
  });
86
84
  });
87
85
  describe('assertSlugifyConfig()', () => {
88
86
  it('should not throw for a valid builder', () => {
89
- expect(() => (0, slugify_config_1.assertSlugifyConfig)(slugify_config_1.SlugifyConfig.builder())).not.toThrow();
87
+ expect(() => assertSlugifyConfig(SlugifyConfig.builder())).not.toThrow();
90
88
  });
91
89
  describe('error handling', () => {
92
90
  it('should throw TypeError for invalid separator', () => {
93
- const builder = slugify_config_1.SlugifyConfig.builder();
91
+ const builder = SlugifyConfig.builder();
94
92
  builder.separator = 123;
95
- expect(() => (0, slugify_config_1.assertSlugifyConfig)(builder)).toThrow(TypeError);
93
+ expect(() => assertSlugifyConfig(builder)).toThrow(TypeError);
96
94
  });
97
95
  it('should throw TypeError for invalid case value', () => {
98
- const builder = slugify_config_1.SlugifyConfig.builder();
96
+ const builder = SlugifyConfig.builder();
99
97
  builder.case = 'invalid';
100
- expect(() => (0, slugify_config_1.assertSlugifyConfig)(builder)).toThrow(TypeError);
98
+ expect(() => assertSlugifyConfig(builder)).toThrow(TypeError);
101
99
  });
102
100
  it('should throw TypeError for invalid removeAccents', () => {
103
- const builder = slugify_config_1.SlugifyConfig.builder();
101
+ const builder = SlugifyConfig.builder();
104
102
  builder.removeAccents = 'yes';
105
- expect(() => (0, slugify_config_1.assertSlugifyConfig)(builder)).toThrow(TypeError);
103
+ expect(() => assertSlugifyConfig(builder)).toThrow(TypeError);
106
104
  });
107
105
  it('should throw TypeError for invalid maxLength', () => {
108
- const builder = slugify_config_1.SlugifyConfig.builder();
106
+ const builder = SlugifyConfig.builder();
109
107
  builder.maxLength = -1;
110
- expect(() => (0, slugify_config_1.assertSlugifyConfig)(builder)).toThrow(TypeError);
108
+ expect(() => assertSlugifyConfig(builder)).toThrow(TypeError);
111
109
  });
112
110
  it('should throw TypeError for invalid allowedChars', () => {
113
- const builder = slugify_config_1.SlugifyConfig.builder();
111
+ const builder = SlugifyConfig.builder();
114
112
  builder.allowedChars = 'not-a-regex';
115
- expect(() => (0, slugify_config_1.assertSlugifyConfig)(builder)).toThrow(TypeError);
113
+ expect(() => assertSlugifyConfig(builder)).toThrow(TypeError);
116
114
  });
117
115
  it('should throw TypeError for invalid transformers', () => {
118
- const builder = slugify_config_1.SlugifyConfig.builder();
116
+ const builder = SlugifyConfig.builder();
119
117
  builder.transformers = ['not-a-function'];
120
- expect(() => (0, slugify_config_1.assertSlugifyConfig)(builder)).toThrow(TypeError);
118
+ expect(() => assertSlugifyConfig(builder)).toThrow(TypeError);
121
119
  });
122
120
  });
123
121
  });
124
122
  describe('getSlugifyConfig()', () => {
125
123
  it('should return the default config initially', () => {
126
- expect((0, slugify_config_1.getSlugifyConfig)().separator).toBe('-');
124
+ expect(getSlugifyConfig().separator).toBe('-');
127
125
  });
128
126
  });
129
127
  describe('setSlugifyConfig()', () => {
130
128
  it('should update the global config', () => {
131
- const config = slugify_config_1.SlugifyConfig.builder().withSeparator('_').build();
132
- (0, slugify_config_1.setSlugifyConfig)(config);
133
- expect((0, slugify_config_1.getSlugifyConfig)().separator).toBe('_');
129
+ const config = SlugifyConfig.builder().withSeparator('_').build();
130
+ setSlugifyConfig(config);
131
+ expect(getSlugifyConfig().separator).toBe('_');
134
132
  });
135
133
  });
136
134
  describe('resetSlugifyConfig()', () => {
137
135
  it('should restore the default config', () => {
138
- const config = slugify_config_1.SlugifyConfig.builder().withSeparator('_').build();
139
- (0, slugify_config_1.setSlugifyConfig)(config);
140
- (0, slugify_config_1.resetSlugifyConfig)();
141
- expect((0, slugify_config_1.getSlugifyConfig)().separator).toBe('-');
136
+ const config = SlugifyConfig.builder().withSeparator('_').build();
137
+ setSlugifyConfig(config);
138
+ resetSlugifyConfig();
139
+ expect(getSlugifyConfig().separator).toBe('-');
142
140
  });
143
141
  });
144
142
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utilitish",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/FDonovan12/utilitish.git"
@@ -10,8 +10,15 @@
10
10
  "provenance": false
11
11
  },
12
12
  "description": "",
13
+ "type": "module",
13
14
  "main": "dist/index.js",
14
15
  "types": "dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "import": "./dist/index.js",
19
+ "types": "./dist/index.d.ts"
20
+ }
21
+ },
15
22
  "files": [
16
23
  "dist"
17
24
  ],