How to use the get-stdin function in get-stdin

To help you get started, we’ve selected a few get-stdin 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 flow-typed / flow-typed / definitions / npm / get-stdin_v5.x.x / test_get-stdin_v5.x.x.js View on Github external
import getStdin from 'get-stdin';

getStdin().then((str: string) => {});
getStdin.buffer().then((str: Buffer) => {});

// $ExpectError
(getStdin(): number);

// $ExpectError
(getStdin.buffer(): number);
github pgilad / leasot / src / cli / cli.ts View on Github external
const run = (program: ProgramArgs): void => {
    if (program.args && program.args.length > 0) {
        return parseAndReportFiles(program.args, program);
    }

    if (process.stdin.isTTY) {
        return program.help();
    }

    // data is coming from a pipe
    getStdin()
        .then(function(content: string) {
            const todos = parseContentSync(content, program);
            outputTodos(todos, program);
        })
        .catch(function(e) {
            console.error(e);
            process.exit(1);
        });
};
github mikberg / codenamer / src / cli.js View on Github external
letters. Adjust variance like 'n10/2'.
      c       Word class. Restrict this word to a word class:
                        - J for adjective
                        - N for noun
                        - R for adverb
                        - V for verb
      a               Alliterate (word rhyme) up to and including this word,
                      e.g. allow 'cheshire cat' but not 'cheshire dog'.

    Examples
      $ cat myfile.txt | codenamer
      $ curl -s https://en.wikipedia.org/wiki/Batman | codenamer
      $ curl -s https://en.wikipedia.org/wiki/Batman | codenamer --format pa-a,n15
`, minimistOptions);

getStdin().then(input => {
  if (!input) {
    /* eslint no-console:0 */
    console.error('ERR: No input given');
    console.log(cli.help);
    process.exit(0);
  }

  const options = Object.assign({}, defaults, cli.flags);
  const output = codenamer(options.format.split('-'), input, options.count);

  console.log(output.map(code => code.join('-')).join('\n'));
});
github gajus / canonical / src / bin / commands / fixCommand.js View on Github external
const handleStdin = (argv) => {
    /* eslint-disable no-unused-expressions */
    yargs
    /* eslint-enable */
        .demand(0, 0)
        .argv;

    getStdin()
        .then((stdin) => {
            const result = fixText(stdin, {
                syntax: argv.syntax
            });

            /* eslint-disable no-console */
            console.log(result);
            /* eslint-enable */
        });
};
github gajus / canonical / src / bin / commands / lintCommand.js View on Github external
const handleStdin = (argv) => {
    /* eslint-disable no-unused-expressions */
    yargs
    /* eslint-enable */
        .demand(0, 0)
        .argv;

    getStdin()
        .then((stdin) => {
            const report = lintText(stdin, {
                filePath: argv.filePath,
                syntax: argv.syntax
            });

            outputReport({
                errorCount: report.errorCount,
                results: [
                    report
                ],
                warningCount: report.warningCount
            }, argv.outputFormat);
        });
};
github jeswin / basho / src / bashfury.js View on Github external
#!/usr/bin/env node

import parse from "./parse";
import getStdin from "get-stdin";

getStdin()
  .then(async str => {
    const output = await parse(
      process.argv.slice(2),
      str.replace(/\n$/, "").split("\n")
    );
    if (output.mustPrint) {
      if (Array.isArray(output.result)) {
        output.result.forEach(i => console.log(i));
      } else {
        console.log(output.result);
      }
    }
    process.exit(0);
  })
  .catch(error => {
    console.error(error.message);
github kvz / invig / src / cli.js View on Github external
})
}

const invig = new Invig({
  src   : program.src,
  check : program.check,
  dryrun: program.dryrun,
  bail  : program.bail,
  init  : program.init,
  quiet : program.quiet,
  npmBinDir,
  es7   : program.es7,
})

if (program.src === '-') {
  getStdin().then(stdin => {
    invig
      .runOnStdIn(stdin)
      .catch(err => {
        scrolex.failure(`${err}`)
        process.exit(1)
      })
      .then(() => {
        scrolex.success(`Done`)
      })
  })
} else {
  invig
    .runOnPattern()
    .catch(err => {
      scrolex.failure(`${err}`)
      process.exit(1)
github relekang / lint-filter / src / index.js View on Github external
const options = parseOptions()

  if (options.command === 'generate-config') {
    return setup(options)
  }

  const diff = await getDiffInformation(options)

  if (options.command === 'list-files') {
    return console.log(_.keys(diff).join(' '))
  }

  if (!options.command) {
    let result
    if (_.isEmpty(options.files)) {
      const input = await stdin()

      if (input === '') {
        throw new Error('stdin was empty')
      }

      result = await checkString(diff, input, options)
    } else {
      result = await checkFiles(diff, options.files, options)
    }
    return handleResult(result, options)
  }

  throw new Error(`Unknown command '${options.command}'`)
}
github lukechilds / htconvert / src / cli.js View on Github external
#!/usr/bin/env node

import program from 'commander';
import { readFile } from 'fs-promise';
import getStdin from 'get-stdin';
import { version } from '../package.json';
import htconvert from './htconvert';

program
  .version(version)
  .option('-f, --file [.htaccess]', 'File containing .htaccess redirects')
  .parse(process.argv);

const readHtaccess = program.file ? readFile(program.file, 'utf-8') : getStdin();

readHtaccess
  .then(htaccess => htaccess ? htconvert(htaccess) : program.help())
  .then(console.log);
github KnisterPeter / react-to-typescript-definitions / src / index.ts View on Github external
options.topLevelModule ? null : options.moduleName,
      code,
      {},
      options.reactImport
    );
    process.stdout.write(result);
  };
  if (options.file) {
    fs.readFile(options.file, (err, data) => {
      if (err) {
        throw err;
      }
      processInput(data.toString());
    });
  } else {
    getStdin().then(processInput);
  }
}

get-stdin

Get stdin as a string or buffer

MIT
Latest version published 3 years ago

Package Health Score

73 / 100
Full package analysis

Popular get-stdin functions