Skip to content

Instantly share code, notes, and snippets.

@dfkaye
dfkaye / i18n.js
Last active February 20, 2019 16:32 — forked from WebReflection/i18n.js
i18n in 10 lines of code
// @webreflection's i18n.js
// More at https://medium.com/@WebReflection/easy-i18n-in-10-lines-of-javascript-poc-eb9e5444d71e
function i18n(template) {
for (var
info = i18n.db[i18n.locale][template.join('\x01')],
out = [info.t[0]],
i = 1, length = info.t.length; i < length; i++
) out[i] = arguments[1 + info.v[i - 1]] + info.t[i];
return out.join('');
@dfkaye
dfkaye / dom-to-json.js
Last active July 25, 2018 21:59 — forked from sstur/dom-to-json.js
Stringify DOM nodes using JSON (and revive again)
// 25 July 2018
// forked from https://gist.github.com/sstur/7379870
// modified:
// + reduce key assignment logic
// + eliminate accidental globals
// + use attr.name, attr.value, instead of attr[0], attr[1]
// + add a couple tests at the end.
function toJSON(node) {
node = node || this;
// 17 November 2017
// original https://gist.github.com/airportyh/203f7c2d8a8b29af44218b79596af32f
// from @airporty https://twitter.com/airportyh/status/931540087602581504
// The initial refactoring breaks `main()` steps to smaller functions, but adds
// whitespace.
// 21 November 2017 - added discrete unit tests for each function, vastly more
// robust, heavily renamed, heavier on comments.