Coder Social home page Coder Social logo

get_stdin's Introduction

get_stdin ci

Get stdin as a string or buffer

Usage

// example.ts
import { getStdin, getStdinBuffer } from 'https://deno.land/x/get_stdin/mod.ts';

console.log(await getStdin());
//=> 'unicorns'

console.log(await getStdinBuffer());
//=> Uint8Array(8) [
//   117, 110, 105,
//   99, 111, 114,
//   110, 115
// ]

There's a sync mode too

// example.ts
import { getStdinSync, getStdinBufferSync } from 'https://deno.land/x/get_stdin/mod.ts';

console.log(getStdinSync());
//=> 'unicorns'

console.log(await getStdinBufferSync());
//=> Uint8Array(8) [
//   117, 110, 105,
//   99, 111, 114,
//   110, 115
// ]
$ echo unicorns | deno run example.ts
unicorns

Also you can read like a cli application

// example.ts
import { getStdin } from 'https://deno.land/x/get_stdin/mod.ts';

console.log("¿What's your name?");
const guest = await getStdin();

console.log(`Hellou ${guest || 'Stranger'}`);
//=> 'Hellou Deno'

You can read whole files from stdin too

// example.ts
import { getStdin } from 'https://deno.land/x/get_stdin/mod.ts';

const input = await getStdin({ exitOnEnter: false });

console.log(`Received a bunch of (possibly) multiline text from stdin:\n${input}`);
$ echo lots\nof\nstuff\nhere > example.txt
$ cat example.txt | deno run example.ts
lots
of
stuff
here

API

getStdin(options?: GetStdinOptions)

Get stdin as a string.

getStdinBuffer(options?: GetStdinOptions)

Get stdin as a Buffer.

getStdinSync(options?: GetStdinOptions)

Get stdin as a string in sync mode.

getStdinBufferSync(options?: GetStdinOptions)

Get stdin as a Buffer in sync mode.

GetStdinOptions

  • exitOnEnter (optional) - If true, stop reading the stdin once a newline char is reached. Defaults to true.

Inspired

  • Inspired by get-stdin - Get stdin as a string or buffer

get_stdin's People

Contributors

rjoydip avatar sant123 avatar vehmloewff avatar

Stargazers

 avatar

Watchers

 avatar  avatar

get_stdin's Issues

Add UTF8!

Hi!
I wrote this test code:


import { getStdin } from 'https://deno.land/x/[email protected]/mod.ts'

const input = await getStdin() 
console.log(`Text:  ${input}`)

  1. Typed Hello world!
    And all well done! I see this result: Text: Hello world!

  2. Typed Привет мир!
    But if i use cyrillic i see this: Text: �ਢ�� ���!

tell me how to fix it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.