Skip to content

Commit 1bbdb40

Browse files
committed
Update docs
1 parent e15e60a commit 1bbdb40

File tree

5 files changed

+102
-72
lines changed

5 files changed

+102
-72
lines changed

app/docs/animations-authoring.recho.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
* = Animations Authoring =
99
* ============================================================================
1010
*
11-
* Animations are very powerful tools making your notebooks more interactive
12-
* and engaging. In Recho, there are at least two ways to author animations.
11+
* Animations are very powerful tools making your notebooks more interactive
12+
* and engaging. In Recho, there are at least two ways to author animations.
1313
* You can choose either one which suits you best.
1414
*
1515
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -69,11 +69,11 @@ const rocket = recho.interval(2);
6969
//➜ 🚀💨
7070
{
7171
const x = (count) => 40 - (count % 40);
72-
echo("🐌💨".padStart(x(snail)), {quote: false});
73-
echo("🐢💨".padStart(x(turtle)), {quote: false});
74-
echo("🚶‍♂️💨".padStart(x(human)), {quote: false});
75-
echo("🚗💨".padStart(x(car)), {quote: false});
76-
echo("🚀💨".padStart(x(rocket)), {quote: false});
72+
echo("🐌💨".padStart(x(snail)));
73+
echo("🐢💨".padStart(x(turtle)));
74+
echo("🚶‍♂️💨".padStart(x(human)));
75+
echo("🚗💨".padStart(x(car)));
76+
echo("🚀💨".padStart(x(rocket)));
7777
}
7878

7979
/**
@@ -94,7 +94,7 @@ echo(now);
9494
const x = echo(Math.abs(~~(Math.sin(now / 1000) * 22)));
9595

9696
//➜ ~(๑•̀ㅂ•́)و✧
97-
echo("~".repeat(x) + "(๑•̀ㅂ•́)و✧", {quote: false});
97+
echo(recho.inspect("~".repeat(x) + "(๑•̀ㅂ•́)و✧", {quote: false}));
9898

9999
/**
100100
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

app/docs/api-reference.recho.js

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,51 @@
1313

1414
/**
1515
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16-
* echo(value[, options])
16+
* echo(...values)
1717
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1818
*
19-
* Echos a value inline with your code as comments.
19+
* Echos one or more values inline with your code as comments. If only one
20+
* value is provided, return the value itself. If multiple values are provided,
21+
* return all the values as an array.
2022
*
21-
* @param {any} value - The value to echo.
22-
* @param {Object} [options] - The options to format the output.
23-
* @param {string} [options.quote="double"] - The quote style of the output.
24-
* @param {number} [options.indent=null] - The indentation of the output.
25-
* @param {number} [options.limit=200] - The limit of the output.
26-
* @returns {any} The value.
23+
* @param {...any} values - The values to echo.
24+
* @returns {any} The values if multiple values are provided, or the single value.
2725
*/
2826

2927
//➜ "Hello, World!"
3028
echo("Hello, World!");
3129

32-
//➜ 'Hello, World!'
33-
echo("Hello, World!", {quote: "single"});
30+
//➜ 1 2 3
31+
echo(1, 2, 3);
32+
33+
//➜ Peter: Age = 20
34+
//➜ Height = 180
35+
echo("Peter: ", "Age = 20\nHeight = 180");
36+
37+
const a = echo(1 + 2);
3438

35-
//➜ Hello, World!
36-
echo("Hello, World!", {quote: false});
39+
//➜ 3
40+
echo(a);
3741

38-
//➜ {
39-
//➜ a: 1,
40-
//➜ b: 2
41-
//➜ }
42-
echo({a: 1, b: 2}, {indent: 2});
42+
const numbers = echo(1, 2, 3);
4343

