a typescript wrapper for Application Insights
import { trackException } from './appinsights-helper'
trackException({ exception: error })
import NodeCache from 'node-cache'; // or 'redis' | |
class CacheService { | |
constructor(ttlSeconds) { | |
// this could also be redis | |
this.cache = new NodeCache({ stdTTL: ttlSeconds, checkperiod: ttlSeconds * 0.2, useClones: false }); | |
} | |
get(key, storeFunction) { |
const { ServiceBusClient, ReceiveMode } = require('@azure/service-bus') | |
const connectionString = process.env['servicebus-connection'] | |
async function send () { | |
const sbClient = ServiceBusClient.createFromConnectionString(connectionString) | |
const client = sbClient.createTopicClient('topic-name') | |
const sender = client.createSender() | |
// set label=TEST for use in subscription filter | |
const msg = { label: 'TEST', body: { foo: 'bar', ts: new Date() } } |
import * as rp from 'request-promise-native' | |
function convertTable (columns: any[], rows: any[]): any[] { | |
return rows.map((row: any[]) => columns.reduce((obj, col, idx) => { | |
obj[col.name] = row[idx] | |
return obj | |
}, {})) | |
} | |
// API reference @ https://dev.applicationinsights.io/reference |
Object.getOwnPropertyNames(Date.prototype) | |
.filter(name => name.startsWith('to')) | |
.map(method => `${method}: ${(new Date())[method]()}`) |
function numToColor (num, maxHue = 350, minHue = 0) { | |
const hue = num * (maxHue - minHue) + minHue | |
return `hsl(${hue}, 70%, 45%)` | |
} |
const glob = require('glob') | |
const fs = require('fs'); | |
const xml2js = require('xml2js'); | |
const path = require('path'); | |
function parseFile (filePath, parser) { | |
fs.readFile(filePath, (err, data) => { | |
parser.parseString(data, (err, result) => { | |
const itemgroups = result.Project.ItemGroup; | |
if (itemgroups && itemgroups.length) { |