update
I've created a little repository that simply exposes the final utility as npm
module.
It's called html-escaper
there is basically one rule only: do not ever replace one char after another if you are transforming a string into another.
/*----------------------------------------------------------------------------------------- | |
credit: taken and modified from an early obscure vue v1 loader | |
(https://github.com/your-budget-today/personal - no longer available) | |
notes: | |
1. put your components in /app/cmp/ folder or change the line 40 below to suit | |
2. You can also add the following to bottom of the dynamically loaded file for debugging | |
e.g. //# sourceURL=simplest.js | |
example usage (there is a more verbose one allowing for reuse at the bottom of this file): |
<!-- | |
see this working in Svelte REPL: | |
https://svelte.technology/repl?version=1.38.0&gist=36de0315edd6d53dc8a9bb72cf3bfb53 | |
--> | |
<Cmp></Cmp> | |
<script> | |
import Cmp from './Cmp.html' |
export function observe(key, callback, opts) { | |
const single = !Array.isArray(key); | |
const keypaths = single ? [ key ] : key; | |
const parts = keypaths.map(keypath => keypath.replace(/\[(\d+)\]/g, '.$1').split('.')); | |
const keys = parts.map(parts => parts[0]); | |
const fn = callback.bind(this); | |
let last = parts.map(parts => getNestedValue(this.get(), parts)); | |
if (!opts || opts.init !== false) { |
var hw = (function () { | |
'use strict'; | |
function noop() {} | |
function assign(tar, src) { | |
for (var k in src) tar[k] = src[k]; | |
return tar; | |
} |
-- This is the result I want: | |
-- | |
-- foo | bar | description | |
-- -----+-----+------------- | |
-- 3 | 4 | two | |
-- 1 | 2 | four | |
-- 5 | 6 | five | |
-- | |
-- Which I can get with this query, but can I do it | |
-- more simply? |
update
I've created a little repository that simply exposes the final utility as npm
module.
It's called html-escaper
there is basically one rule only: do not ever replace one char after another if you are transforming a string into another.
declare module '*.svelte' { | |
type Data = { [key]: any } | |
type Changed = { [key]: boolean } | |
type Listener = { cancel: () => void } | |
export default class Component { | |
root: Component | |
options: Data | |
constructor(init: { target: Element, data: Data }) |
# Redis Cheatsheet | |
# All the commands you need to know | |
redis-server /path/redis.conf # start redis with the related configuration file | |
redis-cli # opens a redis prompt | |
# Strings. |
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; // importing xmlhttprequest package because node doesn't support it out of the box | |
const superHeroes = ['Batman', 'Superman', 'WonderWoman', 'Flash', 'Cyborg', 'Aquaman', 'Green Lantern', 'Martian Manhunter']; // an array of request params | |
const completedFetchingData = () => { // function to be called when all ajax requests complete. | |
console.log('Just completed fetching the data'); | |
} | |
const failedFetchingData = () => { // function to be called when data fetching fails | |
console.log('Failed to fetch the data'); | |
} | |
const ajaxRequestWithPromise = (param) => { |
{ | |
"name": "project-name", | |
"description": "Template for static sites", | |
"version": "1.0.0", | |
"homepage": "http://www.project-name.com", | |
"author": { | |
"name": "Adam Buczynski", | |
"url": "http://adambuczynski.com" | |
}, | |
"license": "UNLICENSED", |