Skip to content

Turkish language support #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,24 +534,24 @@ export function parseOp(exp: string): {
}

export function toSlug(str: unknown) {
if (typeof str !== 'string') {
return '';
}
if (typeof str !== 'string') {
return null;
}

let res = str.replace(/^\s+|\s+$/g, ''); // trim
res = res.toLowerCase();
let res = str.replace(/^\s+|\s+$/g, ''); // trim
res = res.toLowerCase();

// remove accents
const from = 'àáãảạăằắẳẵặâầấẩẫậèéẻẽẹêềếểễệđùúủũụưừứửữựòóỏõọôồốổỗộơờớởỡợìíỉĩịäëïîöüûñçýỳỹỵỷ';
const to = 'aaaaaaaaaaaaaaaaaeeeeeeeeeeeduuuuuuuuuuuoooooooooooooooooiiiiiaeiiouuncyyyyy';
for (let i = 0, l = from.length; i < l; i++) {
res = res.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
}
// remove accents and convert Turkish characters to English counterparts
const from = 'àáãảạăằắẳẵặâầấẩẫậèéẻẽẹêềếểễệđùúủũụưừứửữựòóỏõọôồốổỗộơờớởỡợìíỉĩịäëïîöüûñçýỳỹỵỷşçğöüı';
const to = 'aaaaaaaaaaaaaaaaaeeeeeeeeeeeduuuuuuuuuuuoooooooooooooooooiiiiiaeiiouuncyyyyyscgoui';
for (let i = 0, l = from.length; i < l; i++) {
res = res.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
}

res = res
.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
.replace(/\s+/g, '-') // collapse whitespace and replace by -
.replace(/-+/g, '-'); // collapse dashes
res = res
.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
.replace(/\s+/g, '-') // collapse whitespace and replace by -
.replace(/-+/g, '-'); // collapse dashes

return res;
return res;
}