Public
Edited
Mar 8
Importers
7 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
nutcase(garbledString2).split(' ').filter(d=>d.match(/[A-Za-z]/))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
nutcase = (str, ...rules) =>

reform (str,
condenseSpace,
splitCamelCase,

escapeIntlEmails(true),
escapeHTTP, addFullStop,
guessPunctuation(2),
attachSingletons,
splitCamelCase,

leaveNumberedSeq,
isolateNumbers,
reconnectGlyphs(/\-'’_/),
joinTrailingST,
guessAcronyms(3,'Lu'),
guessAmpernyms(false),
removeLineSpace,
unescapeFormatting,
condenseSpace,
appendSymbols,
attachPaths,
...rules
).trim()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
guessPunctuation = (min=2)=> str=>
str.replace(new RegExp(
String.raw`([^\p{Nd}\.!\?&]{${min},})([\.!\?,;:\p{Nd}])`,'gu'),' $1$2')
Insert cell
leaveNumberedSeq = str =>
str.replace(/([\p{Nd}\p{P}\p{S}]+)/gu," $1 ")
// P{L} or p{Nd} or p{P}
.replace(/ ([\.]) /g,'$1')
// wrapped in spaces to avoid linebreaks
.replace(/ ?([\\\/]) /g,'$1')
// concat path like strings
.replace(/ (\.\d{1,2})/g,'$1')
// trailing number edge case
Insert cell
isolateNumbers = str =>
str.replace(/([\p{S}\P{P}\/\\])(\p{Nd}\S+)/gu, " $1$2")
// improve specificity; P{P} or not?
.replace(/(\S+\p{Nd})([\p{S}\P{P}])/gu, "$1$2 ")
// greedy or not?
Insert cell
Insert cell
attachPaths = str =>
str.replace(/([\/\\]\S+\.)\s/gu,'$1')
Insert cell
appendSymbols = str =>
str.replace(/ ([%]) /,'$1 ')
Insert cell
splitCamelCase = str=>
str.replace(/(\p{Ll}{2,}|[aI])(\p{Lu}\p{L}?)/gmu,'$1 $2')
Insert cell
unescapeFormatting = str =>
str.replace(/(<<<)([\s\S]+?)(>>>)/gm,
String.call.bind( (l,m,r)=>['',l,m.replace(/ +/gmu,''),r].join('')))
Insert cell
attachSingletons = str =>
str.replace(/ +([\p{Lu}]) +/gu,'$1 ')
// String.call.bind( d=> d ==='I'? ` ${d} ` : `${d} `))
Insert cell
reconnectGlyphs = (glyphs = /'\-_/ ) => str =>
str.replace(new RegExp(String.raw`\s+([${glyphs}])\s+`,'g'),'$1')
Insert cell
guessAmpernyms = (split = false) => str =>
str.replace(/\s?([\.&])\s?(\p{Lu}+)(\p{Lu})/gu,'$1$2 $3')
// split repeated caps
.replace(/\s(\p{Lu})\s&\s+(\p{Lu})/gu,' $1&$2' + (split ? ' ' : ''))
// append space to replacement if needed
Insert cell
widenClosures = str=>
str.replace(/([\p{Ps}\p{Pe}]+)/gmu,' $1 ')
Insert cell
joinTrailingST = str =>
str.replace(/ ?([\'’])([st])/g,"$1$2 ")
Insert cell
condenseSpace = str =>
str.replace(/ +/g,' ')
Insert cell
removeLineSpace = str =>
str.replace(/(\r)?\n +/gm,'$1\n')
Insert cell
addFullStop = str =>
str.replace(/(\S*?[^\.\s,;:!?]\s*?)$/gu,'$1.')
Insert cell
adjustFullStop = str =>
str.replace(/(\p{L}{2,}\.)(\p{L}\.)/gu, '$1 $2')
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more