tinyinput 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) walonCode
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,92 @@
1
+ **TinyInput**
2
+ ================
3
+
4
+ A simple library that takes user input the same way it is done in Python.
5
+
6
+ **Description**
7
+ ---------------
8
+
9
+ TinyInput is a lightweight JavaScript library that provides an easy way to read user input from the standard input (stdin) and write to the standard output (stdout). Inspired by Python's built-in `input()` function, TinyInput aims to simplify user input handling in Node.js applications.
10
+
11
+ **Features**
12
+ ------------
13
+
14
+ * Read user input from stdin
15
+ * Write to stdout
16
+ * Simple and easy to use API
17
+
18
+ **Installation**
19
+ --------------
20
+
21
+ To install TinyInput, run the following command:
22
+
23
+ ```
24
+ npm install tinyinput
25
+ ```
26
+
27
+ **Usage**
28
+ -----
29
+
30
+ To use TinyInput, simply import the library and call the `input()` function:
31
+ ```ts
32
+ import { input } from 'tinyinput';
33
+
34
+ async function main(){
35
+ const userInput = await input('Please enter your name: ', opt);
36
+ console.log(`Hello, ${userInput}!`);
37
+ }
38
+
39
+ main()
40
+
41
+ //opt can be "int" | "float" | "string"
42
+ ```
43
+
44
+ **Technologies**
45
+ -------------
46
+
47
+ * Written in TypeScript
48
+ * Built with tsup
49
+ * Compatible with Node.js
50
+
51
+ **Configuration and Env**
52
+ ------------------------
53
+
54
+ No specific configuration or environment variables are required to use TinyInput.
55
+
56
+ **Folder Structure**
57
+ ---------------------
58
+
59
+ ```
60
+ .
61
+ ├── .gitignore
62
+ ├── .npmignore
63
+ ├── LICENSE
64
+ ├── README.md
65
+ ├── package-lock.json
66
+ ├── package.json
67
+ ├── src
68
+ | ├── index.ts
69
+ | ├── type.ts
70
+ ├── tsconfig.json
71
+ ├── tsup.config.ts
72
+ ```
73
+
74
+ **Author**
75
+ ---------
76
+
77
+ Mohamed Lamin Walon-Jalloh ([@walonCode](https://github.com/walonCode))
78
+
79
+ **Contribution**
80
+ -------------
81
+
82
+ If you'd like to contribute to TinyInput, please fork the repository and submit a pull request. Your help is greatly appreciated!
83
+
84
+ **License**
85
+ ---------
86
+
87
+ TinyInput is licensed under the MIT License.
88
+
89
+ **GitHub Badges**
90
+
91
+ TypeScript: ![TypeScript](https://img.shields.io/badge/-TypeScript-3178C6?style=flat-square&logo=typescript&logoColor=white)
92
+ Node.js: ![Node.js](https://img.shields.io/badge/-Node.js-339933?style=flat-square&logo=node.js&logoColor=white)
@@ -0,0 +1,5 @@
1
+ type Opt = "int" | "float" | "string";
2
+
3
+ declare function input(question: string, opt: Opt): Promise<string | number>;
4
+
5
+ export { input };
@@ -0,0 +1,5 @@
1
+ type Opt = "int" | "float" | "string";
2
+
3
+ declare function input(question: string, opt: Opt): Promise<string | number>;
4
+
5
+ export { input };
package/dist/index.js ADDED
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ input: () => input
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_promises = require("readline/promises");
27
+ async function input(question, opt) {
28
+ const r1 = (0, import_promises.createInterface)({
29
+ input: process.stdin,
30
+ output: process.stdout
31
+ });
32
+ let value;
33
+ let parse;
34
+ while (true) {
35
+ value = await r1.question(question);
36
+ r1.close();
37
+ value = value.trim();
38
+ if (opt === "int") {
39
+ parse = parseInt(value, 10);
40
+ if (!Number.isNaN(parse)) break;
41
+ console.log("Please enter a valid integer");
42
+ } else if (opt === "float") {
43
+ parse = parseFloat(value);
44
+ if (!Number.isNaN(value)) break;
45
+ console.log("Please enter a valid number");
46
+ } else {
47
+ if (value.length > 0) {
48
+ parse = value;
49
+ break;
50
+ }
51
+ console.log("Please enter a non-empty string.");
52
+ }
53
+ }
54
+ return parse;
55
+ }
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ input
59
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,34 @@
1
+ // src/index.ts
2
+ import { createInterface } from "readline/promises";
3
+ async function input(question, opt) {
4
+ const r1 = createInterface({
5
+ input: process.stdin,
6
+ output: process.stdout
7
+ });
8
+ let value;
9
+ let parse;
10
+ while (true) {
11
+ value = await r1.question(question);
12
+ r1.close();
13
+ value = value.trim();
14
+ if (opt === "int") {
15
+ parse = parseInt(value, 10);
16
+ if (!Number.isNaN(parse)) break;
17
+ console.log("Please enter a valid integer");
18
+ } else if (opt === "float") {
19
+ parse = parseFloat(value);
20
+ if (!Number.isNaN(value)) break;
21
+ console.log("Please enter a valid number");
22
+ } else {
23
+ if (value.length > 0) {
24
+ parse = value;
25
+ break;
26
+ }
27
+ console.log("Please enter a non-empty string.");
28
+ }
29
+ }
30
+ return parse;
31
+ }
32
+ export {
33
+ input
34
+ };
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "tinyinput",
3
+ "version": "0.0.1",
4
+ "description": "A simple library that takes user input the same way it is done in python.",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsup"
10
+ },
11
+ "repository": {
12
+ "url": "https://github.com/walonCode/tinyinput/"
13
+ },
14
+ "keywords": [
15
+ "input",
16
+ "stdin",
17
+ "stdout"
18
+ ],
19
+ "author": "Mohamed Lamin Walon-Jalloh",
20
+ "license": "MIT",
21
+ "devDependencies": {
22
+ "@types/node": "^24.3.0",
23
+ "tsup": "^8.5.0",
24
+ "typescript": "^5.9.2"
25
+ }
26
+ }