Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,11 @@
{
let s = " \t String with spaces \t ";
// a future version of ECMAScript will have trimStart(). Some current
// implementations have trimLeft().
console.log("original: '" + s + "'");
console.log("trimmed left: '" + s.replace(/^\s+/,'') + "'");
// a future version of ECMAScript will have trimEnd(). Some current
// implementations have trimRight().
console.log("trimmed right: '" + s.replace(/\s+$/,'') + "'");
console.log("trimmed both: '" + s.trim() + "'");
}

View file

@ -0,0 +1,48 @@
(() => {
'use strict';
// stripStart :: Text -> Text
let stripStart = s => dropWhile(isSpace, s);
// stripEnd :: Text -> Text
let stripEnd = s => dropWhileEnd(isSpace, s);
// strip :: Text -> Text
let strip = s => dropAround(isSpace, s);
// OR: let strip = s => s.trim();
// GENERIC FUNCTIONS
// dropAround :: (Char -> Bool) -> Text -> Text
let dropAround = (p, s) => dropWhile(p, dropWhileEnd(p, s));
// dropWhile :: (a -> Bool) -> [a] -> [a]
let dropWhile = (p, xs) => {
for (var i = 0, lng = xs.length;
(i < lng) && p(xs[i]); i++) {}
return xs.slice(i);
}
// dropWhileEnd :: (Char -> Bool) -> Text -> Text
let dropWhileEnd = (p, s) => {
for (var i = s.length; i-- && p(s[i]);) {}
return s.slice(0, i + 1);
}
// isSpace :: Char -> Bool
let isSpace = c => /\s/.test(c);
// show :: a -> String
let show = x => JSON.stringify(x, null, 2);
// TEST
let strText = " \t\t \n \r Much Ado About Nothing \t \n \r ";
return show([stripStart, stripEnd, strip]
.map(f => '-->' + f(strText) + '<--'));
})();