How to use typescript-monads - 10 common examples

To help you get started, we’ve selected a few typescript-monads examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github patrickmichalina / fusing-angular / src / electron / protocol.ts View on Github external
import { protocol } from 'electron'
import { join, normalize } from 'path'
import { reader } from 'typescript-monads'
import { IElectronConfig } from './config'

export const initInterceptFileProtocol = reader(cfg => {
  const log = cfg.LOGGER.child({ function: 'initInterceptFileProtocol' })
  log.trace('Entered function')

  const PROTOCOL = 'file';

  log.trace('setting interceptFileProtocol')
  protocol.interceptFileProtocol(PROTOCOL, (request, callback) => {
    // strip protocol
    let url = request.url.substr(PROTOCOL.length + 1);

    if (request.url.includes('/assets/') || request.url.includes('index.html')) {
      // build complete path for node require function
      url = join(cfg.PATH_TO_PUBLIC_FOLDER, url);
    }

    // replace backslashes by forward slashes (windows)
github patrickmichalina / fusing-angular / src / server / cluster.ts View on Github external
import { createExpressApplication } from "./app"
import * as throng from 'throng'

const serverListen = () => () => console.info('Angular Universal server listening for requests...')

const createApplicationServer =
  (app: Application) =>
    reader(config =>
      createServer(app).listen(config.PORT, serverListen()))

const spawnServer = (config: IConfig) =>
  createExpressApplication
    .flatMap(createApplicationServer)
    .run(config)

export const spawnServerCluster = reader(config =>
  config.NODE_DEBUG
    ? spawnServer(config)
    : throng(config.CLUSTERED_WORKERS, () => spawnServer(config)))
github patrickmichalina / fusing-angular / fuse.ts View on Github external
setServerRef(val?: ServerLauncher) {
    this.serverRef = maybe(val)
  }
  killNgc = () => this.ngcProcess.tapSome(ref => ref.kill())
github patrickmichalina / fusing-angular / src / server / config.ts View on Github external
    .match({ some: maybe, none: () => maybe(process.env.PORT) })
    .map(p => +p).valueOr(4200),
github patrickmichalina / fusing-angular / src / electron / menus / shared / language.ts View on Github external
.tapSome(items => {
      items.forEach(i => i.checked = false)
      maybe(items.find(b => b.id === lang)).tapSome(b => {
        sendAngularMessage(window, 'change-language', lang)
        b.checked = true
      })
    })
}
github patrickmichalina / fusing-angular / src / server / config.ts View on Github external
readonly [key: string]: string
}

export interface IConfig {
  readonly PORT: number
  readonly NODE_DEBUG: boolean
  readonly CLUSTERED_WORKERS: number
  readonly DIST_FOLDER: string
  readonly WWW_ROOT: string
  readonly HTTP_LOGS_ENABLED: boolean
}

export const STANDARD_CONFIG: IConfig = {
  NODE_DEBUG: maybe(process.env.NODE_ENV).filter(a => a === 'production').isNone(),
  HTTP_LOGS_ENABLED: maybe(process.env.HTTP_LOGS_DISABLED).filter(Boolean).isNone(),
  PORT: maybe(argv['port'] as string | undefined)
    .match({ some: maybe, none: () => maybe(process.env.PORT) })
    .map(p => +p).valueOr(4200),
  CLUSTERED_WORKERS: maybe(process.env.WEB_CONCURRENCY).map(a => +a).valueOr(1),
  DIST_FOLDER: resolve('dist'),
  WWW_ROOT: 'wwwroot'
}
github patrickmichalina / fusing-angular / fuse.ts View on Github external
electron: {
      renderer: fusebox({
        target: 'browser',
        output: 'dist/desktop/wwwroot/assets/js',
        entry: this.aot
          ? this.prod ? 'ngc/esnext/electron/angular/main.aot.prod.js' : 'ngc/esnext/electron/angular/main.aot.js'
          : this.prod ? 'src/electron/angular/main.prod.ts' : 'src/electron/angular/main.ts',
        webIndex: { template: 'src/browser/index.pug', distFileName: '../../index.html', publicPath: '/assets/js' },
        dependencies: { ignorePackages: packageJson.fusebox.ignore.browser },
        codeSplitting: { useHash: false, maxPathLength: 0 },
        devServer: false,
        env: Object
          .keys(process.env)
          .filter(k => k.includes('NG_'))
          .reduce((acc, curr) => ({ ...acc, [curr.replace('NG_', '')]: process.env[curr] }), {
            NG_SERVER_HOST: maybe(process.env.HOSTNAME).valueOr(`http://localhost:${this.ngServerPort}`)
          }),
        ...this.shared,
        plugins: [pluginConsolidate('pug', { ...pugSharedLocals, isElectron: true }), ...this.shared.plugins]
      }),
      main: fusebox({
        target: 'electron',
        entry: 'src/electron/app.ts',
        output: 'dist/desktop',
        useSingleBundle: true,
        devServer: false,
        sourceMap: false,
        dependencies: {
          ignoreAllExternal: false,
          ignorePackages: packageJson.fusebox.ignore.electron
        },
        ...this.shared
github patrickmichalina / fusing-angular / src / server / config.ts View on Github external
export interface StringDictionary {
  readonly [key: string]: string
}

export interface IConfig {
  readonly PORT: number
  readonly NODE_DEBUG: boolean
  readonly CLUSTERED_WORKERS: number
  readonly DIST_FOLDER: string
  readonly WWW_ROOT: string
  readonly HTTP_LOGS_ENABLED: boolean
}

export const STANDARD_CONFIG: IConfig = {
  NODE_DEBUG: maybe(process.env.NODE_ENV).filter(a => a === 'production').isNone(),
  HTTP_LOGS_ENABLED: maybe(process.env.HTTP_LOGS_DISABLED).filter(Boolean).isNone(),
  PORT: maybe(argv['port'] as string | undefined)
    .match({ some: maybe, none: () => maybe(process.env.PORT) })
    .map(p => +p).valueOr(4200),
  CLUSTERED_WORKERS: maybe(process.env.WEB_CONCURRENCY).map(a => +a).valueOr(1),
  DIST_FOLDER: resolve('dist'),
  WWW_ROOT: 'wwwroot'
}
github patrickmichalina / fusing-angular / src / server / config.ts View on Github external
export interface StringDictionary {
  readonly [key: string]: string
}

export interface IConfig {
  readonly PORT: number
  readonly NODE_DEBUG: boolean
  readonly CLUSTERED_WORKERS: number
  readonly DIST_FOLDER: string
  readonly WWW_ROOT: string
  readonly HTTP_LOGS_ENABLED: boolean
}

export const STANDARD_CONFIG: IConfig = {
  NODE_DEBUG: maybe(process.env.NODE_ENV).filter(a => a === 'production').isNone(),
  HTTP_LOGS_ENABLED: maybe(process.env.HTTP_LOGS_DISABLED).filter(Boolean).isNone(),
  PORT: maybe(argv['port'] as string | undefined)
    .match({ some: maybe, none: () => maybe(process.env.PORT) })
    .map(p => +p).valueOr(4200),
  CLUSTERED_WORKERS: maybe(process.env.WEB_CONCURRENCY).map(a => +a).valueOr(1),
  DIST_FOLDER: resolve('dist'),
  WWW_ROOT: 'wwwroot'
}

typescript-monads

Write cleaner TypeScript

MIT
Latest version published 12 months ago

Package Health Score

56 / 100
Full package analysis

Popular typescript-monads functions