44-
//➜ [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
45-
echo(new Array(100).fill(0), {limit: 80});
44+
//➜ [ 1, 2, 3 ]
45+
echo(numbers);
46+
47+
/**
48+
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49+
* recho.inspect(value[, options])
50+
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51+
*
52+
* Formats a value for inspection with customizable options.
53+
*
54+
* @param {any} value - The value to inspect.
55+
* @param {Object} [options] - The options to format the output.
56+
* @param {string} [options.quote="double"] - The quote style of the output ("single", "double", or false).
57+
* @param {number} [options.indent=null] - The indentation of the output (null, "\t", or a positive integer).
58+
* @param {number} [options.limit=200] - The character limit of the output.
59+
* @returns {string} The formatted string representation of the value.
60+
*/
4661

4762
/**
4863
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -138,7 +153,7 @@ const Noise = recho.require("perlin-noise-3d");
138153
for (let i = 0; i < 100; i++) {
139154
values.push(noise.get(i / 100, i / 100, i / 100));
140155
}
141-
echo(values, {limit: 80});
156+
echo(recho.inspect(values, {limit: 80}));
142157
}
143158

144159
const d3 = recho.require("d3-array", "d3-random");
@@ -166,8 +181,8 @@ const isVisible = recho.toggle(false);
166181
//➜ "The button is enabled."
167182
//➜ "The button is hidden."
168183
{
169-
echo(`The button is ${isEnabled ? 'enabled' : 'disabled'}.`);
170-
echo(`The button is ${isVisible ? 'visible' : 'hidden'}.`);
184+
echo(`The button is ${isEnabled ? "enabled" : "disabled"}.`);
185+
echo(`The button is ${isVisible ? "visible" : "hidden"}.`);
171186
}
172187

173188
/**
@@ -246,6 +261,6 @@ const temperature = recho.number(24, {min: -10, max: 40, step: 0.5});
246261

247262
//➜ "The room temperature is 24 °C (75.2 °F)."
248263
{
249-
const fahrenheit = (temperature * 9 / 5) + 32;
264+
const fahrenheit = (temperature * 9) / 5 + 32;
250265
echo(`The room temperature is ${temperature} °C (${fahrenheit} °F).`);
251266
}

app/docs/inline-echoing.recho.js

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const message = echo("Hello, World!");
2626

2727
/**
2828
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29-
* Instant Feedback
29+
* Instant Feedback
3030
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3131
*
3232
* `echo` allows you to quickly get feedback about the states of your code. You
@@ -147,23 +147,61 @@ const customDate = echo(new Date().toLocaleString());
147147

148148
/**
149149
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
150-
* Formatting Outputs
150+
* Echoing Multiple Values
151+
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
152+
*
153+
* You can pass multiple values to `echo` in a single call. The values will be
154+
* merged horizontally.
155+
*/
156+
157+
//➜ 1 2 3
158+
echo(1, 2, 3);
159+
160+
//➜ Hello World
161+
echo("Hello", "World");
162+
163+
//➜ Peter: Age = 20
164+
//➜ Height = 180
165+
echo("Peter: ", "Age = 20\nHeight = 180");
166+
167+
/**
168+
* You can also call `echo` multiple times to echo multiple values in ForStatement,
169+
* BlockStatement, and more. The values will be joined by a newline.
170+
*/
171+
172+
//➜ 0
173+
//➜ 1
174+
//➜ 2
175+
for (let i = 0; i < 3; i++) echo(i);
176+
177+
//➜ 1
178+
//➜ 2
179+
//➜ 3
180+
{
181+
echo(1);
182+
echo(2);
183+
echo(3);
184+
}
185+
186+
/**
151187
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
152-
* `echo` provides `options` to format the output. For example, you can format
153-
* the quote style of a string value using the `quote` option:
188+
* Inspecting Options
189+
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190+
* You can use `recho.inspect()` with options to format the output. For example,
191+
* you can format the quote style of a string value using the `quote` option:
154192
*/
155193

156194
//➜ "Hello, World!"
157195
const defaultQuotedString = echo("Hello, World!");
158196

