Index

strings

MMO.core · 24 symbols · generated 30 Sep 2026

namespace

strings

strings.js:3
MMO.core.strings = {…}
Namespace
MMO.core

Constants8

SPRINTF_FORMAT

strings.js:4
SPRINTF_FORMAT = /(.?)\{([\w\\\/\.\:\-\$\#]+)\}/g

HTML_ESCAPES

strings.js:8
HTML_ESCAPES = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#x27;', }

REG_CLEAR_GLOBAL_PARENTHESIS

strings.js:22
REG_CLEAR_GLOBAL_PARENTHESIS = 8
function

bytesize

strings.js:33

Format a byte count as a human readable size (binary units, decimal prefixes).

function MMO.core.strings.bytesize(bytes, decimals = 2)
Namespace
MMO.core.strings
bytesnumber
decimals = 2numberhow many decimals to keep
returnsstring
bytesize(2048) === '2.00 ko'
function

safeJsonEncode

strings.js:48

Alias to JSON.stringify, safe for circular references WARNING: don't use to stringify content that will be decoded. All circular references are lost during this process.

function MMO.core.strings.safeJsonEncode(value, space)
Namespace
MMO.core.strings
DO NOT USE TO SAVE DATA WITH THE SERVER (except for entities). INFORMATIONS ARE LOST !
value*
space
returns
function

toCamelCase

strings.js:66

Convert words into a camel case valid string ex: font-weight => fontWeight

function MMO.core.strings.toCamelCase(str)
Namespace
MMO.core.strings
strstring
returnsstring
function

escapeHTML

strings.js:77

Escape the characters that would otherwise be read as markup.

function MMO.core.strings.escapeHTML(str)
Namespace
MMO.core.strings
str*coerced to a string
returnsstring
function

toBoolean

strings.js:90

Read a boolean the way an html attribute or a query parameter carries it: the STRINGS '0', '', 'false' and 'FALSE' are false, unlike plain javascript truthiness.

function MMO.core.strings.toBoolean(value)
Namespace
MMO.core.strings
value*
returnsboolean
function

generatePassword

strings.js:106

Draw a random password, retrying until every required character class is present.

function MMO.core.strings.generatePassword(length = 10, withSpecialChar = true, withDigit = true, withUpperCase = true, withLowerCase = true)
Namespace
MMO.core.strings
WARNING: built on `Math.random`, which is NOT cryptographically secure. Use it for a suggestion the user can accept, never to derive a secret on its own.
length = 10number
withSpecialChar = truebooleanrequire at least one of !@#$%^&*
withDigit = truebooleanrequire at least one digit
withUpperCase = truebooleanrequire at least one upper case letter
withLowerCase = truebooleanrequire at least one lower case letter
returnsstring
function

escapeRegex

strings.js:144

Escape a part of a regex <MDN|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping>

function MMO.core.strings.escapeRegex(str)
Namespace
MMO.core.strings
strstring
returnsstring
function

extractRegexSource

strings.js:154

Extract regex source and clear some stuff

function MMO.core.strings.extractRegexSource(regex, flags = -1)
Namespace
MMO.core.strings
regexRegExp | string
flags = -1numberbinary flags. Clearing options
returnsstring
function

anyRegex

strings.js:187

Create a regular expression that matches any of the regex.

function MMO.core.strings.anyRegex(regex, min = false, max = false, anchorStart = true, anchorEnd = true)
Namespace
MMO.core.strings
This regular expression is usefull to test a string.
regexArraya list of regular expression
min = false
max = false
anchorStart = true
anchorEnd = true
returnsRegExp
function

objectRegex

strings.js:221

Create a regular expression for a serialized object, each properties separated by sep.

function MMO.core.strings.objectRegex(regexMap, sep = '', required = true)
Namespace
MMO.core.strings
Each property is match in order of declaration. To have sticky regex, use anchors '^'|'$' on each regex that must be sticky to the previous/next regex (only at the start and/or the end of the regex). WARNING: without required field, the first or last regex must have a start|end anchor, else the match will return an empty string NOTE: all the regex's flags are merged
regexMapobjecta map of regular expressions
sep = ''Stringa separator between regex
required = trueArray | Booleana list of key in regexMap that are required to match in the string
returnsRegExp
function

listRegex

strings.js:275

Create a regular expression for a serialized list, each properties separated by sep, not ordered.

function MMO.core.strings.listRegex(regexMap, sep = ',', required = false)
Namespace
MMO.core.strings
This regular expression is usefull to test a string. Use matchList to get all the matches
regexMapobjectkey: RexExp the regular expression to capture with the name for each group
sep = ','Stringa separator between regex
required = falseArraya list of required regex to match in the string
returnsRegExp
function

matchObject

strings.js:301

Match a serialized object

function MMO.core.strings.matchObject(text, regexMap, sep = '', required = true)
Namespace
MMO.core.strings
See
MMO.core.strings.objectRegex
text
regexMap
sep = ''
required = true
returnsnull | objectnull if any required key is missing
function

matchList

strings.js:323

Match a serialized list, with no defined order (any regular expression can match first) If some text is not contained in any captured, but the regex matches, this text is returned at the index '-1'

function MMO.core.strings.matchList(text, regexMap, sep = ',', required = false)
Namespace
MMO.core.strings
text[type][description]
regexMap[type][description]
sep = ','stringbetween regex
required = falseArraykeys of regexMap that MUST match
returnsnull | objectnull if any required key is missing
matchList('12px', {size: /\d+/, unit: /px/}): {size: 12, unit: px} matchList('12px test', {size: /\d+/, unit: /px/}): {size: 12, unit: px, -1: ' test'} matchList('px12', {size: /\d+/, unit: /px/}): {size: 12, unit: px} matchList('12', {size: /\d+/, unit: /px/}) => {size: 12, unit: undefined} matchList('12', {size: /\d+/, unit: /px/}, ['unit']) => null
function

serialize

strings.js:382

Convert any variable into a valid string

function MMO.core.strings.serialize(value, levelMax = 3, hash = [], hashValues = [])
Namespace
MMO.core.strings
value
levelMax = 3
hash = []
hashValues = []
returnsstring
function

printf

strings.js:459
printf like. variable must be surrounded with {varialble} (injector) ex: printf('Hello, {message}!', {message: 'world'}) > Hello, world!function MMO.core.strings.printf(format, data, allow_partial = false, encode = null)
Namespace
MMO.core.strings
formatstring
dataObjectthe data to use as replacement
allow_partial = falsebooleanif true, will leave the injectors that can't be found in data
encode = nullFunctionfunction to use to encode the value found in data
returnsstringthe text injected
function

extractPrintf

strings.js:481

Reverse of MMO.core.strings.printf: recover the values a format was filled with.

function MMO.core.strings.extractPrintf(format, result)
Namespace
MMO.core.strings
formatstringthe format containing {key} injectors
resultstringthe string produced from that format
returns?Objectthe captured values, or null when result does not match format
extractPrintf('/user/{id}', '/user/42') => {id: '42'}
function

dump

strings.js:490

alias to printf with encode = serialize

function MMO.core.strings.dump(format, data)
Namespace
MMO.core.strings
format
data
function

stripAccent

strings.js:527

Strip accent of string

function MMO.core.strings.stripAccent(a)
Namespace
MMO.core.strings
astring
returnsstring
function

split

strings.js:538

Split words (utf-8) with a set of delimeters

function MMO.core.strings.split(a, delim = [' ', "\n", "\t"])
Namespace
MMO.core.strings
astring[description]
delim = [' ', "\n", "\t"]Array[description]
returnsArray<string>
function

distanceEquality

strings.js:563

Compute the strict distance between words.

function MMO.core.strings.distanceEquality(a, b)
Namespace
MMO.core.strings
If b contains a, retuen 1, else return 0
a[type][description]
b[type][description]
returns[type][description]
function

distanceJaroWinkler

strings.js:601

Compute the the Jaro Distance between two sequences (string or array) s1 and s2, using strict equality operator ===.

function MMO.core.strings.distanceJaroWinkler(a, b)
Namespace
MMO.core.strings
TIP: use with utf8Split to compare utf-8 strings Jaro distance formula: `dj = 1/3 * (m/|s1| + m/|s2| + (m-t)/m)` - dj is the Jaro distance - m is the number of matching characters (identical and the distance between them is < max(|s1|,|s2|)/2 - 1) - t is half the number of transpositions (compare the i-th character of s1 and the i-th character of s2 divided by 2) - |s1| is the length of the first string - |s2| is the length of the second string The Jaro-Winkler similarity uses a prefix scale p which gives more favorable ratings to strings that match from the beginning for a set prefix length l. p is a constant scaling factor for how much the score is adjusted upwards for having common prefixes. The standard value for this constant in Winkler’s work is p=0.1. l is the length of the common prefix at the start of the string (up to a maximum of 4 characters). Jaro-Winkler distance formula: `dw = dj + (l*p*(1-dj))` dj = (⅓) ( 6/6 + 6/6 + (6–1)/6) = ⅓ 17/6 = 0,944 = 94,4% l = 3 (which refers to “mar”). p = 0.1 (standard value) dw = 0,944 + ((0,1*3)(1–0,944)) = 96,1%
a
b
“martha” and “marhta”. m = 6 t = 2/2 =1 (2 couples of non matching characters, the 4-th and 5-th) { t/h ; h/t } |s1| = 6 |s2| = 6
function

score

strings.js:668

Score a searched text with some text content

function MMO.core.strings.score(search, text, distanceFn, normalize = true)
Namespace
MMO.core.strings
searchArraylist of words to search for
textArraylist of words to search in
distanceFnFunctionfunction(a,b): float
normalize = trueboolif true, remove accent in text and set to lower case
returnsMap<string: Array<string, float>> | falsefalswe if nothing matched