Skip to content

Instantly share code, notes, and snippets.

@Komock
Komock / ng-convert-component-to-module.js
Created May 17, 2019 06:37
Node script to convert existing component to module
const path = require('path');
const fs = require('fs');
const APP_MODULES_DIR = 'projects/evo-ui-kit/src/lib/modules';
const APP_COMPONENTS_DIR = 'projects/evo-ui-kit/src/lib/components';
const pascalize = (str) => {
return str
.replace(/\s(.)/g, (s) => s.toUpperCase() )
.replace(/-(.)/g, (s) => s.toUpperCase() )
.replace(/\s/g, '')
@Komock
Komock / settings.json
Created March 8, 2020 06:20
live Sass Compiler plugin config (should be in .vscode folder)
{
"liveSassCompile.settings": {
"generateMap": false,
"includeItems": [
"./scss/style.scss"
],
"formats":[
{
"format": "expanded",
"extensionName": ".css",
@Komock
Komock / print-html-element.js
Created May 15, 2020 14:05
Print HTML element by selector
function printElem(selector, width, height) {
const newWindow = window.open('', 'PRINT', `height=${height},width=${width}`);
const element = document.querySelector(selector);
newWindow.document.write(`
<html>
<head>
<title>${document.title}</title>
</head>
<body>${element.innerHTML}</body>
</html>`);
@Komock
Komock / zone-enter.operator.ts
Created May 20, 2020 07:23
RxJS Operator to pipe into zone
export function enterZone(zone: NgZone) {
return <T>(source: Observable<T>) =>
new Observable<T>(observer =>
source.subscribe({
next: (x) => zone.run(() => observer.next(x)),
error: (err) => observer.error(err),
complete: () => observer.complete()
})
);
}
@Komock
Komock / view-state.ts
Created September 23, 2021 06:32
View state from BehaviorSubject
export class ViewState<T extends object> extends BehaviorSubject<T> {
constructor(initialState: T) {
super(initialState);
}
patch(newState: Partial<T>) {
this.next({
...this.value,
...newState
});