ng add @angular-eslint/schematics
npm i prettier prettier-eslint eslint-config-prettier eslint-plugin-prettier -D
Filename: .eslintrc.json
function formatDate(date = new Date(), format = "yyyy/mm/dd") { | |
const map = { | |
mm: date.getMonth() + 1, | |
dd: date.getDate(), | |
yyyy: date.getFullYear() | |
} | |
return format.replace(/mm|dd|yyyy/gi, matched => { | |
return map[matched].toString().padStart(2, '0') | |
}) |
function truncate(str, length) { | |
return str.length > length | |
? `${str.substr(0, length)}...` | |
: str; | |
} |
import { AfterViewInit, Directive, ElementRef, Input, Renderer2 } from '@angular/core'; | |
@Directive({ | |
selector: '[appReadMore]' | |
}) | |
export class ReadMoreDirective implements AfterViewInit { | |
@Input() limit : number = 50; //to get the custom text limit | |
@Input() toggle : boolean = false; //true: 'Read Less' button will be present | |
txtSpan! : HTMLSpanElement; |
const synth = speechSynthesis; | |
const msg = new SpeechSynthesisUtterance(); | |
msg.text = 'Hola amo'; | |
// o directamente new SpeechSynthesisUtterance('Hola amo'); | |
msg.lang = 'es-ES'; | |
synth.speak(msg); |
function queryStringToJSON(qs) { | |
var pares = qs.slice(1).split('&'); | |
var resultado = {}; | |
pares.forEach(function(par) { | |
par = par.split('='); | |
resultado[par[0]] = decodeURIComponent(par[1] || ''); | |
}); | |
return JSON.parse(JSON.stringify(resultado)); |
type ServiceConfigParams = "port" | "basePath" | "enableStripePayments"; | |
const serviceConfigChecked: Record<ServiceConfigParams, string | number | boolean> = { | |
port: 3000, | |
basePath: "http://localhost", | |
enableStripePayments: false, | |
}; |
type Point2d = [x: number, y: number]; | |
type Point3d = [x: number, y: number, z: number]; | |
const point: Point2d = [1, 2]; // the IDE will help you showing which is x and y |
const degToRad = (degree): number => (degree * Math.PI) / 180; |
function computeFrequency(input: string): Map<string, number> { | |
const freqTable = new Map(); | |
for (let ch of input) { | |
if (!freqTable.has(ch)) { | |
freqTable.set(ch, 1); | |
} else { | |
freqTable.set(ch, freqTable.get(ch) + 1); | |
} | |
} |