Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Sep 18, 2023. It is now read-only.

refactor: replace deprecated String.prototype.substr() #42

Merged
merged 1 commit into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions lib/name-transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ module.exports = {
*generateNames(prefixes, suffixes, name) {
for (const prefix of prefixes) {
if (name.toLowerCase().startsWith(prefix.toLowerCase())) {
const truncated = name.substr(prefix.length)
const truncated = name.slice(prefix.length)
yield truncated
for (const suffix of suffixes) {
if (truncated.toLowerCase().endsWith(suffix.toLowerCase())) {
yield truncated.substr(0, truncated.length - suffix.length)
yield truncated.slice(0, truncated.length - suffix.length)
}
}
}
}
for (const suffix of suffixes) {
if (name.toLowerCase().endsWith(suffix.toLowerCase())) {
const truncated = name.substr(0, name.length - suffix.length)
const truncated = name.slice(0, name.length - suffix.length)
yield truncated
for (const prefix of prefixes) {
if (truncated.toLowerCase().startsWith(prefix.toLowerCase())) {
yield truncated.substr(prefix.length)
yield truncated.slice(prefix.length)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/check-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function rulesFromDir(dir) {
function makeTitle(name) {
return name
.replace(/-/g, ' ')
.replace(/\w\S*/g, x => x.charAt(0).toUpperCase() + x.substr(1))
.replace(/\w\S*/g, x => x.charAt(0).toUpperCase() + x.slice(1))
.replace(/\b(The|An?|And|To|In|On|With)\b/g, x => x.toLowerCase())
.replace(/\b(Dom)\b/g, x => x.toUpperCase())
}
Expand Down