mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-05-03 13:43:10 +03:00
New: char count for Compose field
Uses pre-compiled regex for perf
This commit is contained in:
parent
a2e55eca90
commit
13a347ce37
6 changed files with 226 additions and 0 deletions
scripts
48
scripts/extract-url.js
Normal file
48
scripts/extract-url.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
import fs from 'fs';
|
||||
import regexSupplant from 'twitter-text/dist/lib/regexSupplant.js';
|
||||
import validDomain from 'twitter-text/dist/regexp/validDomain.js';
|
||||
import validPortNumber from 'twitter-text/dist/regexp/validPortNumber.js';
|
||||
import validUrlPath from 'twitter-text/dist/regexp/validUrlPath.js';
|
||||
import validUrlPrecedingChars from 'twitter-text/dist/regexp/validUrlPrecedingChars.js';
|
||||
import validUrlQueryChars from 'twitter-text/dist/regexp/validUrlQueryChars.js';
|
||||
import validUrlQueryEndingChars from 'twitter-text/dist/regexp/validUrlQueryEndingChars.js';
|
||||
|
||||
// The difference with twitter-text's extractURL is that the protocol isn't
|
||||
// optional.
|
||||
|
||||
const urlRegex = regexSupplant(
|
||||
'(' + // $1 total match
|
||||
'(#{validUrlPrecedingChars})' + // $2 Preceeding chracter
|
||||
'(' + // $3 URL
|
||||
'(https?:\\/\\/)' + // $4 Protocol (optional) <-- THIS IS THE DIFFERENCE, MISSING '?' AFTER PROTOCOL
|
||||
'(#{validDomain})' + // $5 Domain(s)
|
||||
'(?::(#{validPortNumber}))?' + // $6 Port number (optional)
|
||||
'(\\/#{validUrlPath}*)?' + // $7 URL Path
|
||||
'(\\?#{validUrlQueryChars}*#{validUrlQueryEndingChars})?' + // $8 Query String
|
||||
')' +
|
||||
')',
|
||||
{
|
||||
validUrlPrecedingChars,
|
||||
validDomain,
|
||||
validPortNumber,
|
||||
validUrlPath,
|
||||
validUrlQueryChars,
|
||||
validUrlQueryEndingChars,
|
||||
},
|
||||
'gi',
|
||||
);
|
||||
|
||||
const filePath = 'src/data/url-regex.json';
|
||||
fs.writeFile(
|
||||
filePath,
|
||||
JSON.stringify({
|
||||
source: urlRegex.source,
|
||||
flags: urlRegex.flags,
|
||||
}),
|
||||
(err) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
console.log(`Wrote ${filePath}`);
|
||||
},
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue