Skip to content

Commit e9c4d9d

Browse files
authored
v0.9.2 (#24)
1 parent a4fcc63 commit e9c4d9d

File tree

75 files changed

+623
-1211
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+623
-1211
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ curl https://api.spacexdata.com/v4/launches/latest | nodejsscript -p 'Object.ent
3939
## Goods
4040
[s #shelljs](./docs/modules/s.md)
4141
· [$](./docs/modules/.md) ([$.api() #sade](./docs/modules/.md#api), [$.read()](./docs/modules/.md#read), [$.xdg](./docs/modules/xdg_.xdg.md), …)
42-
· [echo()](./docs/README.md#echo)
42+
· [echo() #css-in-console](./docs/README.md#echo)
4343
· [fetch() #node-fetch](./docs/README.md#fetch)
4444
· [pipe()](./docs/README.md#pipe)
4545
· [cyclicLoop()](./docs/README.md#cyclicloop)
@@ -136,6 +136,12 @@ Keep in mind that you can always turn off this for next command by using:
136136
s.$("-g").rm("*.txt");
137137
```
138138
139+
## Helper(s) for developing
140+
You can create `jsconfig.json` to help your editor provide proper suggestions.
141+
As editor you can use VSCode or Vim with for example [neoclide/coc.nvim](https://github.com/neoclide/coc.nvim).
142+
NodeJSScript provides `nodejsscript --global-jsconfig add script_file` to
143+
help generate `jsconfig.json`.
144+
139145
## Migration from `zx`
140146
The `runA` is almost identical to `$`:
141147
```js

_index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @category Public */
2-
export { echo, EchoFunction, css_rules, css_colors } from './src/echo.d';
2+
export { echo, EchoFunction } from './src/echo.d';
33
export { xdg_, __sade, _env, _exit } from './src/$.d';
44
/**
55
* Contains configuration for current script and methods

bin/cli.mjs

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { stdin as key_stdin } from "../src/keys.js";
88

99
process.on('uncaughtException', printError);
1010
(async function main(){
11-
const candidate= argv.splice(2, 1)[0];
11+
const candidate= argv.splice(2, 1)[0] || "--help";
1212
let filepath_tmp;
1313
if(candidate[0]==="-")
1414
filepath_tmp= handleMyArgvs(candidate);
@@ -58,15 +58,15 @@ function printError(e){
5858
}
5959
function printUsage(){
6060
const [ n, v, d ]= info("name", "version", "description");
61-
const css= echo.css(
62-
"* { margin-left: 2; }",
63-
".n { color: lightblue; }",
64-
".v { color: lightgreen; margin-left: 0; }",
65-
".code { font-style: italic; margin-left: 0; }",
66-
".H { color: yellow; }",
67-
".T { margin-left: 4; }"
68-
);
69-
echo(`%c${n}@%c${v}`, css.n, css.v);
61+
const css= echo.css`
62+
* { margin-left: 2; }
63+
.n { color: lightblue; }
64+
.v { color: lightgreen; margin-left: 0; }
65+
.code { font-style: italic; margin-left: 0; }
66+
.H { color: yellow; }
67+
.T { margin-left: 4; }
68+
`;
69+
echo("%c%s%c@%c%s", css.n, css.unset, css.v, n, v);
7070
echo(`%c${d}`, css.T);
7171
echo(`%cUsage%c:`, css.H);
7272
echo(`%c${n} [options] <script>`, css.T);
@@ -83,6 +83,7 @@ function printUsage(){
8383
echo(`%cls | ${n} -p '$.stdin.lines().filter(line=> line[0]==="R").map(line=> \`file: \${line}\`)'`, css.T);
8484
echo("%cUsage in scripts%c:", css.H);
8585
echo("%cJust start the file with: %c#!/usr/bin/env nodejsscript", css.T, css.code);
86+
echo("%c…and make the script file executable.", css.T);
8687
$.exit(0);
8788
}
8889
function info(...keys){
@@ -108,13 +109,30 @@ function jsconfigTypes(){
108109
$.exit(0);
109110
}
110111
function runEval(is_print){
111-
let input= argv.splice(2, 1)[0];
112+
let input= argv.splice(2, 1)[0] ?? "";
112113
if(is_print){
113-
let out_arr= input.split(";").reverse();
114+
const m= "--§--"+randomUUID().replaceAll("-", "")+"--§--";
115+
const store_quotes= [];
116+
input= input.replace(/(['"`])(?:(?!\1)[^\\]|\\[\s\S])*\1/g,
117+
//temporary remove quotes (can contain ';')
118+
f=> (store_quotes.push(f), m));
119+
const m_regexp= new RegExp(m, "g");
120+
let out_arr= input.split(";")
121+
.map(/* return quotes */ v=> v.replace(m_regexp, ()=> store_quotes.shift()))
122+
.reverse();
114123
if(out_arr[0].trim()==="") out_arr.shift();
115-
out_arr[0]= `echo(${out_arr[0]})`;
124+
let pre= "";
125+
let out= out_arr[0]?.trim();
126+
if(out && out[0]==="}"){// "function …{ …; }" ⇒ [ " }".trim(), "function …{ …" ]
127+
pre= "}";
128+
out= out.slice(1).trim();
129+
}
130+
const input_rest= argv.slice(2).join(",");
131+
if(input_rest.trim()!=="") out= `pipe(${input_rest})(${out})`;
132+
out_arr[0]= `${pre} echo(${out})`;
116133
input= out_arr.reverse().join(";");
117134
}
135+
input+= ";$.exit(0);";
118136
const filepath= $.xdg.temp`nodejsscript-${randomUUID()}.mjs`;
119137
s.echo(input).to(filepath);
120138
return filepath;

docs/README.md

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ nodejsscript
2020

2121
- [EchoFunction](interfaces/EchoFunction.md)
2222

23-
### Type Aliases
24-
25-
- [css\_rules](README.md#css_rules)
26-
- [css\_colors](README.md#css_colors)
27-
2823
### Public Namespaces
2924

3025
- [$](modules/.md)
@@ -44,7 +39,7 @@ nodejsscript
4439

4540
### pipe
4641

47-
**pipe**(...`funs`): (`input`: `any`) => `any`
42+
**pipe**(`...funs`): (`input`: `any`) => `any`
4843

4944
Function similar to [Ramda `R.pipe`](https://ramdajs.com/docs/#pipe). Provides functional way to combine commands/functions.
5045

@@ -168,11 +163,11 @@ ___
168163

169164
### echo
170165

171-
**echo**(`message?`, ...`optionalParams`): [`ShellString`](modules/s.md#shellstring)
166+
**echo**(`message?`, `...optionalParams`): [`ShellString`](modules/s.md#shellstring)
172167

173168
This is mixed function between bash’s `echo` and `console.log`.
174169
By default, works more like `console.log` with partial supports
175-
for styling mimic CSS and `console.log` in the web browser. See [css](interfaces/EchoFunction.md#css).
170+
for styling mimic CSS and `console.log` in the web browser. See [`echo.css`](interfaces/EchoFunction.md#type-declaration) (internally uses [css-in-console - npm](https://www.npmjs.com/package/css-in-console)).
176171

177172
The [use](interfaces/EchoFunction.md#use) provides more `echo` way,
178173
the first argument accepts options string starting with `-`:
@@ -322,27 +317,6 @@ v0.1.13
322317

323318
`never`
324319

325-
## Type Aliases
326-
327-
### css\_rules
328-
329-
Ƭ **css\_rules**: ``"unset: all;"`` \| ``"display: none;"`` \| \`color: ${css\_colors};\` \| \`background: ${css\_colors};\` \| \`margin-left: ${number};\` \| ``"font-style: italic;"`` \| ``"font-weight: bold;"`` \| \`text-decoration: ${"underline" \| "line-through"}\` \| ``"animation: blink;"``
330-
331-
- `color: COLOR` – see [css_colors](README.md#css_colors)
332-
- `background: COLOR` – see [css_colors](README.md#css_colors)
333-
- `margin-left: NUMBER` – counts spaces before string
334-
- `font-style: italic`
335-
- `font-weight: bold`
336-
- `text-decoration: underline|line-through`
337-
- `animation:blink`
338-
- TODO: `…:before { content: "…" }`, `tab-size`
339-
340-
___
341-
342-
### css\_colors
343-
344-
Ƭ **css\_colors**: ``"black"`` \| ``"red"`` \| ``"green"`` \| ``"yellow"`` \| ``"blue"`` \| ``"magenta"`` \| ``"cyan"`` \| ``"white"`` \| ``"gray"`` \| ``"lightred"`` \| ``"lightgreen"`` \| ``"lightyellow"`` \| ``"lightblue"`` \| ``"lightmagenta"`` \| ``"lightcyan"`` \| ``"whitesmoke"``
345-
346320
## Properties
347321

348322
### \_env

docs/classes/fetch.Response.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616

1717
- [error](fetch.Response.md#error)
1818
- [redirect](fetch.Response.md#redirect)
19+
- [json](fetch.Response.md#json)
1920
- [clone](fetch.Response.md#clone)
2021
- [buffer](fetch.Response.md#buffer)
2122
- [arrayBuffer](fetch.Response.md#arraybuffer)
2223
- [formData](fetch.Response.md#formdata)
2324
- [blob](fetch.Response.md#blob)
24-
- [json](fetch.Response.md#json)
25+
- [json](fetch.Response.md#json-1)
2526
- [text](fetch.Response.md#text)
2627

2728
### Constructors
@@ -70,6 +71,23 @@ ___
7071

7172
___
7273

74+
### json
75+
76+
`Static` **json**(`data`, `init?`): [`Response`](fetch.Response.md)
77+
78+
#### Parameters
79+
80+
| Name | Type |
81+
| :------ | :------ |
82+
| `data` | `any` |
83+
| `init?` | [`ResponseInit`](../interfaces/fetch.ResponseInit.md) |
84+
85+
#### Returns
86+
87+
[`Response`](fetch.Response.md)
88+
89+
___
90+
7391
### clone
7492

7593
**clone**(): [`Response`](fetch.Response.md)

docs/classes/s.ProcessPromise.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,33 @@ A resolved promise.
206206

207207
Promise.resolve
208208

209-
`Static` **resolve**<`T`\>(`value`): `Promise`<`T`\>
209+
`Static` **resolve**<`T`\>(`value`): `Promise`<`Awaited`<`T`\>\>
210+
211+
Creates a new resolved promise for the provided value.
212+
213+
#### Type parameters
214+
215+
| Name |
216+
| :------ |
217+
| `T` |
218+
219+
#### Parameters
220+
221+
| Name | Type | Description |
222+
| :------ | :------ | :------ |
223+
| `value` | `T` | A promise. |
224+
225+
#### Returns
226+
227+
`Promise`<`Awaited`<`T`\>\>
228+
229+
A promise whose internal state matches the provided promise.
230+
231+
#### Inherited from
232+
233+
Promise.resolve
234+
235+
`Static` **resolve**<`T`\>(`value`): `Promise`<`Awaited`<`T`\>\>
210236

211237
Creates a new resolved promise for the provided value.
212238

@@ -224,7 +250,7 @@ Creates a new resolved promise for the provided value.
224250

225251
#### Returns
226252

227-
`Promise`<`T`\>
253+
`Promise`<`Awaited`<`T`\>\>
228254

229255
A promise whose internal state matches the provided promise.
230256

@@ -459,7 +485,7 @@ Creates a new Promise.
459485

460486
| Name | Type | Description |
461487
| :------ | :------ | :------ |
462-
| `executor` | (`resolve`: (`value`: [`ProcessOutput`](s.ProcessOutput.md) \| `PromiseLike`<[`ProcessOutput`](s.ProcessOutput.md)\>) => `void`, `reject`: (`reason?`: `any`) => `void`) => `void` | A callback used to initialize the promise. This callback is passed two arguments: a resolve callback used to resolve the promise with a value or the result of another promise, and a reject callback used to reject the promise with a provided reason or error. |
488+
| `executor` | (`resolve`: (`value`: [`ProcessOutput`](s.ProcessOutput.md) \| `PromiseLike`<[`ProcessOutput`](s.ProcessOutput.md)\>) => `void`, `reject`: (`reason?`: `any`) => `void`) => `void` | A callback used to initialize the promise. This callback is passed two arguments: a resolve callback used to resolve the promise with a value or the result of another promise, and a reject callback used to reject the promise with a provided reason or error. |
463489

464490
#### Inherited from
465491

docs/classes/s.child.ChildProcess.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ v11.13.0, v10.16.0
171171

172172
| Name | Type |
173173
| :------ | :------ |
174-
| `emitter` | `NodeEventTarget` |
174+
| `emitter` | `_NodeEventTarget` |
175175
| `eventName` | `string` \| `symbol` |
176176
| `options?` | `StaticEventEmitterOptions` |
177177

@@ -189,7 +189,7 @@ EventEmitter.once
189189

190190
| Name | Type |
191191
| :------ | :------ |
192-
| `emitter` | `DOMEventTarget` |
192+
| `emitter` | `_DOMEventTarget` |
193193
| `eventName` | `string` |
194194
| `options?` | `StaticEventEmitterOptions` |
195195

@@ -362,7 +362,7 @@ v15.2.0, v14.17.0
362362

363363
| Name | Type |
364364
| :------ | :------ |
365-
| `emitter` | `EventEmitter` \| `DOMEventTarget` |
365+
| `emitter` | `EventEmitter` \| `_DOMEventTarget` |
366366
| `name` | `string` \| `symbol` |
367367

368368
#### Returns
@@ -377,7 +377,7 @@ ___
377377

378378
### setMaxListeners
379379

380-
`Static` **setMaxListeners**(`n?`, ...`eventTargets`): `void`
380+
`Static` **setMaxListeners**(`n?`, `...eventTargets`): `void`
381381

382382
```js
383383
const {
@@ -400,7 +400,7 @@ v15.4.0
400400
| Name | Type | Description |
401401
| :------ | :------ | :------ |
402402
| `n?` | `number` | A non-negative number. The maximum number of listeners per `EventTarget` event. |
403-
| `...eventTargets` | (`EventEmitter` \| `DOMEventTarget`)[] | - |
403+
| `...eventTargets` | (`EventEmitter` \| `_DOMEventTarget`)[] | - |
404404

405405
#### Returns
406406

@@ -907,7 +907,7 @@ ___
907907

908908
### emit
909909

910-
**emit**(`event`, ...`args`): `boolean`
910+
**emit**(`event`, `...args`): `boolean`
911911

912912
#### Parameters
913913

0 commit comments

Comments
 (0)