more low-hanging fruits

This commit is contained in:
Henry Jameson 2026-08-04 17:12:46 +03:00
commit b2dca4a3f6
20 changed files with 45 additions and 45 deletions

View file

@ -3,7 +3,7 @@ import emojis from '@kazvmoe-infra/unicode-emoji-json/data-by-group.json' with {
type: 'json', type: 'json',
} }
Object.keys(emojis).map((k) => { Object.keys(emojis).forEach((k) => {
emojis[k].forEach((e) => { emojis[k].forEach((e) => {
delete e.unicode_version delete e.unicode_version
delete e.emoji_version delete e.emoji_version

View file

@ -154,7 +154,7 @@ const registration = {
}) })
}, },
replaceNewlines(str) { replaceNewlines(str) {
return str.replace(/\s*\n\s*/g, ' \n') return str.replaceAll('\s*\n\s*', ' \n')
}, },
}, },
} }

View file

@ -181,7 +181,7 @@ export default {
} }
// Processor to use with html_tree_converter // Processor to use with html_tree_converter
const processItem = (item, index, array, what) => { const processItem = (item, index, array) => {
// Handle text nodes - just add emoji // Handle text nodes - just add emoji
if (typeof item === 'string') { if (typeof item === 'string') {
const emptyText = item.trim() === '' const emptyText = item.trim() === ''
@ -281,7 +281,7 @@ export default {
// Processor for back direction (for finding "last" stuff, just easier this way) // Processor for back direction (for finding "last" stuff, just easier this way)
let encounteredTextReverse = false let encounteredTextReverse = false
const processItemReverse = (item, index, array, what) => { const processItemReverse = (item, index, array) => {
// Handle text nodes - just add emoji // Handle text nodes - just add emoji
if (typeof item === 'string') { if (typeof item === 'string') {
const emptyText = item.trim() === '' const emptyText = item.trim() === ''
@ -479,7 +479,7 @@ export default {
> >
{this.collapse {this.collapse
? pass2.map((x) => { ? pass2.map((x) => {
if (typeof x === 'string') return x.replace(/\n/g, ' ') if (typeof x === 'string') return x.replaceAll('\n', ' ')
if (!Array.isArray(x)) return x if (!Array.isArray(x)) return x
return x.map((y) => (y.type === 'br' ? ' ' : y)) return x.map((y) => (y.type === 'br' ? ' ' : y))
}) })
@ -547,8 +547,8 @@ export const preProcessPerLine = (html, greentext) => {
(string.includes('>') || string.includes('<')) (string.includes('>') || string.includes('<'))
) { ) {
const cleanedString = string const cleanedString = string
.replace(/<[^>]+?>/gi, '') // remove all tags .replaceAll(/<[^>]+?>/gi, '') // remove all tags
.replace(/@\w+/gi, '') // remove mentions (even failed ones) .replaceAll(/@\w+/gi, '') // remove mentions (even failed ones)
.trim() .trim()
if (cleanedString.startsWith('&gt;')) { if (cleanedString.startsWith('&gt;')) {
return `<span class='greentext'>${string}</span>` return `<span class='greentext'>${string}</span>`

View file

@ -300,7 +300,7 @@ const EmojiTab = {
sortPackFiles(nameOfPack) { sortPackFiles(nameOfPack) {
// Sort by key // Sort by key
const sorted = Object.keys(this.knownPacks[nameOfPack].files) const sorted = Object.keys(this.knownPacks[nameOfPack].files)
.sort() .sort((a, b) => a.localeCompare(b))
.reduce((acc, key) => { .reduce((acc, key) => {
if (key.length === 0) return acc if (key.length === 0) return acc
acc[key] = this.knownPacks[nameOfPack].files[key] acc[key] = this.knownPacks[nameOfPack].files[key]

View file

@ -179,7 +179,7 @@ export default {
[ [
'admin_dash', 'admin_dash',
'temp_overrides', 'temp_overrides',
...this.canonPath.map((p) => p.replace(/\./g, '_DOT_')), ...this.canonPath.map((p) => p.replaceAll('\.', '_DOT_')),
'label', 'label',
].join('.'), ].join('.'),
) )
@ -198,7 +198,7 @@ export default {
[ [
'admin_dash', 'admin_dash',
'temp_overrides', 'temp_overrides',
...this.canonPath.map((p) => p.replace(/\./g, '_DOT_')), ...this.canonPath.map((p) => p.replaceAll('\.', '_DOT_')),
'description', 'description',
].join('.'), ].join('.'),
) )

View file

@ -257,7 +257,7 @@ const AppearanceTab = {
const result = { const result = {
name: `${meta.directives.name || this.$t('settings.style.themes3.palette.imported')}: ${variant}`, name: `${meta.directives.name || this.$t('settings.style.themes3.palette.imported')}: ${variant}`,
key: `style.${variant.toLowerCase().replace(/ /g, '_')}`, key: `style.${variant.toLowerCase().replaceAll(' ', '_')}`,
bg, bg,
fg, fg,
text, text,

View file

@ -319,7 +319,7 @@ export default {
return useInterfaceStore().themeDataUsed return useInterfaceStore().themeDataUsed
}, },
shadowsAvailable() { shadowsAvailable() {
return Object.keys(DEFAULT_SHADOWS).sort() return Object.keys(DEFAULT_SHADOWS).sort((a, b) => a.localeCompare(b))
}, },
currentShadowOverriden: { currentShadowOverriden: {
get() { get() {

View file

@ -147,7 +147,7 @@ const StatusBody = {
return this.status.attachments.map((file) => file.type) return this.status.attachments.map((file) => file.type)
}, },
collapsedStatus() { collapsedStatus() {
return this.status.raw_html.replace(/(\n|<br\s?\/?>)/g, ' ') return this.status.raw_html.replaceAll('(\n|<br\s?\/?>)', ' ')
}, },
...mapState(useMergedConfigStore, ['mergedConfig']), ...mapState(useMergedConfigStore, ['mergedConfig']),
}, },
@ -168,7 +168,7 @@ const StatusBody = {
.filter((mention) => !mention.notifying) .filter((mention) => !mention.notifying)
.forEach((mention) => { .forEach((mention) => {
const { content, url } = mention const { content, url } = mention
const cleanedString = content.replace(/<[^>]+?>/gi, '') // remove all tags const cleanedString = content.replaceAll(/<[^>]+?>/gi, '') // remove all tags
if (!cleanedString.startsWith('@')) return if (!cleanedString.startsWith('@')) return
const handle = cleanedString.slice(1) const handle = cleanedString.slice(1)
const host = url.replace(/^https?:\/\//, '').replace(/\/.+?$/, '') const host = url.replace(/^https?:\/\//, '').replace(/\/.+?$/, '')

View file

@ -196,7 +196,7 @@ export default {
}, },
computed: { computed: {
escapedNewBio() { escapedNewBio() {
return ldEscape(this.newBio).replace(/\n/g, '<br>') return ldEscape(this.newBio).replaceAll('\n', '<br>')
}, },
somethingToSave() { somethingToSave() {
if (this.newName !== this.user.name_unescaped) return true if (this.newName !== this.user.name_unescaped) return true

View file

@ -62,8 +62,8 @@ export const parseUser = (data) => {
}) })
output.fields_text = data.fields.map((field) => { output.fields_text = data.fields.map((field) => {
return { return {
name: unescape(field.name.replace(/<[^>]*>/g, '')), name: unescape(field.name.replaceAll('<[^>]*>', '')),
value: unescape(field.value.replace(/<[^>]*>/g, '')), value: unescape(field.value.replaceAll('<[^>]*>', '')),
} }
}) })

View file

@ -3,7 +3,7 @@ import { capitalize } from 'lodash'
function humanizeErrors(errors) { function humanizeErrors(errors) {
return Object.entries(errors).reduce((errs, [k, val]) => { return Object.entries(errors).reduce((errs, [k, val]) => {
const message = val.reduce((acc, message) => { const message = val.reduce((acc, message) => {
const key = capitalize(k.replace(/_/g, ' ')) const key = capitalize(k.replaceAll('_', ' '))
return acc + [key, message].join(' ') + '. ' return acc + [key, message].join(' ') + '. '
}, '') }, '')
return [...errs, message] return [...errs, message]

View file

@ -29,7 +29,7 @@ export const createStyleSheet = (id, priority = 1000) => {
addRule(rule) { addRule(rule) {
let newRule = rule let newRule = rule
if (!CSS.supports?.('backdrop-filter', 'blur()')) { if (!CSS.supports?.('backdrop-filter', 'blur()')) {
newRule = newRule.replace(/backdrop-filter:[^;]+;/g, '') // Remove backdrop-filter newRule = newRule.replaceAll('backdrop-filter:[^;]+;', '') // Remove backdrop-filter
} }
if (newRule.startsWith('::-webkit')) { if (newRule.startsWith('::-webkit')) {
@ -44,7 +44,7 @@ export const createStyleSheet = (id, priority = 1000) => {
} }
this.rules.push( this.rules.push(
newRule.replace(/var\(--shadowFilter\)[^;]*;/g, ''), // Remove shadowFilter references newRule.replaceAll('var\(--shadowFilter\)[^;]*;', ''), // Remove shadowFilter references
) )
}, },
} }

View file

@ -1,7 +1,7 @@
/* global process */ /* global process */
function urlBase64ToUint8Array(base64String) { function urlBase64ToUint8Array(base64String) {
const padding = '='.repeat((4 - (base64String.length % 4)) % 4) const padding = '='.repeat((4 - (base64String.length % 4)) % 4)
const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/') const base64 = (base64String + padding).replaceAll('-', '+').replace(/_/g, '/')
const rawData = window.atob(base64) const rawData = window.atob(base64)
return Uint8Array.from([...rawData].map((char) => char.codePointAt(0))) return Uint8Array.from([...rawData].map((char) => char.codePointAt(0)))

View file

@ -460,7 +460,7 @@ export const generatePreset = (input) => {
return composePreset( return composePreset(
colors, colors,
generateRadii(input), generateRadii(input),
generateShadows(input, colors.theme.colors, colors.mod), generateShadows(input, colors.theme.colors),
generateFonts(input), generateFonts(input),
) )
} }

View file

@ -47,7 +47,7 @@ const highlightStyle = (prefs) => {
const highlightClass = (user) => { const highlightClass = (user) => {
return ( return (
'USER____' + user.screen_name?.replace(/\./g, '_').replace(/@/g, '_AT_') 'USER____' + user.screen_name?.replaceAll('\.', '_').replace(/@/g, '_AT_')
) )
} }

View file

@ -231,7 +231,7 @@ export const useEmojiStore = defineStore('emoji', {
.then((allPacks) => { .then((allPacks) => {
// Sort by key // Sort by key
return Object.keys(allPacks) return Object.keys(allPacks)
.sort() .sort((a, b) => a.localeCompare(b))
.reduce((acc, key) => { .reduce((acc, key) => {
if (key.length === 0) return acc if (key.length === 0) return acc
acc[key] = allPacks[key] acc[key] = allPacks[key]

View file

@ -578,7 +578,7 @@ export const useInterfaceStore = defineStore('interface', {
return { name: x.variant, ...cleanDirectives } return { name: x.variant, ...cleanDirectives }
}) })
.forEach((palette) => { .forEach((palette) => {
const key = 'style.' + palette.name.toLowerCase().replace(/ /g, '_') const key = 'style.' + palette.name.toLowerCase().replaceAll(' ', '_')
if (!firstStylePaletteName) firstStylePaletteName = key if (!firstStylePaletteName) firstStylePaletteName = key
palettesIndex[key] = () => Promise.resolve(palette) palettesIndex[key] = () => Promise.resolve(palette)
}) })

View file

@ -50,7 +50,7 @@ describe('RichContent', () => {
}, },
}) })
expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(html)) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(html))
}) })
it('unescapes everything as needed', () => { it('unescapes everything as needed', () => {
@ -67,7 +67,7 @@ describe('RichContent', () => {
}, },
}) })
expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(expected)) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
}) })
it('replaces mention with mentionsline', () => { it('replaces mention with mentionsline', () => {
@ -83,7 +83,7 @@ describe('RichContent', () => {
}, },
}) })
expect(wrapper.html().replace(/\n/g, '')).to.eql( expect(wrapper.html().replaceAll('\n', '')).to.eql(
compwrap(p(mentionsLine(1), ' how are you doing today?')), compwrap(p(mentionsLine(1), ' how are you doing today?')),
) )
}) })
@ -116,7 +116,7 @@ describe('RichContent', () => {
}, },
}) })
expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(expected)) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
}) })
it('Does not touch links if link handling is disabled', () => { it('Does not touch links if link handling is disabled', () => {
@ -211,7 +211,7 @@ describe('RichContent', () => {
}, },
}) })
expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(expected)) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
}) })
it("Doesn't add nonexistent emoji to post", () => { it("Doesn't add nonexistent emoji to post", () => {
@ -228,7 +228,7 @@ describe('RichContent', () => {
}, },
}) })
expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(html)) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(html))
}) })
it('Greentext + last mentions', () => { it('Greentext + last mentions', () => {
@ -279,7 +279,7 @@ describe('RichContent', () => {
}, },
}) })
expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(expected)) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
}) })
it('buggy example/hashtags', () => { it('buggy example/hashtags', () => {
@ -315,7 +315,7 @@ describe('RichContent', () => {
}, },
}) })
expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(expected)) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
}) })
it('rich contents of a mention are handled properly', () => { it('rich contents of a mention are handled properly', () => {
@ -365,8 +365,8 @@ describe('RichContent', () => {
expect( expect(
wrapper wrapper
.html() .html()
.replace(/\n/g, '') .replaceAll('\n', '')
.replace(/<!--.*?-->/g, ''), .replaceAll('<!--.*?-->', ''),
).to.eql(compwrap(expected)) ).to.eql(compwrap(expected))
}) })
@ -438,8 +438,8 @@ describe('RichContent', () => {
expect( expect(
wrapper wrapper
.html() .html()
.replace(/\n/g, '') .replaceAll('\n', '')
.replace(/<!--.*?-->/g, ''), .replaceAll('<!--.*?-->', ''),
).to.eql(compwrap(expected)) ).to.eql(compwrap(expected))
}) })
@ -484,7 +484,7 @@ describe('RichContent', () => {
}, },
}) })
expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(expected)) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
}) })
it.skip('[INFORMATIVE] Performance testing, 10 000 simple posts', () => { it.skip('[INFORMATIVE] Performance testing, 10 000 simple posts', () => {

View file

@ -107,7 +107,7 @@ describe('Statuses module', () => {
showImmediately: true, showImmediately: true,
timeline: 'public', timeline: 'public',
}) })
expect(state.timelines.public.maxId).to.eql('1') expect(state.timelines.public.maxId).to.equal('1')
mutations.addNewStatuses(state, { mutations.addNewStatuses(state, {
statuses: [secondStatus], statuses: [secondStatus],
@ -120,7 +120,7 @@ describe('Statuses module', () => {
secondStatus, secondStatus,
status, status,
]) ])
expect(state.timelines.public.maxId).to.eql('1') expect(state.timelines.public.maxId).to.equal('1')
}) })
it('keeps a descending by id order in timeline.visibleStatuses and timeline.statuses', () => { it('keeps a descending by id order in timeline.visibleStatuses and timeline.statuses', () => {
@ -340,7 +340,7 @@ describe('Statuses module', () => {
expect(state.allStatusesObject['1'].emoji_reactions[0].me).to.eql(true) expect(state.allStatusesObject['1'].emoji_reactions[0].me).to.eql(true)
expect( expect(
state.allStatusesObject['1'].emoji_reactions[0].accounts[0].id, state.allStatusesObject['1'].emoji_reactions[0].accounts[0].id,
).to.eql('me') ).to.equal('me')
}) })
it('adds a new reaction', () => { it('adds a new reaction', () => {
@ -362,7 +362,7 @@ describe('Statuses module', () => {
expect(state.allStatusesObject['1'].emoji_reactions[0].me).to.eql(true) expect(state.allStatusesObject['1'].emoji_reactions[0].me).to.eql(true)
expect( expect(
state.allStatusesObject['1'].emoji_reactions[0].accounts[0].id, state.allStatusesObject['1'].emoji_reactions[0].accounts[0].id,
).to.eql('me') ).to.equal('me')
}) })
it('decreases count in existing reaction', () => { it('decreases count in existing reaction', () => {
@ -429,8 +429,8 @@ describe('Statuses module', () => {
mutations.showNewStatuses(state, { timeline: 'public' }) mutations.showNewStatuses(state, { timeline: 'public' })
expect(state.timelines.public.visibleStatuses.length).to.eql(2) expect(state.timelines.public.visibleStatuses.length).to.eql(2)
expect(state.timelines.public.minVisibleId).to.eql('10') expect(state.timelines.public.minVisibleId).to.equal('10')
expect(state.timelines.public.minId).to.eql('10') expect(state.timelines.public.minId).to.equal('10')
}) })
}) })

View file

@ -54,7 +54,7 @@ const run = () => {
// Sort by key // Sort by key
const sorted = Object.keys(emojisObject) const sorted = Object.keys(emojisObject)
.sort() .sort((a, b) => a.localeCompare(b))
.reduce((acc, key) => { .reduce((acc, key) => {
if (key.length === 0) return acc if (key.length === 0) return acc
acc[key] = emojisObject[key] acc[key] = emojisObject[key]