day 174 — code 365

Sun 05 Jun 2016

I finished the count-to-6 tutorial! The last exercise was on using tagged template strings. I found these really confusing. They’re a kind of syntactic sugar:

myFunc `Hello ${name}!`

Desugars into:

myFunc(["Hello ", "!"], name);

This allows us to process name, eg. escaping unsafe HTML characters, such as <, >, &, ‘, “…

This is my final code from the last exercise:

function escaper(unsafe) {
return unsafe
.replace(/&/g, "&amp;")
// .replace(/'/g, "&#39;")
.replace(/'/g, "&apos;")
.replace(/"/g, "&quot;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;");
}

function html(arrStr, ...subs) {
var result = arrStr[0];
for (var i = 0; i < subs.length; i++) {
result += escaper(subs[i]) + arrStr[i + 1];
}
return result;
}

And then we call the functions:

html`<b>${process.argv[2]} says</b>: "${process.argv[3]}"`

JS Modules, Transpiring, Bundling

I started on this tutorial:

I got to use Browserify, Webpack, and Babel! I’ve used babel before, when I was trying to get React set up, but that experience didn’t work out (app didn’t work when deployed to my server). I’m hoping that going through these ‘background’ tutorials will help when I get stuck into React tutorials….

Babel requires a config file for specifying which presets to use. This is the .babelrc file. I found out that .rc files are config files, a naming convention from Runcom files on a CTSS operating system circa 1962; not ‘runtime configuration’, although that does describe their function well, too.

Like what you read? Give Ampers Smith a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.