npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pythonic-js-input

v1.3.0

Published

Python처럼 간편하게 터미널 입력을 받을 수 있는 JavaScript 라이브러리 (node:readline/promises 기반, 붙여넣기 완벽 지원)

Readme

pythonic-js-input

Python의 input() 함수처럼 간편하게 JavaScript에서 터미널 입력을 받을 수 있는 라이브러리입니다.

✨ 특징: 여러 줄 붙여넣기를 완벽하게 지원합니다! node:readline/promises와 비동기 반복자를 사용하여 안정적인 입력 처리를 제공합니다.

설치

npm install pythonic-js-input

핵심 원리

이 라이브러리는 node:readline/promises와 **비동기 반복자(async iterator)**를 사용하여 구현되었습니다.

// 내부 구조 (간략화)
const readline = require('node:readline/promises');
const rl = readline.createInterface({ 
    input: process.stdin, 
    output: process.stdout,
    terminal: false
});
const inputGenerator = rl[Symbol.asyncIterator]();

async function input(prompt = "") {
    if (prompt) process.stdout.write(prompt);
    const result = await inputGenerator.next();
    return result.value;
}

이 방식의 장점:

  • 여러 줄 붙여넣기 완벽 지원: 여러 줄을 한 번에 붙여넣어도 순차적으로 처리
  • 안정적: readline interface를 한 번만 생성하여 재사용
  • Python과 동일한 동작: 정확히 Python의 input()처럼 작동

사용법

기본 입력

const { input } = require("pythonic-js-input");

(async () => {
  const name = await input("이름을 입력하세요: ");
  console.log(`안녕하세요, ${name}님!`);
})();

정수 입력

const { inputInt } = require("pythonic-js-input");

(async () => {
  const age = await inputInt("나이를 입력하세요: ");
  console.log(`당신은 ${age}살입니다.`);
})();

실수 입력

const { inputFloat } = require("pythonic-js-input");

(async () => {
  const height = await inputFloat("키를 입력하세요 (cm): ");
  console.log(`당신의 키는 ${height}cm입니다.`);
})();

여러 줄 입력 (붙여넣기 지원 ✨)

const { inputLines } = require("pythonic-js-input");

(async () => {
  // 여러 줄을 한 번에 복사(Ctrl+C)해서 붙여넣기(Ctrl+V) 가능!
  const lines = await inputLines("3줄을 입력하세요:", 3);
  console.log("입력한 내용:");
  lines.forEach((line, index) => {
    console.log(`${index + 1}: ${line}`);
  });
})();

빈 줄로 종료 (엔터만 입력)

const { inputUntilEmpty } = require("pythonic-js-input");

(async () => {
  // 여러 줄 입력 후 빈 줄(엔터만)을 입력하면 종료
  const lines = await inputUntilEmpty("입력을 시작하세요 (빈 줄로 종료):");
  console.log(`총 ${lines.length}줄 입력되었습니다.`);
})();

특정 키워드로 종료

const { inputUntilKeyword } = require("pythonic-js-input");

(async () => {
  // "END"를 입력하면 종료
  const lines = await inputUntilKeyword("입력 시작 (END로 종료):", "END");
  console.log("입력된 내용:", lines);
})();

텍스트 블록 입력

const { inputText } = require("pythonic-js-input");

(async () => {
  // 여러 줄을 하나의 문자열로 입력받기
  const text = await inputText("메모를 작성하세요 (빈 줄로 종료):");
  console.log("작성된 메모:\n" + text);
})();

모든 입력 받기 (EOF까지)

const { inputAll } = require("pythonic-js-input");

(async () => {
  // Ctrl+D (Mac/Linux) 또는 Ctrl+Z (Windows)로 종료
  const lines = await inputAll("여러 줄을 입력하세요:");
  lines.forEach((line) => console.log(line));
})();

배열 입력

const { inputArray, inputIntArray } = require("pythonic-js-input");

(async () => {
  // 문자열 배열
  const fruits = await inputArray("과일 이름을 공백으로 구분하여 입력하세요: ");
  console.log("입력한 과일:", fruits);

  // 정수 배열
  const numbers = await inputIntArray(
    "숫자들을 공백으로 구분하여 입력하세요: "
  );
  console.log("입력한 숫자:", numbers);
  console.log(
    "합계:",
    numbers.reduce((a, b) => a + b, 0)
  );
})();

