Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@stdlib/math-base-tools-evalpoly

Package Overview
Dependencies
Maintainers
4
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stdlib/math-base-tools-evalpoly - npm Package Compare versions

Comparing version
0.0.2
to
0.0.3
+5
CHANGELOG.md
# CHANGELOG
> Package changelog.
See [GitHub Releases](https://github.com/stdlib-js/math-base-tools-evalpoly/releases) for the changelog.
<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="45.115ex" height="6.843ex" style="vertical-align: -3.005ex;" viewBox="0 -1652.5 19424.6 2946.1" role="img" focusable="false" xmlns="http://www.w3.org/2000/svg" aria-labelledby="MathJax-SVG-1-Title">
<title id="MathJax-SVG-1-Title">c Subscript n Baseline x Superscript n Baseline plus c Subscript n minus 1 Baseline x Superscript n minus 1 Baseline plus ellipsis plus c 1 x Superscript 1 Baseline plus c 0 equals sigma-summation Underscript i equals 0 Overscript n Endscripts c Subscript i Baseline x Superscript i</title>
<defs aria-hidden="true">
<path stroke-width="1" id="E1-MJMATHI-63" d="M34 159Q34 268 120 355T306 442Q362 442 394 418T427 355Q427 326 408 306T360 285Q341 285 330 295T319 325T330 359T352 380T366 386H367Q367 388 361 392T340 400T306 404Q276 404 249 390Q228 381 206 359Q162 315 142 235T121 119Q121 73 147 50Q169 26 205 26H209Q321 26 394 111Q403 121 406 121Q410 121 419 112T429 98T420 83T391 55T346 25T282 0T202 -11Q127 -11 81 37T34 159Z"></path>
<path stroke-width="1" id="E1-MJMATHI-6E" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path>
<path stroke-width="1" id="E1-MJMATHI-78" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path>
<path stroke-width="1" id="E1-MJMAIN-2B" d="M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z"></path>
<path stroke-width="1" id="E1-MJMAIN-2212" d="M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z"></path>
<path stroke-width="1" id="E1-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path>
<path stroke-width="1" id="E1-MJMAIN-2026" d="M78 60Q78 84 95 102T138 120Q162 120 180 104T199 61Q199 36 182 18T139 0T96 17T78 60ZM525 60Q525 84 542 102T585 120Q609 120 627 104T646 61Q646 36 629 18T586 0T543 17T525 60ZM972 60Q972 84 989 102T1032 120Q1056 120 1074 104T1093 61Q1093 36 1076 18T1033 0T990 17T972 60Z"></path>
<path stroke-width="1" id="E1-MJMAIN-30" d="M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z"></path>
<path stroke-width="1" id="E1-MJMAIN-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path>
<path stroke-width="1" id="E1-MJSZ2-2211" d="M60 948Q63 950 665 950H1267L1325 815Q1384 677 1388 669H1348L1341 683Q1320 724 1285 761Q1235 809 1174 838T1033 881T882 898T699 902H574H543H251L259 891Q722 258 724 252Q725 250 724 246Q721 243 460 -56L196 -356Q196 -357 407 -357Q459 -357 548 -357T676 -358Q812 -358 896 -353T1063 -332T1204 -283T1307 -196Q1328 -170 1348 -124H1388Q1388 -125 1381 -145T1356 -210T1325 -294L1267 -449L666 -450Q64 -450 61 -448Q55 -446 55 -439Q55 -437 57 -433L590 177Q590 178 557 222T452 366T322 544L56 909L55 924Q55 945 60 948Z"></path>
<path stroke-width="1" id="E1-MJMATHI-69" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z"></path>
</defs>
<g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)" aria-hidden="true">
<use xlink:href="#E1-MJMATHI-63" x="0" y="0"></use>
<use transform="scale(0.707)" xlink:href="#E1-MJMATHI-6E" x="613" y="-213"></use>
<g transform="translate(958,0)">
<use xlink:href="#E1-MJMATHI-78" x="0" y="0"></use>
<use transform="scale(0.707)" xlink:href="#E1-MJMATHI-6E" x="809" y="583"></use>
</g>
<use xlink:href="#E1-MJMAIN-2B" x="2277" y="0"></use>
<g transform="translate(3278,0)">
<use xlink:href="#E1-MJMATHI-63" x="0" y="0"></use>
<g transform="translate(433,-150)">
<use transform="scale(0.707)" xlink:href="#E1-MJMATHI-6E" x="0" y="0"></use>
<use transform="scale(0.707)" xlink:href="#E1-MJMAIN-2212" x="600" y="0"></use>
<use transform="scale(0.707)" xlink:href="#E1-MJMAIN-31" x="1379" y="0"></use>
</g>
</g>
<g transform="translate(5140,0)">
<use xlink:href="#E1-MJMATHI-78" x="0" y="0"></use>
<g transform="translate(572,412)">
<use transform="scale(0.707)" xlink:href="#E1-MJMATHI-6E" x="0" y="0"></use>
<use transform="scale(0.707)" xlink:href="#E1-MJMAIN-2212" x="600" y="0"></use>
<use transform="scale(0.707)" xlink:href="#E1-MJMAIN-31" x="1379" y="0"></use>
</g>
</g>
<use xlink:href="#E1-MJMAIN-2B" x="7364" y="0"></use>
<use xlink:href="#E1-MJMAIN-2026" x="8365" y="0"></use>
<use xlink:href="#E1-MJMAIN-2B" x="9759" y="0"></use>
<g transform="translate(10760,0)">
<use xlink:href="#E1-MJMATHI-63" x="0" y="0"></use>
<use transform="scale(0.707)" xlink:href="#E1-MJMAIN-31" x="613" y="-213"></use>
</g>
<g transform="translate(11647,0)">
<use xlink:href="#E1-MJMATHI-78" x="0" y="0"></use>
<use transform="scale(0.707)" xlink:href="#E1-MJMAIN-31" x="809" y="583"></use>
</g>
<use xlink:href="#E1-MJMAIN-2B" x="12896" y="0"></use>
<g transform="translate(13897,0)">
<use xlink:href="#E1-MJMATHI-63" x="0" y="0"></use>
<use transform="scale(0.707)" xlink:href="#E1-MJMAIN-30" x="613" y="-213"></use>
</g>
<use xlink:href="#E1-MJMAIN-3D" x="15062" y="0"></use>
<g transform="translate(16118,0)">
<use xlink:href="#E1-MJSZ2-2211" x="0" y="0"></use>
<g transform="translate(147,-1090)">
<use transform="scale(0.707)" xlink:href="#E1-MJMATHI-69" x="0" y="0"></use>
<use transform="scale(0.707)" xlink:href="#E1-MJMAIN-3D" x="345" y="0"></use>
<use transform="scale(0.707)" xlink:href="#E1-MJMAIN-30" x="1124" y="0"></use>
</g>
<use transform="scale(0.707)" xlink:href="#E1-MJMATHI-6E" x="721" y="1627"></use>
</g>
<g transform="translate(17729,0)">
<use xlink:href="#E1-MJMATHI-63" x="0" y="0"></use>
<use transform="scale(0.707)" xlink:href="#E1-MJMATHI-69" x="613" y="-213"></use>
</g>
<g transform="translate(18507,0)">
<use xlink:href="#E1-MJMATHI-78" x="0" y="0"></use>
<use transform="scale(0.707)" xlink:href="#E1-MJMATHI-69" x="809" y="583"></use>
</g>
</g>
</svg>
{{alias}}( c, x )
Evaluates a polynomial.
Parameters
----------
c: Array<number>
Polynomial coefficients sorted in ascending degree.
x: number
Value at which to evaluate the polynomial.
Returns
-------
out: number
Evaluated polynomial.
Examples
--------
> var arr = [ 3.0, 2.0, 1.0 ];
// 3*10^0 + 2*10^1 + 1*10^2
> var v = {{alias}}( arr, 10.0 )
123.0
{{alias}}.factory( c )
Returns a function for evaluating a polynomial.
Parameters
----------
c: Array<number>
Polynomial coefficients sorted in ascending degree.
Returns
-------
fcn: Function
Function for evaluating a polynomial.
Examples
--------
> var polyval = {{alias}}.factory( [ 3.0, 2.0, 1.0 ] );
// 3*10^0 + 2*10^1 + 1*10^2
> var v = polyval( 10.0 )
123.0
// 3*5^0 + 2*5^1 + 1*5^2
> v = polyval( 5.0 )
38.0
See Also
--------
/*
* @license Apache-2.0
*
* Copyright (c) 2021 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// TypeScript Version: 2.0
/**
* Evaluates a polynomial.
*
* @param x - value at which to evaluate a polynomial
* @returns evaluated polynomial
*/
type EvaluationFunction = ( x: number ) => number;
/**
* Interface for evaluating polynomials.
*/
interface EvalPoly {
/**
* Evaluates a polynomial.
*
* ## Notes
*
* - The implementation uses [Horner's rule][horners-method] for efficient computation.
*
* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method
*
*
* @param c - polynomial coefficients sorted in ascending degree
* @param x - value at which to evaluate the polynomial
* @returns evaluated polynomial
*
* @example
* var v = evalpoly( [3.0,2.0,1.0], 10.0 ); // 3*10^0 + 2*10^1 + 1*10^2
* // returns 123.0
*/
( c: Array<number>, x: number ): number;
/**
* Generates a function for evaluating a polynomial.
*
* ## Notes
*
* - The compiled function uses [Horner's rule][horners-method] for efficient computation.
*
* [horners-method]: http://en.wikipedia.org/wiki/Horner%27s_method
*
*
* @param c - polynomial coefficients sorted in ascending degree
* @returns function for evaluating a polynomial
*
* @example
* var polyval = evalpoly.factory( [3.0,2.0,1.0] );
*
* var v = polyval( 10.0 ); // => 3*10^0 + 2*10^1 + 1*10^2
* // returns 123.0
*
* v = polyval( 5.0 ); // => 3*5^0 + 2*5^1 + 1*5^2
* // returns 38.0
*/
factory( c: Array<number> ): EvaluationFunction;
}
/**
* Evaluates a polynomial.
*
* ## Notes
*
* - The implementation uses [Horner's rule][horners-method] for efficient computation.
*
* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method
*
*
* @param c - polynomial coefficients sorted in ascending degree
* @param x - value at which to evaluate the polynomial
* @returns evaluated polynomial
*
* @example
* var v = evalpoly( [3.0,2.0,1.0], 10.0 ); // 3*10^0 + 2*10^1 + 1*10^2
* // returns 123.0
*
* @example
* var polyval = evalpoly.factory( [3.0,2.0,1.0] );
*
* var v = polyval( 10.0 ); // => 3*10^0 + 2*10^1 + 1*10^2
* // returns 123.0
*
* v = polyval( 5.0 ); // => 3*5^0 + 2*5^1 + 1*5^2
* // returns 38.0
*/
declare var evalpoly: EvalPoly;
// EXPORTS //
export = evalpoly;
/*
* @license Apache-2.0
*
* Copyright (c) 2021 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import evalpoly = require( './index' );
// TESTS //
// The function returns a number...
{
evalpoly( [ 3.0, 2.0, 1.0 ], 10.0 ); // $ExpectType number
}
// The function does not compile if provided a first argument which is not an array of numbers...
{
evalpoly( true, 10.0 ); // $ExpectError
evalpoly( false, 10.0 ); // $ExpectError
evalpoly( 'abc', 10.0 ); // $ExpectError
evalpoly( 123, 10.0 ); // $ExpectError
evalpoly( {}, 10.0 ); // $ExpectError
evalpoly( ( x: number ): number => x, 10.0 ); // $ExpectError
}
// The function does not compile if provided a second argument which is not a number...
{
const c = [ 3.0, 2.0, 1.0 ];
evalpoly( c, true ); // $ExpectError
evalpoly( c, false ); // $ExpectError
evalpoly( c, 'abc' ); // $ExpectError
evalpoly( c, [] ); // $ExpectError
evalpoly( c, {} ); // $ExpectError
evalpoly( c, ( x: number ): number => x ); // $ExpectError
}
// The compiler throws an error if the function is provided an insufficient number of arguments...
{
const c = [ 3.0, 2.0, 1.0 ];
evalpoly(); // $ExpectError
evalpoly( c ); // $ExpectError
}
// Attached to main export is a `factory` method which returns a function...
{
const c = [ 3.0, 2.0, 1.0 ];
evalpoly.factory( c ); // $ExpectType EvaluationFunction
}
// The compiler throws an error if the `factory` method is provided an unsupported number of arguments...
{
const c = [ 3.0, 2.0, 1.0 ];
evalpoly.factory(); // $ExpectError
evalpoly.factory( c, 2.0 ); // $ExpectError
}
// The `factory` method returns a function which returns a number...
{
const c = [ 3.0, 2.0, 1.0 ];
const polyval = evalpoly.factory( c );
polyval( 1.0 ); // $ExpectType number
}
// The `factory` method returns a function which does not compile if provided a first argument which is not a number...
{
const c = [ 3.0, 2.0, 1.0 ];
const polyval = evalpoly.factory( c );
polyval( true ); // $ExpectError
polyval( false ); // $ExpectError
polyval( 'abc' ); // $ExpectError
polyval( [] ); // $ExpectError
polyval( {} ); // $ExpectError
polyval( ( x: number ): number => x ); // $ExpectError
}
// The compiler throws an error if the `factory` method is provided a first argument which is not an array of numbers...
{
evalpoly.factory( true ); // $ExpectError
evalpoly.factory( false ); // $ExpectError
evalpoly.factory( 'abc' ); // $ExpectError
evalpoly.factory( 123 ); // $ExpectError
evalpoly.factory( {} ); // $ExpectError
evalpoly.factory( ( x: number ): number => x ); // $ExpectError
}
+1
-1

@@ -24,3 +24,3 @@ /**

*
* @module @stdlib/math/base/tools/evalpoly
* @module @stdlib/math-base-tools-evalpoly
*

@@ -27,0 +27,0 @@ * @example

{
"name": "@stdlib/math-base-tools-evalpoly",
"version": "0.0.2",
"version": "0.0.3",
"description": "Evaluate a polynomial.",

@@ -5,0 +5,0 @@ "license": "Apache-2.0",

#/
# @license Apache-2.0
#
# Copyright (c) 2021 The Stdlib Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#/
# USER VARIABLES #
ifndef VERBOSE
QUIET := @
else
QUIET :=
endif
# Indicate whether to "fast" fail when linting, running tests, etc:
ifndef FAST_FAIL
FAIL_FAST := true
else
ifeq ($(FAST_FAIL), 0)
FAIL_FAST := false
else
FAIL_FAST := true
endif
endif
# Define the `NODE_PATH` environment variable:
NODE_PATH ?=
# Define the `NODE_ENV` environment variable:
NODE_ENV ?=
# INTERNAL VARIABLES #
# Instruct make to warn us when we use an undefined variable (e.g., misspellings).
MAKEFLAGS += --warn-undefined-variables
# Define the default target:
.DEFAULT_GOAL := all
# Define the `SHELL` variable to avoid issues on systems where the variable may be inherited from the environment.
#
# ## Notes
#
# - We use `bash` so that we can use `pipefail`.
#
#
# [1]: https://www.gnu.org/prep/standards/html_node/Makefile-Basics.html#Makefile-Basics
# [2]: http://clarkgrubb.com/makefile-style-guide
SHELL := bash
# Define shell flags.
#
# ## Notes
#
# - `.SHELLFLAGS` was introduced in GNU Make 3.82 and has no effect on the version of GNU Make installed on Mac OS X, which is 3.81.
# - The `-e` flag causes `bash` to exit immediately if a `bash` executed command fails.
# - The `-u` flag causes `bash` to exit with an error message if a variable is accessed without being defined.
# - The `pipefail` option specifies that, if any of the commands in a pipeline fail, the entire pipeline fails. Otherwise the return value of a pipeline is the return value of the last command.
# - The `-c` flag is in the default value of `.SHELLFLAGS`, which must be preserved, as this is how `make` passes the script to be executed to `bash`.
#
.SHELLFLAGS := -eu -o pipefail -c
# Remove targets if its recipe fails.
#
# ## Notes
#
# - Mentioning this target anywhere in a Makefile prevents a user from re-running make and using an incomplete or invalid target.
# - When debugging, it may be necessary to comment this line out so the incomplete or invalid target can be inspected.
#
# [1]: https://www.gnu.org/software/make/manual/html_node/Special-Targets.html
.DELETE_ON_ERROR:
# Remove all the default suffixes, preferring to define all rules explicitly.
#
# [1]: https://www.gnu.org/software/make/manual/html_node/Suffix-Rules.html#Suffix-Rules
# [2]: https://www.gnu.org/software/make/manual/html_node/Suffix-Rules.html#Suffix-Rules
.SUFFIXES:
# Determine the OS ([1][1], [2][2]).
#
# [1]: https://en.wikipedia.org/wiki/Uname#Examples
# [2]: http://stackoverflow.com/a/27776822/2225624
OS ?= $(shell uname)
ifneq (, $(findstring MINGW,$(OS)))
OS := WINNT
else
ifneq (, $(findstring MSYS,$(OS)))
OS := WINNT
else
ifneq (, $(findstring CYGWIN,$(OS)))
OS := WINNT
else
ifneq (, $(findstring Windows_NT,$(OS)))
OS := WINNT
endif
endif
endif
endif
# Determine the filename:
this_file := $(lastword $(MAKEFILE_LIST))
# Determine the absolute path of the Makefile (see http://blog.jgc.org/2007/01/what-makefile-am-i-in.html):
this_dir := $(dir $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
# Remove the trailing slash:
this_dir := $(patsubst %/,%,$(this_dir))
# Determine root directory:
ROOT_DIR = $(this_dir)
# Define the root build directory:
BUILD_DIR ?= $(ROOT_DIR)/build
# Define the root directory for storing distributable files:
DIST_DIR ?= $(ROOT_DIR)/dist
# Define the root directory for storing temporary files:
TMP_DIR ?= $(ROOT_DIR)/tmp
# Define the directories for writing reports, including code coverage:
REPORTS_DIR ?= $(ROOT_DIR)/reports
COVERAGE_DIR ?= $(REPORTS_DIR)/coverage
# Define the top-level directory containing node module dependencies:
NODE_MODULES ?= $(ROOT_DIR)/node_modules
# Define the top-level directory containing node module executables:
BIN_DIR ?= $(NODE_MODULES)/.bin
# Define the path to the root `package.json`:
ROOT_PACKAGE_JSON ?= $(ROOT_DIR)/package.json
# Define the folder name convention for source files requiring compilation:
SRC_FOLDER ?= src
# Define the folder name convention for documentation files:
DOCUMENTATION_FOLDER ?= docs
# Define the folder name convention for configuration files:
CONFIG_FOLDER ?= etc
# Define the folder name convention for benchmark files:
BENCHMARKS_FOLDER ?= benchmark
# Define the folder name convention for benchmark fixtures:
BENCHMARKS_FIXTURES_FOLDER ?= $(BENCHMARKS_FOLDER)/fixtures
# Define the folder name convention for examples files:
EXAMPLES_FOLDER ?= examples
# Define the folder name convention for examples fixtures:
EXAMPLES_FIXTURES_FOLDER ?= $(EXAMPLES_FOLDER)/fixtures
# Define the folder name convention for test files:
TESTS_FOLDER ?= test
# Define the folder name convention for test fixtures:
TESTS_FIXTURES_FOLDER ?= $(TESTS_FOLDER)/fixtures
# Define a filepath pattern for benchmark files:
BENCHMARKS_FILTER ?= .*/.*
# Define a filepath pattern for example files:
EXAMPLES_FILTER ?= .*/.*
# Define a filepath pattern for test files:
TESTS_FILTER ?= .*/.*
# Define a filename pattern for benchmark files:
BENCHMARKS_PATTERN ?= benchmark*.js
# Define a filename pattern for example files:
EXAMPLES_PATTERN ?= *.js
# Define a filename pattern for test files:
TESTS_PATTERN ?= test*.js
# Define Node environments:
ifdef NODE_ENV
NODE_ENV_BENCHMARK := $(NODE_ENV)
NODE_ENV_EXAMPLES := $(NODE_ENV)
NODE_ENV_TEST := $(NODE_ENV)
else
NODE_ENV ?=
NODE_ENV_BENCHMARK ?= benchmark
NODE_ENV_EXAMPLES ?= examples
NODE_ENV_TEST ?= test
endif
# Define whether delete operations should be safe (i.e., deleted items are sent to trash, rather than permanently deleted):
SAFE_DELETE ?= false
# Define the delete command:
ifeq ($(SAFE_DELETE), true)
# FIXME: -rm -rf
DELETE := -rm
DELETE_FLAGS := -rf
else
DELETE ?= -rm
DELETE_FLAGS ?= -rf
endif
# Determine the `open` command:
ifeq ($(OS), Darwin)
OPEN ?= open
else
OPEN ?= xdg-open
endif
# TODO: add Windows command
# Define the command for `node`:
NODE ?= node
# Define the command for `npm`:
NPM ?= npm
# Define the path to a JavaScript test runner.
#
# ## Notes
#
# - We reference the `bin` file directly in order to support using `istanbul` for code coverage on Windows (https://github.com/gotwarlost/istanbul#usage-on-windows)
JAVASCRIPT_TEST ?= $(NODE_MODULES)/tape/bin/tape
# Define any command-line options to use when invoking the test runner:
JAVASCRIPT_TEST_FLAGS ?=
# Define the path to the executable for parsing TAP output:
TAP_REPORTER ?= $(BIN_DIR)/tap-spec
# Define the path to the Istanbul executable:
ISTANBUL ?= $(BIN_DIR)/istanbul
# Define which files and directories to exclude from coverage instrumentation:
ISTANBUL_EXCLUDES_FLAGS ?= \
--no-default-excludes \
-x 'node_modules/**' \
-x 'reports/**' \
-x 'tmp/**' \
-x 'deps/**' \
-x 'dist/**' \
-x "**/$(SRC_FOLDER)/**" \
-x "**/$(TESTS_FOLDER)/**" \
-x "**/$(EXAMPLES_FOLDER)/**" \
-x "**/$(BENCHMARKS_FOLDER)/**" \
-x "**/$(CONFIG_FOLDER)/**" \
-x "**/$(DOCUMENTATION_FOLDER)/**"
# Define the command to generate test coverage:
ISTANBUL_COVER ?= $(ISTANBUL) cover
# Define the type of report Istanbul should produce:
ISTANBUL_COVER_REPORT_FORMAT ?= lcov
# Define the command-line options to be used when generating code coverage:
ISTANBUL_COVER_FLAGS ?= \
$(ISTANBUL_EXCLUDES_FLAGS) \
--dir $(COVERAGE_DIR) \
--report $(ISTANBUL_COVER_REPORT_FORMAT)
# On Mac OSX, in order to use `|` and other regular expression operators, we need to use enhanced regular expression syntax (-E); see https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man7/re_format.7.html#//apple_ref/doc/man/7/re_format.
ifeq ($(OS), Darwin)
find_kernel_prefix := -E
else
find_kernel_prefix :=
endif
# Common exclude flags that most recipes for finding package files should use (Note: order does matter to some degree):
FIND_COMMON_EXCLUDE_FLAGS ?= \
-not -path "$(ROOT_DIR)/.*" \
-not -path "$(NODE_MODULES)/*" \
-not -path "$(BUILD_DIR)/*" \
-not -path "$(REPORTS_DIR)/*" \
# Define exclusion flags to use when searching for benchmark files:
FIND_BENCHMARKS_EXCLUDE_FLAGS ?= \
$(FIND_COMMON_EXCLUDE_FLAGS) \
-not -path "$(ROOT_DIR)/**/$(BENCHMARKS_FIXTURES_FOLDER)/*"
# Define flags for finding benchmark files:
FIND_BENCHMARKS_FLAGS ?= \
-type f \
-name "$(BENCHMARKS_PATTERN)" \
-path "$(ROOT_DIR)/**/$(BENCHMARKS_FOLDER)/**" \
-regex "$(BENCHMARKS_FILTER)" \
$(FIND_BENCHMARKS_EXCLUDE_FLAGS)
ifneq ($(OS), Darwin)
FIND_BENCHMARKS_FLAGS := -regextype posix-extended $(FIND_BENCHMARKS_FLAGS)
endif
# Define a command to list benchmark files:
FIND_BENCHMARKS_CMD ?= find $(find_kernel_prefix) $(ROOT_DIR) $(FIND_BENCHMARKS_FLAGS)
# Define exclusion flags to use when searching for examples files:
FIND_EXAMPLES_EXCLUDE_FLAGS ?= \
$(FIND_COMMON_EXCLUDE_FLAGS) \
-not -path "$(ROOT_DIR)/**/$(EXAMPLES_FIXTURES_FOLDER)/*"
# Define flags for finding examples files:
FIND_EXAMPLES_FLAGS ?= \
-type f \
-name "$(EXAMPLES_PATTERN)" \
-path "$(ROOT_DIR)/**/$(EXAMPLES_FOLDER)/**" \
-regex "$(EXAMPLES_FILTER)" \
$(FIND_EXAMPLES_EXCLUDE_FLAGS)
ifneq ($(OS), Darwin)
FIND_EXAMPLES_FLAGS := -regextype posix-extended $(FIND_EXAMPLES_FLAGS)
endif
# Define a command to list example files:
FIND_EXAMPLES_CMD ?= find $(find_kernel_prefix) $(ROOT_DIR) $(FIND_EXAMPLES_FLAGS)
# Define exclusion flags to use when searching for test files:
FIND_TESTS_EXCLUDE_FLAGS ?= \
$(FIND_COMMON_EXCLUDE_FLAGS) \
-not -path "$(ROOT_DIR)/**/$(TESTS_FIXTURES_FOLDER)/*"
# Define flags for finding test files:
FIND_TESTS_FLAGS ?= \
-type f \
-name "$(TESTS_PATTERN)" \
-regex "$(TESTS_FILTER)" \
$(FIND_TESTS_EXCLUDE_FLAGS)
ifneq ($(OS), Darwin)
FIND_TESTS_FLAGS := -regextype posix-extended $(FIND_TESTS_FLAGS)
endif
# Define a command to list test files:
FIND_TESTS_CMD ?= find $(find_kernel_prefix) $(ROOT_DIR) $(FIND_TESTS_FLAGS)
# RULES #
#/
# Default target.
#
# @example
# make
#
# @example
# make all
#/
all: help
.PHONY: all
#/
# Prints a `Makefile` help message.
#
# @example
# make help
#/
help:
$(QUIET) echo 'Read the Makefile to see the list of available commands.'
$(QUIET) echo ''
.PHONY: help
#/
# Prints the runtime value of a `Makefile` variable.
#
# ## Notes
#
# - The rule uses the following format:
#
# ```bash
# $ make inspect.<variable>
# ```
#
# @example
# make inspect.ROOT_DIR
#
# @example
# make inspect.CC
#/
inspect.%:
$(QUIET) echo '$*=$($*)'
#/
# Runs the project's install sequence.
#
# @example
# make install
#/
install:
$(NPM) install
.PHONY: install
#/
# Removes node module dependencies.
#
# @example
# make clean-node
#/
clean-node:
$(QUIET) $(DELETE) $(DELETE_FLAGS) $(NODE_MODULES)
#/
# Runs the project's cleanup sequence.
#
# @example
# make clean
#/
clean: clean-node clean-cov
$(QUIET) $(DELETE) $(DELETE_FLAGS) $(BUILD_DIR)
$(QUIET) $(DELETE) $(DELETE_FLAGS) $(REPORTS_DIR)
.PHONY: clean
#/
# Runs JavaScript benchmarks consecutively.
#
# ## Notes
#
# - The recipe assumes that benchmark files can be run via Node.js.
# - This rule is useful when wanting to glob for JavaScript benchmark files (e.g., run all JavaScript benchmarks for a particular package).
#
#
# @param {string} [BENCHMARKS_FILTER] - file path pattern (e.g., `.*/utils/group-by/.*`)
#
# @example
# make benchmark
#
# @example
# make benchmark BENCHMARKS_FILTER=".*/utils/group-by/.*"
#/
benchmark: $(NODE_MODULES)
$(QUIET) $(FIND_BENCHMARKS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ""; \
echo "Running benchmark: $$file"; \
NODE_ENV="$(NODE_ENV_BENCHMARK)" \
NODE_PATH="$(NODE_PATH)" \
$(NODE) $$file || exit 1; \
done
.PHONY: benchmark
#/
# Runs JavaScript examples consecutively.
#
# ## Notes
#
# - This rule is useful when wanting to glob for JavaScript examples files (e.g., run all JavaScript examples for a particular package).
# - This rule **assumes** that examples files can be run using Node.js.
#
#
# @param {string} [EXAMPLES_FILTER] - file path pattern (e.g., `.*/math/base/special/abs/.*`)
#
# @example
# make examples
#
# @example
# make examples EXAMPLES_FILTER=".*/strided/common/.*"
#/
examples: $(NODE_MODULES)
$(QUIET) $(FIND_EXAMPLES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ""; \
echo "Running example: $$file"; \
NODE_ENV="$(NODE_ENV_EXAMPLES)" \
NODE_PATH="$(NODE_PATH)" \
$(NODE) $$file || exit 1; \
done
.PHONY: examples
#/
# Runs JavaScript tests consecutively.
#
# ## Notes
#
# - This rule is useful when wanting to glob for JavaScript test files (e.g., run all JavaScript tests for a particular package).
# - This rule **assumes** that test files can be run using Node.js.
#
#
# @param {string} [TEST_FILTER] - file path pattern (e.g., `.*/math/base/special/abs/.*`)
#
# @example
# make test
#
# @example
# make test TESTS_FILTER=".*/strided/common/.*"
#/
test: $(NODE_MODULES)
$(QUIET) $(FIND_TESTS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r test; do \
echo ''; \
echo "Running test: $$test"; \
NODE_ENV="$(NODE_ENV_TEST)" \
NODE_PATH="$(NODE_PATH)" \
$(JAVASCRIPT_TEST) \
$(JAVASCRIPT_TEST_FLAGS) \
$$test \
| $(TAP_REPORTER) || exit 1; \
done
.PHONY: test
#/
# Runs unit tests and generate a test coverage report.
#
# @example
# make test-cov
#/
test-cov: clean-cov
$(QUIET) NODE_ENV="$(NODE_ENV_TEST)" \
NODE_PATH="$(NODE_PATH)" \
$(ISTANBUL_COVER) $(ISTANBUL_COVER_FLAGS) $(JAVASCRIPT_TEST) -- $$( $(FIND_TESTS_CMD) )
.PHONY: test-cov
#/
# Removes a test coverage directory.
#
# @example
# make clean-cov
#/
clean-cov:
$(QUIET) $(DELETE) $(DELETE_FLAGS) $(COVERAGE_DIR)