This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| angular.module('crypto', []) | |
| .provider('crypto', function () { | |
| var crypto = window.crypto, subtle; | |
| if (!crypto || !(subtle = crypto.subtle || crypto.webkitSubtle)) { | |
| throw new Error('Web Cryptographic API not supported'); | |
| } | |
| var hashAlg = {name: 'SHA-1'}; | |
| var keyDerivationAlg = {name: 'PBKDF2', iterations: 500000, hash: hashAlg}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class EnumMap<E> { | |
| values: string[]; | |
| enum_: E; | |
| private constructor(enum_: E, mappings: EnumMap.Type<E>) { | |
| this.values = Object.keys(mappings); | |
| this.enum_ = enum_; | |
| return Object.assign(Object.create(this), mappings); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function splitWords(str: string) { | |
| return str.replace(/([a-z]|[A-Z]+)([A-Z]+$|[A-Z])/g, "$1 $2"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class EnumMap<E, T> { | |
| values: string[]; | |
| enum_: E; | |
| private constructor(enum_: E, mappings: EnumMap.Type<E, T>) { | |
| this.values = Object.keys(mappings); | |
| this.enum_ = enum_; | |
| return Object.assign(Object.create(this), mappings); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export interface Action { | |
| readonly type: string; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function appendHtml(element, content) { | |
| const aux = document.createElement(element.tagName); | |
| aux.innerHTML = content; | |
| for (let i = 0; i < aux.children.length; i++) { | |
| element.appendChild(aux.children[i]); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function* LazySequence(to, from = 0) { | |
| while (from < to) { | |
| yield from++; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export {}; | |
| declare global { | |
| interface ArrayConstructor { | |
| range(size, start?): number[]; | |
| } | |
| } | |
| Array.range = Array.range || function (size, start = 0) { | |
| return Array.from(Array(size + start).keys()).slice(start); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const idx = (o, ...p) => p.reduce((a, i) => a && a[i], o) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function deepSet(value: any, obj: object, ...path: string[]) { | |
| const target = path.slice(0, -1).reduce((p: any, k) => (p[k] = p[k] || {}), obj); | |
| path.slice(-1).forEach(k => target[k] = value); | |
| } | |
| let o; | |
| deepSet(99, o = { a: { x: 88 } }, ...'a.b.c'.split('.')); | |
| console.log(o); |