@arcsine/nodesh
Advanced tools
Comparing version 1.7.0 to 1.7.1
@@ -38,3 +38,3 @@ /// <reference types="node" /> | ||
*/ | ||
static get $exec(): AsyncIterable<any>['$exec']; | ||
static get $exec(): string['$exec']; | ||
/** | ||
@@ -74,3 +74,3 @@ * In the process of using the tool, there may be a need for encapsulating common | ||
* @example | ||
* (argv[0] ?? 'Enter a file name:'.$prompt()) | ||
* ($argv[0] ?? 'Enter a file name:'.$prompt()) | ||
* // Pull in name from argv[0] or prompt if missing | ||
@@ -107,7 +107,3 @@ * .$read() // Read file | ||
*/ | ||
static get $pattern(): { | ||
URL: RegExp; | ||
EMAIL: RegExp; | ||
PROPER_NAME: RegExp; | ||
}; | ||
static get $pattern(): Record<'URL' | 'EMAIL' | 'PROPER_NAME', RegExp>; | ||
/** | ||
@@ -114,0 +110,0 @@ * Produces a numeric range, between start (1 by default) and stop (inclusive). A step |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const register_1=require("./util/register");class GlobalHelpers{static $of(a){var b,c;return c=null===(b=a)||void 0===b?void 0:b.$iterable,null!==c&&void 0!==c?c:[a].$iterable}static get $exec(){const a=[];return a.$exec.bind(a)}static get $registerOperator(){return register_1.RegisterUtil.registerOperators}static get $argv(){return process.argv.slice(3)}static get $stdin(){return process.stdin.$iterable}static get $env(){return new Proxy({},{get(a,b){var c,d;return d=(c=process.env[b],null!==c&&void 0!==c?c:process.env[b.toUpperCase()]),null!==d&&void 0!==d?d:process.env[b.toLowerCase()]}})}static get $pattern(){return{URL:/https?:\/\/[\/A-Za-z0-9:=?\-&.%]+/g,EMAIL:/[A-Za-z0-9_]+@[A-Za-z0-9_.]+[.][A-Za-z]+/g,PROPER_NAME:/\b[A-Z][a-z]+\b/g}}static async*$range(a,b=1,c=1){if(0<c&&a<b){const c=b;b=a,a=c}for(let d=b;d<=a;d+=c)yield d}}exports.GlobalHelpers=GlobalHelpers; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const register_1=require("./util/register");class GlobalHelpers{static $of(a){var b,c;return c=null===(b=a)||void 0===b?void 0:b.$iterable,null!==c&&void 0!==c?c:[a].$iterable}static get $exec(){return[].$exec.bind([])}static get $registerOperator(){return register_1.RegisterUtil.registerOperators}static get $argv(){return process.argv.slice(3)}static get $stdin(){return process.stdin.$iterable}static get $env(){return new Proxy({},{get(a,b){var c,d;return d=(c=process.env[b],null!==c&&void 0!==c?c:process.env[b.toUpperCase()]),null!==d&&void 0!==d?d:process.env[b.toLowerCase()]}})}static get $pattern(){return{URL:/https?:\/\/[\/A-Za-z0-9:=?\-&.%]+/g,EMAIL:/[A-Za-z0-9_]+@[A-Za-z0-9_.]+[.][A-Za-z]+/g,PROPER_NAME:/\b[A-Z][a-z]+\b/g}}static async*$range(a,b=1,c=1){if(0<c&&a<b){const c=b;b=a,a=c}for(let d=b;d<=a;d+=c)yield d}}exports.GlobalHelpers=GlobalHelpers; |
@@ -30,6 +30,6 @@ import { $AsyncIterable, ExecConfig, CompletableStream } from '../types'; | ||
*/ | ||
$exec(cmd: string, config?: string[] | Omit<ExecConfig, 'mode'>): $AsyncIterable<string>; | ||
$exec(cmd: string, config: ExecConfig<'text'>): $AsyncIterable<string>; | ||
$exec(cmd: string, config: ExecConfig<'binary'>): $AsyncIterable<Buffer>; | ||
$exec(cmd: string, config: ExecConfig<'raw'>): $AsyncIterable<CompletableStream>; | ||
$exec<T>(this: AsyncIterable<T> | void, cmd: string, config?: string[] | Omit<ExecConfig, 'mode'>): $AsyncIterable<string>; | ||
$exec<T>(this: AsyncIterable<T> | void, cmd: string, config: ExecConfig<'text'>): $AsyncIterable<string>; | ||
$exec<T>(this: AsyncIterable<T> | void, cmd: string, config: ExecConfig<'binary'>): $AsyncIterable<Buffer>; | ||
$exec<T>(this: AsyncIterable<T> | void, cmd: string, config: ExecConfig<'raw'>): $AsyncIterable<CompletableStream>; | ||
} |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const stream_1=require("../util/stream"),exec_1=require("../util/exec"),async_1=require("../util/async");class ExecOperators{async*$exec(a,b={}){const c=Array.isArray(b)?{args:b}:b,{proc:d,result:e}=exec_1.ExecUtil.exec(a,c);if(stream_1.StreamUtil.toStream(this,c.input).pipe(d.stdin),"raw"===c.mode){const a=await stream_1.StreamUtil.readStream(d.stdout,c).$value;yield{...a,completed:async_1.AsyncUtil.combine(e,a.completed)}}else yield*stream_1.StreamUtil.readStream(d.stdout,c);await e}}exports.ExecOperators=ExecOperators; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const stream_1=require("../util/stream"),exec_1=require("../util/exec"),async_1=require("../util/async");class ExecOperators{async*$exec(a,b={}){const c=Array.isArray(b)?{args:b}:b,{proc:d,result:e}=exec_1.ExecUtil.exec(a,c);if(void 0!==this&&(stream_1.StreamUtil.toStream(this,c.input).pipe(d.stdin),d.stdin.on("error",a=>{if("code"in a&&"EPIPE"!==a.code)throw a})),"raw"===c.mode){const a=await stream_1.StreamUtil.readStream(d.stdout,c).$value;yield{...a,completed:async_1.AsyncUtil.combine(e,a.completed)}}else yield*stream_1.StreamUtil.readStream(d.stdout,c);await e}}exports.ExecOperators=ExecOperators; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const readline=require("readline"),fs=require("fs"),stream_1=require("stream"),async_1=require("./async"),text_1=require("./text");class MemoryStream extends stream_1.Writable{constructor(){super(...arguments),this.store=[]}_write(a,b,c){this.store.push(a),c()}getText(){return Buffer.concat(this.store).toString("utf8")}}class StreamUtil{static memoryWritable(){return new MemoryStream}static toStream(a,b){const c=stream_1.Readable.from(async function*(){for await(const c of a){if(c===void 0){yield;continue}c instanceof Buffer?b&&"binary"!==b?yield text_1.TextUtil.toLine(c):yield c:b&&"text"!==b?yield Buffer.from(text_1.TextUtil.toText(c),"utf8"):yield text_1.TextUtil.toLine(c)}}());return c}static async*readStream(a,b={}){var c;const d=(c=b.mode,null!==c&&void 0!==c?c:"text"),e="string"==typeof a?fs.createReadStream(a,{encoding:"text"===d?"utf8":void 0}):a,f=this.trackStream(e);if("raw"===d)return void(yield{stream:e,completed:f});const g="text"===d?readline.createInterface(e):e;let h,i=!1,j=[];const k=async a=>{var b;("string"==typeof a||a instanceof Buffer)&&j.push(a),null===(b=h)||void 0===b?void 0:b.resolve(null)};for(g.on("end",()=>k(i=!0)),g.on("close",()=>k(i=!0)),"text"===d?g.on("line",a=>k(text_1.TextUtil.toText(a))):g.on("data",a=>k("string"==typeof a?Buffer.from(a,"utf8"):a));!i;)await(h=async_1.AsyncUtil.resolvablePromise()),!b.singleValue&&j.length&&(yield*j,j=[]);b.singleValue&&(j="text"===d?[j.join("\n")]:[Buffer.concat(j)]),j.length&&(yield*j),e.destroyed||e.destroy(),await f}static trackStream(a,b=!0){const c=new Promise((b,c)=>{a.on("finish",b),a.on("end",b),a.on("close",b),a.on("error",c)});return b?async_1.AsyncUtil.trackWithTimer(c):c}static getWritable(a){return"string"!=typeof a&&"write"in a?a:fs.createWriteStream(a,{flags:"w",autoClose:!0})}}exports.StreamUtil=StreamUtil; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const readline=require("readline"),fs=require("fs"),stream_1=require("stream"),async_1=require("./async"),text_1=require("./text");class MemoryStream extends stream_1.Writable{constructor(){super(...arguments),this.store=[]}_write(a,b,c){this.store.push(a),c()}getText(){return Buffer.concat(this.store).toString("utf8")}}class StreamUtil{static memoryWritable(){return new MemoryStream}static toStream(a,b){const c=stream_1.Readable.from(async function*(){for await(const c of a){if(c===void 0){yield;continue}c instanceof Buffer?b&&"binary"!==b?yield text_1.TextUtil.toLine(c):yield c:b&&"text"!==b?yield Buffer.from(text_1.TextUtil.toText(c),"utf8"):yield text_1.TextUtil.toLine(c)}}());return c}static async*readStream(a,b={}){var c;const d=(c=b.mode,null!==c&&void 0!==c?c:"text"),e="string"==typeof a?fs.createReadStream(a,{encoding:"text"===d?"utf8":void 0}):a,f=this.trackStream(e);if("raw"===d)return void(yield{stream:e,completed:f});const g="text"===d?readline.createInterface(e):e;let h,i=!1,j=[];const k=async a=>{var b;("string"==typeof a||a instanceof Buffer)&&j.push(a),null===(b=h)||void 0===b?void 0:b.resolve(null)};for(g.on("end",()=>k(i=!0)),g.on("close",()=>k(i=!0)),g.on("error",a=>h.reject(a)),"text"===d?g.on("line",a=>k(text_1.TextUtil.toText(a))):g.on("data",a=>k("string"==typeof a?Buffer.from(a,"utf8"):a));!i;)await(h=async_1.AsyncUtil.resolvablePromise()),!b.singleValue&&j.length&&(yield*j,j=[]);b.singleValue&&(j="text"===d?[j.join("\n")]:[Buffer.concat(j)]),j.length&&(yield*j),e.destroyed||e.destroy(),await f}static trackStream(a,b=!0){const c=new Promise((b,c)=>{a.on("finish",b),a.on("end",b),a.on("close",b),a.on("error",c)});return b?async_1.AsyncUtil.trackWithTimer(c):c}static getWritable(a){return"string"!=typeof a&&"write"in a?a:fs.createWriteStream(a,{flags:"w",autoClose:!0})}}exports.StreamUtil=StreamUtil; |
{ | ||
"name": "@arcsine/nodesh", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"description": "A node-based library, providing Unix shell-like functionality", | ||
"scripts": { | ||
"clean": "rm -rf dist/", | ||
"docs": "./bin/nodesh ./scripts/docs-to-markdown", | ||
"docs": "./bin/nodesh ./scripts/docs/generate", | ||
"minify": "./bin/nodesh ./scripts/minify", | ||
@@ -15,2 +15,3 @@ "build": "npx tsc", | ||
}, | ||
"homepage": "https://arciisine.github.io/nodesh", | ||
"bin": "./bin/nodesh", | ||
@@ -44,2 +45,3 @@ "types": "./dist/index.d.ts", | ||
"eslint": "^6.8.0", | ||
"highlightjs": "^9.16.2", | ||
"typescript": "^3.7.4" | ||
@@ -46,0 +48,0 @@ }, |
@@ -96,4 +96,2 @@ <h1> | ||
const lineGenerator = fs.createReadStream('data.txt').$map(x => ...); | ||
``` | ||
@@ -135,3 +133,3 @@ | ||
#### $of | ||
#### $of | ||
@@ -161,3 +159,2 @@ Will turn any value into a sequence. If the input value is of type: | ||
.$map(x => x ** 2) | ||
``` | ||
@@ -170,3 +167,3 @@ | ||
```typescript | ||
static get $exec(): AsyncIterable<any>['$exec']; | ||
static get $exec(): string['$exec']; | ||
``` | ||
@@ -178,3 +175,2 @@ Example | ||
.$console | ||
``` | ||
@@ -208,3 +204,2 @@ | ||
.$stdout; | ||
``` | ||
@@ -228,6 +223,5 @@ | ||
```javascript | ||
(argv[0] ?? 'Enter a file name:'.$prompt()) | ||
($argv[0] ?? 'Enter a file name:'.$prompt()) | ||
// Pull in name from argv[0] or prompt if missing | ||
.$read() // Read file | ||
``` | ||
@@ -247,3 +241,2 @@ | ||
.$stdout // Pipe to stdout | ||
``` | ||
@@ -263,3 +256,2 @@ | ||
.$map(userName => ... ) | ||
``` | ||
@@ -272,4 +264,3 @@ | ||
```typescript | ||
static get $pattern(): { | ||
URL: RegExp;EMAIL: RegExp;PROPER_NAME: RegExp;}; | ||
static get $pattern(): Record<'URL' | 'EMAIL' | 'PROPER_NAME', RegExp>; | ||
``` | ||
@@ -282,6 +273,5 @@ Example | ||
.$filter(url => url.endsWith('.com')) | ||
``` | ||
#### $range | ||
#### $range | ||
@@ -302,3 +292,2 @@ Produces a numeric range, between start (1 by default) and stop (inclusive). A step | ||
// sequence of 1, 3, 5, 7, 9 | ||
``` | ||
@@ -338,3 +327,2 @@ | ||
.$forEach(console.log) // Will output each line | ||
``` | ||
@@ -355,3 +343,2 @@ | ||
// is now a sequence of all uppercase lines | ||
``` | ||
@@ -372,3 +359,2 @@ | ||
// Will retain all lines that are more than 10 characters | ||
``` | ||
@@ -389,3 +375,2 @@ | ||
.$flatten() // Now a string sequence for each word in the file | ||
``` | ||
@@ -406,3 +391,2 @@ | ||
.$flatMap(line => line.split(/\s+/g)) // Now a word sequence for the file | ||
``` | ||
@@ -428,3 +412,2 @@ | ||
}, {}); // Produces a map of words and their respective frequencies within the document | ||
``` | ||
@@ -445,3 +428,2 @@ | ||
// Produces a single string of the whole file | ||
``` | ||
@@ -470,3 +452,2 @@ | ||
.$wrap(translate.bind(null, 'fr')); // Produces a sequence of french-translated word | ||
``` | ||
@@ -486,3 +467,2 @@ | ||
.$onError(() => `Sample Text`) | ||
``` | ||
@@ -520,3 +500,2 @@ | ||
.$readLines({ number:false }) // Read as a series of lines, without numbering | ||
``` | ||
@@ -528,3 +507,2 @@ | ||
.$filter(line => line.number === 5) // Read only 5th line | ||
``` | ||
@@ -536,3 +514,2 @@ | ||
.$readLines() // Read as a series of lines, with filename, line number prepended | ||
``` | ||
@@ -562,3 +539,2 @@ | ||
}, 0); // Count number of bytes in file | ||
``` | ||
@@ -570,3 +546,2 @@ | ||
.$map(buffer => buffer.length) // Count number of bytes in file | ||
``` | ||
@@ -598,3 +573,2 @@ | ||
}); | ||
``` | ||
@@ -622,3 +596,2 @@ | ||
.$notEmpty() // Return all non-empty lines of the file | ||
``` | ||
@@ -640,3 +613,2 @@ | ||
// Stream unchanged, but was able to track file stat information | ||
``` | ||
@@ -658,3 +630,2 @@ | ||
// The final 1 repeats as it's not duplicated in sequence | ||
``` | ||
@@ -674,3 +645,2 @@ | ||
.$unique({ count: true }) // Will produce [[1, 1], [2, 3], [3, 1], [4, 1], [5, 2]] | ||
``` | ||
@@ -682,3 +652,2 @@ | ||
// Will produce [0, 1, 3, 2] as it captures the first even or odd of a run | ||
``` | ||
@@ -700,3 +669,2 @@ | ||
// Now a sequence of sorted lines | ||
``` | ||
@@ -719,3 +687,2 @@ | ||
// Generator of sorted list strings | ||
``` | ||
@@ -746,3 +713,2 @@ | ||
// Generator of file lines with, file name attached | ||
``` | ||
@@ -763,3 +729,2 @@ | ||
// Produces a sequence of lines inter-spliced with new lines | ||
``` | ||
@@ -781,3 +746,2 @@ | ||
.$stdout; // Displays 30 | ||
``` | ||
@@ -811,3 +775,2 @@ | ||
// Now an array of tuples (as defined by tabs in the tsv) | ||
``` | ||
@@ -830,3 +793,2 @@ | ||
// Now an array of objects { Name: string, Age: string, Major: string } (as defined by tabs in the tsv) | ||
``` | ||
@@ -846,3 +808,2 @@ | ||
.$tokens(/\b[A-Za-z]{6,100}\b/i) // Extract 6+ letter words | ||
``` | ||
@@ -854,3 +815,2 @@ | ||
.$tokens($pattern.URL) // Extract all URLs | ||
``` | ||
@@ -876,3 +836,2 @@ | ||
// All lines with TODO in them | ||
``` | ||
@@ -885,3 +844,2 @@ | ||
// Exclude all lines that include FIXME or TODO | ||
``` | ||
@@ -894,3 +852,2 @@ | ||
// Match all lines with phone numbers | ||
``` | ||
@@ -908,7 +865,6 @@ | ||
```javascript | ||
'<file>' | ||
'<file>' | ||
.$read() | ||
.$replace(/TODO/, 'FIXME') | ||
// All occurrences replaced | ||
``` | ||
@@ -926,3 +882,3 @@ | ||
```javascript | ||
'<file>.html' | ||
'<file>.html' | ||
.$read() | ||
@@ -935,3 +891,2 @@ .$replace({ | ||
// Html special chars escaped | ||
``` | ||
@@ -952,3 +907,2 @@ | ||
// Cleans leading/trailing whitespace per line | ||
``` | ||
@@ -971,3 +925,2 @@ | ||
.$replace(/<[^>]+?>/) // Remove all HTML tags | ||
``` | ||
@@ -993,3 +946,2 @@ | ||
.$first(10) // Read first 10 lines | ||
``` | ||
@@ -1001,3 +953,2 @@ | ||
.$first() // Read first line | ||
``` | ||
@@ -1017,3 +968,2 @@ | ||
.$skip(1) // Skip header | ||
``` | ||
@@ -1035,3 +985,2 @@ | ||
.$last(7) // Read last 7 lines of file | ||
``` | ||
@@ -1043,3 +992,2 @@ | ||
.$last() // Read last line of file | ||
``` | ||
@@ -1059,3 +1007,2 @@ | ||
.$first(10) // Read first 10 lines | ||
``` | ||
@@ -1077,6 +1024,6 @@ | ||
```typescript | ||
$exec(cmd: string, config?: string[] | Omit<ExecConfig, 'mode'>): $AsyncIterable<string>; | ||
$exec(cmd: string, config: ExecConfig<'text'>): $AsyncIterable<string>; | ||
$exec(cmd: string, config: ExecConfig<'binary'>): $AsyncIterable<Buffer>; | ||
$exec(cmd: string, config: ExecConfig<'raw'>): $AsyncIterable<CompletableStream>; | ||
$exec<T>(this: AsyncIterable<T> | void, cmd: string, config?: string[] | Omit<ExecConfig, 'mode'>): $AsyncIterable<string>; | ||
$exec<T>(this: AsyncIterable<T> | void, cmd: string, config: ExecConfig<'text'>): $AsyncIterable<string>; | ||
$exec<T>(this: AsyncIterable<T> | void, cmd: string, config: ExecConfig<'binary'>): $AsyncIterable<Buffer>; | ||
$exec<T>(this: AsyncIterable<T> | void, cmd: string, config: ExecConfig<'raw'>): $AsyncIterable<CompletableStream>; | ||
``` | ||
@@ -1090,3 +1037,2 @@ Example | ||
// Run in a single operation | ||
``` | ||
@@ -1105,3 +1051,2 @@ | ||
// Run in a single operation | ||
``` | ||
@@ -1137,3 +1082,2 @@ | ||
stream.pipe(fs.createWriteStream('out.png')); // Write out | ||
``` | ||
@@ -1156,3 +1100,2 @@ | ||
.$write('out.png') // Write file out | ||
``` | ||
@@ -1175,3 +1118,2 @@ | ||
.$writeFinal('<file>'); | ||
``` | ||
@@ -1196,3 +1138,2 @@ | ||
.$values // Get all values; | ||
``` | ||
@@ -1212,3 +1153,2 @@ | ||
.$value // Get single value | ||
``` | ||
@@ -1231,3 +1171,2 @@ | ||
.$stdout // Pipe to stdout | ||
``` | ||
@@ -1249,3 +1188,2 @@ | ||
.$console // Log out objects | ||
``` | ||
@@ -1278,3 +1216,2 @@ | ||
.$console | ||
``` | ||
@@ -1286,4 +1223,3 @@ | ||
.$console | ||
``` | ||
@@ -96,4 +96,2 @@ <h1> | ||
const lineGenerator = fs.createReadStream('data.txt').$map(x => ...); | ||
``` | ||
@@ -100,0 +98,0 @@ |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
115788
17
10
1330
1159