Skip to content

Commit 0d7e90d

Browse files
committed
Makes module/packet structure more compatible
1 parent 8386fa1 commit 0d7e90d

16 files changed

+1837
-54
lines changed

.eslintrc.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,8 @@ module.exports = {
3636
'error',
3737
'always'
3838
]
39-
}
39+
},
40+
'ignorePatterns': [
41+
'/dist'
42+
]
4043
};

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/node_modules
22
/.parcel-cache
33
/dist
4+
/e2e
5+
/public

README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@ simplex-noise.js is a fast simplex noise implementation in Javascript. It works
99
- [3D voxel world generation](http://29a.ch/sandbox/2012/voxelworld/) example.
1010
- Film grain in [analog film emulator](http://29a.ch/film-emulator/).
1111

12+
Created something awesome with simplex-noise? Let me know so I can add it to the list.
13+
1214
## Installation
1315

1416
```npm i -S simplex-noise```
1517

1618
## Usage
1719

20+
```javascript
21+
// when using es modules
22+
import SimplexNoise from 'simplex-noise';
23+
// when using commonjs
24+
const {SimplexNoise} = require('simplex-noise');
25+
```
26+
1827
By default simplex-noise.js will use Math.random() to seed the noise.
1928
```javascript
2029
// initializing a new simplex instance
@@ -61,12 +70,18 @@ const SimplexNoise = require('simplex-noise'),
6170

6271
## Benchmarks
6372

64-
- [Comparison between 2D and 3D noise](http://jsperf.com/simplex-noise/4)
65-
- [Comparison with simplex implementation in three.js](http://jsperf.com/simplex-noise-comparison/3)
73+
simplex-noise.js is reasonably quick.
74+
According to `perf/benchmark.js` I can perform about 50 million `noise2D()` calls/second on a single thread on my desktop (Ryzen 5950X).
75+
So ~20 nanoseconds per call.
6676

67-
For development you can open `perf/index.html` and watch the console or run `node perf/benchmark.js` in a shell.
68-
There is also a rake task for comparing your current changes can also run `make compare`.
69-
The command works using git stash.
77+
```
78+
$ node perf/index.js
79+
27745787.933336906
80+
init: 192,590 ops/sec ±1%
81+
noise2D: 57,928,891 ops/sec ±1%
82+
noise3D: 34,159,230 ops/sec ±0%
83+
noise4D: 24,589,786 ops/sec ±0%
84+
```
7085

7186
## Tests
7287

@@ -77,7 +92,8 @@ npm install && npm test
7792

7893
## Changelog
7994

80-
### main
95+
### 3.0.0
96+
- Changed module structure. When using bundlers that import the es module even using require() the import might need to be updated.
8197
- Dependency update
8298
- Setting sideEffects: false in package.json
8399
- Added snapshot tests

build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
mkdir -p dist
3+
tsc --build tsconfig-commonjs.json
4+
tsc --build tsconfig-esm.json
5+
echo '{"type": "module"}' > dist/esm/package.json

commonjs-wrapper.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import SimplexNoise from './simplex-noise.js';
2+
// dumb hack so there is a consistent way to import using commonjs
3+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4+
(SimplexNoise as any)['SimplexNoise'] = SimplexNoise;
5+
export = SimplexNoise;

0 commit comments

Comments
 (0)