Skip to content

Commit 2c8491e

Browse files
committed
Add specific browser entry point and add method docs
1 parent ca1d577 commit 2c8491e

File tree

6 files changed

+85
-4
lines changed

6 files changed

+85
-4
lines changed

lib/node_modules/@stdlib/math/base/tools/evalpoly/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ v = polyval( 5.0 ); // => 3*5^0 + 2*5^1 + 1*5^2
5454
// returns 38.0
5555
```
5656

57+
#### evalpoly.compile( c )
58+
59+
Compiles a module `string` containing an exported function which evaluates a [polynomial][polynomial] having coefficients `c`.
60+
61+
```javascript
62+
var str = evalpoly.factory( [ 3.0, 2.0, 1.0 ] );
63+
// returns <string>
64+
```
65+
5766
</section>
5867

5968
<!-- /.usage -->
@@ -63,6 +72,7 @@ v = polyval( 5.0 ); // => 3*5^0 + 2*5^1 + 1*5^2
6372
## Notes
6473

6574
- For hot code paths in which coefficients are invariant, a compiled function will be more performant than `evalpoly()`.
75+
- The `compile` method is intended for **non-browser** environments for the purpose of generating module files. Depending on how this package is bundled for browser environments, the `compile` method may **not** be present.
6676

6777
</section>
6878

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
/**
4+
* Evaluate a polynomial.
5+
*
6+
* @module @stdlib/math/base/tools/evalpoly
7+
*
8+
* @example
9+
* var evalpoly = require( '@stdlib/math/base/tools/evalpoly' );
10+
*
11+
* var v = evalpoly( [3.0,2.0,1.0], 10.0 ); // 3*10^0 + 2*10^1 + 1*10^2
12+
* // returns 123.0
13+
*
14+
* @example
15+
* var evalpoly = require( '@stdlib/math/base/tools/evalpoly' );
16+
*
17+
* var polyval = evalpoly.factory( [3.0,2.0,1.0] );
18+
*
19+
* var v = polyval( 10.0 ); // => 3*10^0 + 2*10^1 + 1*10^2
20+
* // returns 123.0
21+
*
22+
* v = polyval( 5.0 ); // => 3*5^0 + 2*5^1 + 1*5^2
23+
* // returns 38.0
24+
*/
25+
26+
// MODULES //
27+
28+
var setReadOnly = require( '@stdlib/utils/define-read-only-property' );
29+
var evalpoly = require( './evalpoly.js' );
30+
var factory = require( './factory.js' );
31+
32+
33+
// MAIN //
34+
35+
setReadOnly( evalpoly, 'factory', factory );
36+
37+
38+
// EXPORTS //
39+
40+
module.exports = evalpoly;

lib/node_modules/@stdlib/math/base/tools/evalpoly/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
}
1515
],
1616
"main": "./lib",
17+
"browser": "./lib/browser.js",
1718
"directories": {
1819
"benchmark": "./benchmark",
1920
"doc": "./docs",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
// MODULES //
4+
5+
var tape = require( 'tape' );
6+
var evalpoly = require( './../lib/browser.js' );
7+
8+
9+
// TESTS //
10+
11+
tape( 'main export is a function', function test( t ) {
12+
t.ok( true, __filename );
13+
t.equal( typeof evalpoly, 'function', 'main export is a function' );
14+
t.end();
15+
});
16+
17+
tape( 'attached to the main export is a factory method for generating `evalpoly` functions', function test( t ) {
18+
t.equal( typeof evalpoly.factory, 'function', 'exports a factory method' );
19+
t.end();
20+
});

lib/node_modules/@stdlib/math/base/tools/evalpoly/test/test.compile.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,25 @@
33
// MODULES //
44

55
var join = require( 'path' ).join;
6+
var resolve = require( 'path' ).resolve;
67
var tape = require( 'tape' );
78
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
89
var readFile = require( '@stdlib/fs/read-file' ).sync;
910
var Float64Array = require( '@stdlib/array/float64' );
10-
var compile = require( './../lib/compile.js' );
11+
var tryRequire = require( '@stdlib/utils/try-require' );
1112

1213

1314
// VARIABLES //
1415

16+
var compile = tryRequire( resolve( __dirname, '..', 'lib', 'compile.js' ) );
1517
var opts = {
16-
'skip': IS_BROWSER
18+
'skip': ( IS_BROWSER || (compile instanceof Error) )
1719
};
1820

1921

2022
// TESTS //
2123

22-
tape( 'main export is a function', function test( t ) {
24+
tape( 'main export is a function', opts, function test( t ) {
2325
t.ok( true, __filename );
2426
t.equal( typeof compile, 'function', 'main export is a function' );
2527
t.end();

lib/node_modules/@stdlib/math/base/tools/evalpoly/test/test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@
33
// MODULES //
44

55
var tape = require( 'tape' );
6+
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
67
var evalpoly = require( './../lib' );
78

89

10+
// VARIABLES //
11+
12+
var opts = {
13+
'skip': IS_BROWSER
14+
};
15+
16+
917
// TESTS //
1018

1119
tape( 'main export is a function', function test( t ) {
@@ -19,7 +27,7 @@ tape( 'attached to the main export is a factory method for generating `evalpoly`
1927
t.end();
2028
});
2129

22-
tape( 'attached to the main export is a method for compiling `evalpoly` function modules', function test( t ) {
30+
tape( 'in non-browser environments, attached to the main export is a method for compiling `evalpoly` function modules', opts, function test( t ) {
2331
t.equal( typeof evalpoly.compile, 'function', 'exports a compile method' );
2432
t.end();
2533
});

0 commit comments

Comments
 (0)