@bgord/tools 1.1.9 → 1.1.12

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/dist/index.d.ts CHANGED
@@ -75,6 +75,7 @@ export * from "./rounding.adapter";
75
75
  export * from "./rounding.port";
76
76
  export * from "./size.vo";
77
77
  export * from "./size-bytes.vo";
78
+ export * from "./slug.service";
78
79
  export * from "./stopwatch.service";
79
80
  export * from "./sum.service";
80
81
  export * from "./thousands-separator.service";
package/dist/index.js CHANGED
@@ -75,6 +75,7 @@ export * from "./rounding.adapter";
75
75
  export * from "./rounding.port";
76
76
  export * from "./size.vo";
77
77
  export * from "./size-bytes.vo";
78
+ export * from "./slug.service";
78
79
  export * from "./stopwatch.service";
79
80
  export * from "./sum.service";
80
81
  export * from "./thousands-separator.service";
package/dist/mime.vo.d.ts CHANGED
@@ -5,7 +5,8 @@ export declare const MimeError: {
5
5
  export declare class Mime {
6
6
  readonly type: string;
7
7
  readonly subtype: string;
8
- constructor(candidate: string);
8
+ private constructor();
9
+ static fromString(candidate: string): Mime;
9
10
  static fromExtension(extension: ExtensionType): Mime;
10
11
  isSatisfiedBy(another: Mime): boolean;
11
12
  toExtension(): ExtensionType;
package/dist/mime.vo.js CHANGED
@@ -5,13 +5,17 @@ export const MimeError = { NotAccepted: "mime.not.accepted" };
5
5
  export class Mime {
6
6
  type;
7
7
  subtype;
8
- constructor(candidate) {
9
- const { type, subtype } = MimeValue.parse(candidate);
8
+ constructor(type, subtype) {
10
9
  this.type = type;
11
10
  this.subtype = subtype;
12
11
  }
12
+ static fromString(candidate) {
13
+ const { type, subtype } = MimeValue.parse(candidate);
14
+ return new Mime(type, subtype);
15
+ }
13
16
  static fromExtension(extension) {
14
- return new Mime(String(mime.contentType(extension)));
17
+ const { type, subtype } = MimeValue.parse(String(mime.contentType(extension)));
18
+ return new Mime(type, subtype);
15
19
  }
16
20
  isSatisfiedBy(another) {
17
21
  if (!(this.type === another.type || this.type === "*"))
@@ -29,8 +33,8 @@ export class Mime {
29
33
  }
30
34
  }
31
35
  export const MIMES = {
32
- csv: new Mime("text/csv"),
33
- text: new Mime("text/plain"),
34
- markdown: new Mime("text/markdown"),
35
- pdf: new Mime("application/pdf"),
36
+ csv: Mime.fromString("text/csv"),
37
+ text: Mime.fromString("text/plain"),
38
+ markdown: Mime.fromString("text/markdown"),
39
+ pdf: Mime.fromString("application/pdf"),
36
40
  };
@@ -0,0 +1,4 @@
1
+ export declare class Slug {
2
+ private static WHITELIST;
3
+ static generate(input: string, separator?: string): string;
4
+ }
@@ -0,0 +1,15 @@
1
+ export class Slug {
2
+ // Any letter or any number
3
+ static WHITELIST = /[\p{L}\p{N}]/u;
4
+ static generate(input, separator = "-") {
5
+ return (input
6
+ .split("")
7
+ .map((character) => (Slug.WHITELIST.test(character) ? character : separator))
8
+ .join("")
9
+ // Collapse multiple consecutive separators
10
+ .replace(new RegExp(`\\${separator}+`, "g"), separator)
11
+ // Trim leading and trailing separators
12
+ .replace(new RegExp(`^\\${separator}|\\${separator}$`, "g"), "")
13
+ .toLocaleLowerCase());
14
+ }
15
+ }
@@ -1 +1 @@
1
- {"root":["../src/age-years.vo.ts","../src/age.vo.ts","../src/api-key.vo.ts","../src/basename.vo.ts","../src/clock-format.service.ts","../src/clock.vo.ts","../src/date-calculator.service.ts","../src/date-formatter.service.ts","../src/date-range.vo.ts","../src/day-iso-id.vo.ts","../src/day.vo.ts","../src/directory-path-absolute.vo.ts","../src/directory-path-relative.vo.ts","../src/division-factor.vo.ts","../src/dll.service.ts","../src/duration-ms.vo.ts","../src/duration.service.ts","../src/email-mask.service.ts","../src/etags.vo.ts","../src/extension.vo.ts","../src/feature-flag-value.vo.ts","../src/feature-flag.vo.ts","../src/file-path-absolute-schema.vo.ts","../src/file-path-relative-schema.vo.ts","../src/file-path.vo.ts","../src/filename-affix.vo.ts","../src/filename-from-string.vo.ts","../src/filename.vo.ts","../src/height-milimiters.vo.ts","../src/height.vo.ts","../src/hour-format.service.ts","../src/hour-schema.vo.ts","../src/hour.vo.ts","../src/iban-mask.service.ts","../src/iban-schema.vo.ts","../src/iban.vo.ts","../src/image.vo.ts","../src/index.ts","../src/language.vo.ts","../src/linear-regression.service.ts","../src/mean.service.ts","../src/mime-types.vo.ts","../src/mime-value.vo.ts","../src/mime.vo.ts","../src/min-max-scaler.service.ts","../src/minute-schema.vo.ts","../src/minute.vo.ts","../src/money-amount.vo.ts","../src/money.vo.ts","../src/month-iso-id.vo.ts","../src/month.vo.ts","../src/multiplication-factor.vo.ts","../src/noop.service.ts","../src/notification-template.vo.ts","../src/object-key.vo.ts","../src/outlier-detector.service.ts","../src/package-version-schema.vo.ts","../src/package-version.vo.ts","../src/pagination-page.vo.ts","../src/pagination-skip.vo.ts","../src/pagination-take.vo.ts","../src/pagination.service.ts","../src/percentage.service.ts","../src/population-standard-deviation.service.ts","../src/quarter-iso-id.vo.ts","../src/quarter.vo.ts","../src/random.service.ts","../src/rate-limiter.service.ts","../src/relative-date.vo.ts","../src/reordering-item-position-value.vo.ts","../src/reordering.service.ts","../src/revision-value.vo.ts","../src/revision.vo.ts","../src/rounding.adapter.ts","../src/rounding.port.ts","../src/size-bytes.vo.ts","../src/size.vo.ts","../src/stopwatch.service.ts","../src/sum.service.ts","../src/thousands-separator.service.ts","../src/time-zone-offset-value.vo.ts","../src/timestamp-value.vo.ts","../src/timestamp.vo.ts","../src/timezone.vo.ts","../src/ts-utils.ts","../src/visually-unambiguous-characters-generator.service.ts","../src/week-iso-id.vo.ts","../src/week.vo.ts","../src/weekday.vo.ts","../src/weight-grams.vo.ts","../src/weight.vo.ts","../src/year-iso-id.vo.ts","../src/year.vo.ts","../src/z-score.service.ts"],"version":"5.9.3"}
1
+ {"root":["../src/age-years.vo.ts","../src/age.vo.ts","../src/api-key.vo.ts","../src/basename.vo.ts","../src/clock-format.service.ts","../src/clock.vo.ts","../src/date-calculator.service.ts","../src/date-formatter.service.ts","../src/date-range.vo.ts","../src/day-iso-id.vo.ts","../src/day.vo.ts","../src/directory-path-absolute.vo.ts","../src/directory-path-relative.vo.ts","../src/division-factor.vo.ts","../src/dll.service.ts","../src/duration-ms.vo.ts","../src/duration.service.ts","../src/email-mask.service.ts","../src/etags.vo.ts","../src/extension.vo.ts","../src/feature-flag-value.vo.ts","../src/feature-flag.vo.ts","../src/file-path-absolute-schema.vo.ts","../src/file-path-relative-schema.vo.ts","../src/file-path.vo.ts","../src/filename-affix.vo.ts","../src/filename-from-string.vo.ts","../src/filename.vo.ts","../src/height-milimiters.vo.ts","../src/height.vo.ts","../src/hour-format.service.ts","../src/hour-schema.vo.ts","../src/hour.vo.ts","../src/iban-mask.service.ts","../src/iban-schema.vo.ts","../src/iban.vo.ts","../src/image.vo.ts","../src/index.ts","../src/language.vo.ts","../src/linear-regression.service.ts","../src/mean.service.ts","../src/mime-types.vo.ts","../src/mime-value.vo.ts","../src/mime.vo.ts","../src/min-max-scaler.service.ts","../src/minute-schema.vo.ts","../src/minute.vo.ts","../src/money-amount.vo.ts","../src/money.vo.ts","../src/month-iso-id.vo.ts","../src/month.vo.ts","../src/multiplication-factor.vo.ts","../src/noop.service.ts","../src/notification-template.vo.ts","../src/object-key.vo.ts","../src/outlier-detector.service.ts","../src/package-version-schema.vo.ts","../src/package-version.vo.ts","../src/pagination-page.vo.ts","../src/pagination-skip.vo.ts","../src/pagination-take.vo.ts","../src/pagination.service.ts","../src/percentage.service.ts","../src/population-standard-deviation.service.ts","../src/quarter-iso-id.vo.ts","../src/quarter.vo.ts","../src/random.service.ts","../src/rate-limiter.service.ts","../src/relative-date.vo.ts","../src/reordering-item-position-value.vo.ts","../src/reordering.service.ts","../src/revision-value.vo.ts","../src/revision.vo.ts","../src/rounding.adapter.ts","../src/rounding.port.ts","../src/size-bytes.vo.ts","../src/size.vo.ts","../src/slug.service.ts","../src/stopwatch.service.ts","../src/sum.service.ts","../src/thousands-separator.service.ts","../src/time-zone-offset-value.vo.ts","../src/timestamp-value.vo.ts","../src/timestamp.vo.ts","../src/timezone.vo.ts","../src/ts-utils.ts","../src/visually-unambiguous-characters-generator.service.ts","../src/week-iso-id.vo.ts","../src/week.vo.ts","../src/weekday.vo.ts","../src/weight-grams.vo.ts","../src/weight.vo.ts","../src/year-iso-id.vo.ts","../src/year.vo.ts","../src/z-score.service.ts"],"version":"5.9.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/tools",
3
- "version": "1.1.9",
3
+ "version": "1.1.12",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Bartosz Gordon",
@@ -28,7 +28,7 @@
28
28
  "@types/mime-types": "3.0.1",
29
29
  "cspell": "9.4.0",
30
30
  "knip": "5.71.0",
31
- "lefthook": "2.0.6",
31
+ "lefthook": "2.0.7",
32
32
  "only-allow": "1.2.2",
33
33
  "shellcheck": "4.1.0",
34
34
  "typescript": "5.9.3",
package/readme.md CHANGED
@@ -100,6 +100,7 @@ src/
100
100
  ├── rounding.port.ts
101
101
  ├── size-bytes.vo.ts
102
102
  ├── size.vo.ts
103
+ ├── slug.service.ts
103
104
  ├── stopwatch.service.ts
104
105
  ├── sum.service.ts
105
106
  ├── thousands-separator.service.ts
package/src/index.ts CHANGED
@@ -75,6 +75,7 @@ export * from "./rounding.adapter";
75
75
  export * from "./rounding.port";
76
76
  export * from "./size.vo";
77
77
  export * from "./size-bytes.vo";
78
+ export * from "./slug.service";
78
79
  export * from "./stopwatch.service";
79
80
  export * from "./sum.service";
80
81
  export * from "./thousands-separator.service";
package/src/mime.vo.ts CHANGED
@@ -5,18 +5,21 @@ import { MimeValue } from "./mime-value.vo";
5
5
  export const MimeError = { NotAccepted: "mime.not.accepted" } as const;
6
6
 
7
7
  export class Mime {
8
- readonly type: string;
9
- readonly subtype: string;
8
+ private constructor(
9
+ readonly type: string,
10
+ readonly subtype: string,
11
+ ) {}
10
12
 
11
- constructor(candidate: string) {
13
+ static fromString(candidate: string): Mime {
12
14
  const { type, subtype } = MimeValue.parse(candidate);
13
15
 
14
- this.type = type;
15
- this.subtype = subtype;
16
+ return new Mime(type, subtype);
16
17
  }
17
18
 
18
19
  static fromExtension(extension: ExtensionType): Mime {
19
- return new Mime(String(mime.contentType(extension)));
20
+ const { type, subtype } = MimeValue.parse(String(mime.contentType(extension)));
21
+
22
+ return new Mime(type, subtype);
20
23
  }
21
24
 
22
25
  isSatisfiedBy(another: Mime): boolean {
@@ -38,8 +41,8 @@ export class Mime {
38
41
  }
39
42
 
40
43
  export const MIMES = {
41
- csv: new Mime("text/csv"),
42
- text: new Mime("text/plain"),
43
- markdown: new Mime("text/markdown"),
44
- pdf: new Mime("application/pdf"),
44
+ csv: Mime.fromString("text/csv"),
45
+ text: Mime.fromString("text/plain"),
46
+ markdown: Mime.fromString("text/markdown"),
47
+ pdf: Mime.fromString("application/pdf"),
45
48
  };
@@ -0,0 +1,18 @@
1
+ export class Slug {
2
+ // Any letter or any number
3
+ private static WHITELIST = /[\p{L}\p{N}]/u;
4
+
5
+ static generate(input: string, separator = "-"): string {
6
+ return (
7
+ input
8
+ .split("")
9
+ .map((character) => (Slug.WHITELIST.test(character) ? character : separator))
10
+ .join("")
11
+ // Collapse multiple consecutive separators
12
+ .replace(new RegExp(`\\${separator}+`, "g"), separator)
13
+ // Trim leading and trailing separators
14
+ .replace(new RegExp(`^\\${separator}|\\${separator}$`, "g"), "")
15
+ .toLocaleLowerCase()
16
+ );
17
+ }
18
+ }