사용자 정의 구분자

const { inputArray } = require("pythonic-js-input");

(async () => {
  const items = await inputArray("쉼표로 구분하여 입력하세요: ", ",");
  console.log("입력한 항목:", items);
})();

API

input(prompt)

  • prompt (string): 사용자에게 표시할 메시지
  • 반환값: Promise<string> - 입력받은 문자열

inputInt(prompt)

  • prompt (string): 사용자에게 표시할 메시지
  • 반환값: Promise<number> - 입력받은 정수

inputFloat(prompt)

  • prompt (string): 사용자에게 표시할 메시지
  • 반환값: Promise<number> - 입력받은 실수

inputLines(prompt, count)

  • prompt (string): 사용자에게 표시할 메시지
  • count (number): 입력받을 줄의 개수
  • 반환값: Promise<string[]> - 입력받은 문자열 배열
  • 특징: 여러 줄을 한 번에 복사해서 붙여넣기 가능 ✨

inputUntilEmpty(prompt)

  • prompt (string): 사용자에게 표시할 메시지
  • 반환값: Promise<string[]> - 입력받은 문자열 배열 (빈 줄 제외)
  • 특징: 빈 줄(엔터만)을 입력하면 입력 종료

inputUntilKeyword(prompt, endKeyword, includeKeyword)

  • prompt (string): 사용자에게 표시할 메시지
  • endKeyword (string): 종료 키워드 (기본값: 'END')
  • includeKeyword (boolean): 종료 키워드를 결과에 포함할지 여부 (기본값: false)
  • 반환값: Promise<string[]> - 입력받은 문자열 배열
  • 특징: 특정 키워드를 입력하면 종료

inputText(prompt)

  • prompt (string): 사용자에게 표시할 메시지
  • 반환값: Promise<string> - 입력받은 텍스트 (줄바꿈으로 연결)
  • 특징: 여러 줄을 하나의 문자열로 반환, 빈 줄로 종료

inputAll(prompt)

  • prompt (string): 사용자에게 표시할 메시지
  • 반환값: Promise<string[]> - 입력받은 모든 줄의 배열
  • 특징: EOF(Ctrl+D 또는 Ctrl+Z)까지 모든 입력 받기

inputArray(prompt, separator)

  • prompt (string): 사용자에게 표시할 메시지
  • separator (string): 구분자 (기본값: 공백)
  • 반환값: Promise<string[]> - 입력받은 문자열 배열

inputIntArray(prompt, separator)

  • prompt (string): 사용자에게 표시할 메시지
  • separator (string): 구분자 (기본값: 공백)
  • 반환값: Promise<number[]> - 입력받은 정수 배열

inputFloatArray(prompt, separator)

  • prompt (string): 사용자에게 표시할 메시지
  • separator (string): 구분자 (기본값: 공백)
  • 반환값: Promise<number[]> - 입력받은 실수 배열

붙여넣기 기능 (New! ✨)

이제 여러 줄을 한 번에 복사해서 붙여넣을 수 있습니다!

const { inputLines } = require("pythonic-js-input");

(async () => {
  // 다음 텍스트를 복사:
  // 첫 번째 줄
  // 두 번째 줄
  // 세 번째 줄

  const lines = await inputLines("3줄을 입력하세요:", 3);
  // Ctrl+V로 한 번에 붙여넣기하면 모든 줄이 입력됩니다!

  console.log(lines); // ['첫 번째 줄', '두 번째 줄', '세 번째 줄']
})();

Python과 비교

Python

name = input("이름을 입력하세요: ")
age = int(input("나이를 입력하세요: "))
numbers = list(map(int, input("숫자들을 입력하세요: ").split()))

# 여러 줄 입력
lines = []
for i in range(3):
    lines.append(input())

JavaScript (이 라이브러리 사용)

const {
  input,
  inputInt,
  inputIntArray,
  inputLines,
} = require("pythonic-js-input");

(async () => {
  const name = await input("이름을 입력하세요: ");
  const age = await inputInt("나이를 입력하세요: ");
  const numbers = await inputIntArray("숫자들을 입력하세요: ");

  // 여러 줄 입력 (붙여넣기 지원!)
  const lines = await inputLines("", 3);
})();

라이선스

MIT