mirror of
https://github.com/nolanlawson/pinafore
synced 2024-12-11 17:59:20 +01:00
19 lines
566 B
JavaScript
19 lines
566 B
JavaScript
// via https://github.com/tootsuite/mastodon/blob/5d5c0f4/app/javascript/mastodon/features/compose/util/counter.js
|
|
|
|
import { urlRegex } from './urlRegex'
|
|
import { handleRegex } from './handleRegex'
|
|
import { mark, stop } from './marks'
|
|
import { length } from 'stringz'
|
|
|
|
const urlPlaceholder = 'xxxxxxxxxxxxxxxxxxxxxxx'
|
|
|
|
export function measureText (inputText) {
|
|
mark('measureText()')
|
|
let normalizedText = inputText
|
|
.replace(urlRegex, urlPlaceholder)
|
|
.replace(handleRegex, '$1@$3')
|
|
let len = length(normalizedText)
|
|
stop('measureText()')
|
|
return len
|
|
}
|