Skip to content

Instantly share code, notes, and snippets.

View waterplea's full-sized avatar

Alex Inkin waterplea

View GitHub Profile
@waterplea
waterplea / for-map.directive.ts
Created September 8, 2020 17:56
ngFor for maps with delay on removal
export class ForMapOfContext<T> {
destroyed = false;
constructor(readonly $implicit: T) {}
}
@Directive({selector: '[ngForMap][ngForMapOf]'})
export class ForMapOfDirective<T, G> {
@Input()
set ngForMapOf(map: Map<T, G>) {
@waterplea
waterplea / for-map.ts
Created August 13, 2020 07:37
ngFor for immutable maps
export class ForMapOfContext<T> {
destroyed = false;
constructor(readonly $implicit: T) {}
}
@Directive({selector: '[ngForMap][ngForMapOf]'})
export class ForMapOfDirective<T, G> {
@Input()
set ngForMapOf(map: Map<T, G>) {
@waterplea
waterplea / setRangeOffset.ts
Created July 10, 2020 10:22
Setting range in characters, traversing nodes
// Filtering SVGElements for TreeWalker
// Filter must be a function in IE, other modern browsers are compliant to this format
export const svgNodeFilter: NodeFilter = ((node: Node) =>
'ownerSVGElement' in node
? NodeFilter.FILTER_REJECT
: NodeFilter.FILTER_ACCEPT) as any;
/**
* Range.setStart/setEnd, except it uses offset in characters only
*/
@waterplea
waterplea / gradient-parser.ts
Created July 9, 2020 10:09
A RegExp based CSS gradient parser by Dean Taylor turned to TypeScript
//
// TypeScript parser based on Dean Taylor's answer:
// https://stackoverflow.com/a/20238168/2706426
//
interface GradientStop {
color: string;
position?: string;
}
interface ParsedGraient {
@waterplea
waterplea / test.ts
Last active February 10, 2020 07:50
Pupeteer like browser control over devtools protocol in basic Karma
fetch('http://localhost:9222/json')
.then(response => response.json())
.then(([response]) => {
const socket = new WebSocket(response.webSocketDebuggerUrl);
socket.onopen = () => {
socket.send(
JSON.stringify({
id: 1,
method: 'Browser.grantPermissions',
abstract class Sanitizer {
abstract sanitize(context: SecurityContext, value: string | {}): string | null
}
abstract class DomSanitizer implements Sanitizer {
abstract sanitize(context: SecurityContext, value: string | SafeValue): string | null
abstract bypassSecurityTrustHtml(value: string): SafeHtml
abstract bypassSecurityTrustStyle(value: string): SafeStyle
abstract bypassSecurityTrustScript(value: string): SafeScript
abstract bypassSecurityTrustUrl(value: string): SafeUrl