Skip to content

Commit a7761d4

Browse files
committed
fix(docs): add docs for cjs and umd builds
1 parent 5a433bf commit a7761d4

File tree

2 files changed

+97
-24
lines changed

2 files changed

+97
-24
lines changed

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,36 @@ npm i mazes101 --save
1212

1313
## Usage
1414

15+
### For commonjs modules (nodejs)
16+
17+
```js
18+
let maze = require('mazes101');
19+
20+
// 1. create an empty board
21+
let {newBoard} = maze.Boards.rectangular;
22+
let board = newBoard({height: 20, width: 20});
23+
24+
// 2. generate maze in that board
25+
let {getRows, getNeighbours, removeInterWall} = maze.Boards.rectangular;
26+
let {generate} = maze.Generators.kruskal;
27+
board = generate(board, {getRows, getNextRowNeighbours, removeInterWall});
28+
29+
// 3. render the board
30+
let {render} = maze.Renderers.rectangularSvg;
31+
const svgString = render(board);
32+
```
33+
34+
### For ecmascript modules
35+
1536
```js
1637
// 1. create an empty board
1738
import {newBoard} from 'mazes101/boards/rectangular';
1839
let board = newBoard({height: 20, width: 20});
1940

2041
// 2. generate maze in that board
21-
import {getRows, getNextRowNeighbours, removeInterWall} from 'mazes101/boards/rectangular';
42+
import {getRows, getNeighbours, removeInterWall} from 'mazes101/boards/rectangular';
2243
import {generate} from 'mazes101/generators/eller';
23-
board = generate(board, {getRows, getNextRowNeighbours, removeInterWall});
44+
board = generate(board, {getRows, getNeighbours, removeInterWall});
2445

2546
// 3. render the board
2647
import {render} from 'mazes101/renderers/rectangularSvg';

docs/index.md

Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ The output bundle for basic rectangular maze is normally upto 3KBs.
2525

2626
### via CDN
2727

28-
```js
29-
import Maze from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/index.min.js';
28+
```html
29+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/index.umd.js"></script>
30+
<script>
31+
// here mazes101 is available in global scope
32+
</script>
3033
```
3134

32-
3335
## Usage
3436

3537
As mentioned early, these are just some set of utilizes which means that they can be hacked to do anything you like.
@@ -40,11 +42,34 @@ The typical flow of generating a maze looks something as following:
4042
First, chose a [Board Type](boards/index.md) you can create then create an empty board of that type. For example for a rectangular board
4143
you can import it from [`boards/rectangular`](boards/rectangular.md) and use it like:
4244

43-
```js linenums="1"
44-
import {newBoard} from 'mazes101/boards/rectangular';
45+
=== "EcmaScript"
46+
47+
```js linenums="1"
48+
import {newBoard} from 'mazes101/boards/rectangular';
49+
50+
let board = newBoard({height: 20, width: 20});
51+
```
52+
53+
=== "NodeJs"
54+
55+
```js linenums="1"
56+
import mazes101 from 'mazes101';
57+
let {newBoard} = mazes101.Boards.rectangular;
58+
let board = newBoard({height: 20, width: 20});
59+
```
60+
61+
=== "CDN"
62+
63+
```html
64+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/index.umd.js"></script>
65+
```
66+
67+
```js linenums="1"
68+
let {newBoard} = mazes101.Boards.rectangular;
69+
70+
let board = newBoard({height: 20, width: 20});
71+
```
4572

46-
let board = newBoard({height: 20, width: 20});
47-
```
4873

4974
Before generating a maze in this board, you can also do some preprocessing on this board, like
5075
disabling some cells etc.
@@ -55,18 +80,35 @@ Next, step could be to generate a maze in this board, for this you need a maze g
5580
some built-in [Generation Algorithms](generators/index.md) for example lets use
5681
[`generators/kruskal`](generators/kruskal.md):
5782

58-
```js linenums="4"
59-
import {generate} from 'mazes101/generators/kruskal';
60-
61-
// import required functions from the board you selected in step 1
62-
import {
63-
getRows,
64-
getNextRowNeighbours,
65-
removeInterWall
66-
} from 'mazes101/boards/rectangular';
83+
=== "EcmaScript"
84+
85+
```js linenums="4"
86+
import {generate} from 'mazes101/generators/kruskal';
87+
88+
// import required functions from the board you selected in step 1
89+
import {
90+
getRows,
91+
getNextRowNeighbours,
92+
removeInterWall
93+
} from 'mazes101/boards/rectangular';
94+
95+
board = generate(board, {getRows, getNextRowNeighbours, removeInterWall});
96+
```
6797

68-
board = generate(board, {getRows, getNextRowNeighbours, removeInterWall});
69-
```
98+
=== "NodeJs/CDN"
99+
100+
```js linenums="4"
101+
let {generate} = mazes101.Generators.kruskal;
102+
103+
// import required functions from the board you selected in step 1
104+
let {
105+
getRows,
106+
getNextRowNeighbours,
107+
removeInterWall
108+
} = mazes101.Boards.rectangular;
109+
110+
board = generate(board, {getRows, getNextRowNeighbours, removeInterWall});
111+
```
70112

71113
!!! note
72114
The `generate` method returns a new board instead of altering the provided board so, it is important to assign that
@@ -78,10 +120,20 @@ board = generate(board, {getRows, getNextRowNeighbours, removeInterWall});
78120
The last step would be to render the board, Mazes101 comes with some built-in [Renderers](renderers/index.md) too.
79121
For example, [`renderers/rectangularSvg`](renderers/rectangularSvg.md) this renderer renders rectangular boards to svg string.
80122

81-
```js linenums="14"
82-
import {render} from 'mazes101/renderers/rectangularSvg';
123+
=== "EcmaScript"
83124

84-
const svgString = render(board);
85-
```
125+
```js linenums="14"
126+
import {render} from 'mazes101/renderers/rectangularSvg';
127+
128+
const svgString = render(board);
129+
```
130+
131+
=== "NodeJs/CDN"
132+
133+
```js linenums="14"
134+
let {render} = mazes101.Renderers.rectangularSvg;
135+
136+
const svgString = render(board);
137+
```
86138

87139
Now, you can either render this svg string to DOM, save it to a file or send it to client via http.

0 commit comments

Comments
 (0)