159197
//➜ 'Hello, World!'
160-
const singleQuotedString = echo("Hello, World!", {quote: "single"});
198+
const singleQuotedString = echo(recho.inspect("Hello, World!", {quote: "single"}));
161199

162200
//➜ "Hello, World!"
163-
const doubleQuotedString = echo("Hello, World!", {quote: "double"});
201+
const doubleQuotedString = echo(recho.inspect("Hello, World!", {quote: "double"}));
164202

165203
//➜ Hello, World!
166-
const unquotedString = echo("Hello, World!", {quote: false});
204+
const unquotedString = echo(recho.inspect("Hello, World!", {quote: false}));
167205

168206
/**
169207
* You can also format the indentation of the output using the `indent` option.
@@ -176,38 +214,15 @@ const unquotedString = echo("Hello, World!", {quote: false});
176214
//➜ b: 2,
177215
//➜ c: 3
178216
//➜ }
179-
const indentedObject = echo({a: 1, b: 2, c: 3}, {indent: 2});
217+
const indentedObject = echo(recho.inspect({a: 1, b: 2, c: 3}, {indent: 2}));
180218

181219
/**
182220
* You can also limit the length of the output using the `limit` option. It
183221
* must be a positive integer, Infinity, defaults to 200.
184222
*/
185223

186224
//➜ [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
187-
const array1000 = echo(new Array(1000).fill(0), {limit: 80});
188-
189-
/**
190-
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
191-
* Echoing Multiple Values
192-
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
193-
*
194-
* You can call `echo` multiple times to echo multiple values in ForStatement,
195-
* BlockStatement, and more. The values will be joined by a newline.
196-
*/
197-
198-
//➜ 0
199-
//➜ 1
200-
//➜ 2
201-
for (let i = 0; i < 3; i++) echo(i);
202-
203-
//➜ 1
204-
//➜ 2
205-
//➜ 3
206-
{
207-
echo(1);
208-
echo(2);
209-
echo(3);
210-
}
225+
const array1000 = echo(recho.inspect(new Array(1000).fill(0), {limit: 80}));
211226

212227
/**
213228
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

app/examples/pokemon.recho.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ const search = null;
5555
//➜
5656
//➜
5757
{
58-
echo(`⚡ Type: ${pokemon.types[0].type.name.toUpperCase()}`, {quote: false});
59-
echo(`⚖️ Weight: ${pokemon.weight}`, {quote: false});
60-
echo(`📏 Height: ${pokemon.height}`, {quote: false});
61-
echo("", {quote: false});
58+
echo(recho.inspect(`⚡ Type: ${pokemon.types[0].type.name.toUpperCase()}`, {quote: false}));
59+
echo(recho.inspect(`⚖️ Weight: ${pokemon.weight}`, {quote: false}));
60+
echo(recho.inspect(`📏 Height: ${pokemon.height}`, {quote: false}));
61+
echo(recho.inspect("", {quote: false}));
6262
img2ASCIIString(pokemon.sprites.front_default).then(echo);
6363
}
6464

app/examples/running-race.recho.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ const rocket = recho.interval(2);
3030
//➜ 🚀💨
3131
{
3232
const x = (count) => 40 - (count % 40);
33-
echo("🐌💨".padStart(x(snail)), {quote: false});
34-
echo("🐢💨".padStart(x(turtle)), {quote: false});
35-
echo("🚶‍♂️💨".padStart(x(human)), {quote: false});
36-
echo("🚗💨".padStart(x(car)), {quote: false});
37-
echo("🚀💨".padStart(x(rocket)), {quote: false});
33+
echo("🐌💨".padStart(x(snail)));
34+
echo("🐢💨".padStart(x(turtle)));
35+
echo("🚶‍♂️💨".padStart(x(human)));
36+
echo("🚗💨".padStart(x(car)));
37+
echo("🚀💨".padStart(x(rocket)));
3838
}

0 commit comments

Comments
 (0)