Skip to content

Commit 3e561d7

Browse files
committed
fix: replace slugify function with library
1 parent 438998b commit 3e561d7

File tree

4 files changed

+57
-23
lines changed

4 files changed

+57
-23
lines changed

package-lock.json

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"@types/jasmine": "^5.1.4",
2626
"@types/node": "^20.12.7",
2727
"@types/wavesurfer.js": "^6.0.3",
28-
"@types/unidecode": "^0.1.3",
2928
"@typescript-eslint/eslint-plugin": "^7.6.0",
3029
"@typescript-eslint/parser": "^7.6.0",
3130
"find-cache-dir": "^5.0.0",
@@ -55,6 +54,7 @@
5554
"@angular/material": "^17",
5655
"@angular/platform-browser": "^17",
5756
"@angular/router": "^17",
57+
"@sindresorhus/slugify": "^2.2.1",
5858
"bootstrap": "^5.3.3",
5959
"file-saver": "^2.0.5",
6060
"image-conversion": "^2.1.1",
@@ -64,7 +64,6 @@
6464
"shepherd.js": "^11.2.0",
6565
"soundswallower": "^0.6.3",
6666
"standardized-audio-context": "^25.3.70",
67-
"unidecode": "^1.0.1",
6867
"wavesurfer.js": "^6.6.2"
6968
},
7069
"scripts": {

packages/studio-web/src/app/shared/download/download.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injectable } from "@angular/core";
22
import { HttpErrorResponse } from "@angular/common/http";
3-
import { Observable, Subject, takeUntil } from "rxjs";
4-
import { slugify } from "../../utils/utils";
3+
import { Subject, takeUntil } from "rxjs";
4+
import slugify from "@sindresorhus/slugify";
55
import { UploadService } from "../../upload.service";
66
import { ToastrService } from "ngx-toastr";
77

@@ -215,7 +215,7 @@ Please host all assets on your server, include the font and package imports defi
215215
.replace(/[^0-9]/g, "")
216216
.slice(0, -3);
217217
const basename =
218-
(slots.title ? slugify(slots.title, 15) : "readalong") +
218+
(slots.title ? slugify(slots.title).substring(0, 15) : "readalong") +
219219
`-${timestamp}`;
220220
element.href = window.URL.createObjectURL(blob);
221221
element.download = `${basename}.html`;
@@ -253,7 +253,7 @@ Please host all assets on your server, include the font and package imports defi
253253
.replace(/[^0-9]/g, "")
254254
.slice(0, -3);
255255
const basename =
256-
(slots.title ? slugify(slots.title, 15) : "readalong") +
256+
(slots.title ? slugify(slots.title).substring(0, 15) : "readalong") +
257257
`-${timestamp}`;
258258
// - add audio file
259259
if (b64Audio) {
Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +0,0 @@
1-
import unidecode from "unidecode";
2-
3-
export const slugify = (str: string, character_limit: number = 0) => {
4-
// Adapted from https://byby.dev/js-slugify-string
5-
// Character limit of 0 (default) means there is no limit
6-
const slug = String(unidecode(str))
7-
.normalize("NFC") // split accented characters into their base characters and diacritical marks
8-
.trim() // trim leading or trailing whitespace
9-
.toLowerCase() // convert to lowercase
10-
.replace(/\s+/g, "-") // replace spaces with hyphens
11-
.replace(/-+/g, "-"); // remove consecutive hyphens
12-
13-
if (character_limit) {
14-
return slug.substring(0, character_limit);
15-
}
16-
return slug;
17-
};

0 commit comments

Comments
 (0)