diff --git a/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/README.md b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/README.md new file mode 100644 index 000000000000..584830b47cd7 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/README.md @@ -0,0 +1,206 @@ + + +# Figure Element + +> Generate an HTML string for displaying an SVG figure as an image in a GitHub Markdown file. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var createElement = require( '@stdlib/_tools/markdown/img-svg-figure' ); +``` + +#### createElement( \[options] ) + +Generates an HTML `string` for displaying an SVG figure as an image in a GitHub Markdown file. + +```javascript +var html = createElement(); +// returns '
\n \n
\n
' +``` + +The function accepts the following `options`: + +- **className**: element class name. Default: `'figure'`. +- **align**: element alignment. Default: `'center'`. +- **label**: figure label. +- **src**: image source URL. +- **alt**: alternative image text. + +Each `option` corresponds an HTML attribute. For example, to set the image source URL, set the `src` option. + +```javascript +var opts = { + 'src': 'https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@master/docs/img/fig1.svg' +}; + +var html = createElement( opts ); +// returns '
\n \n
\n
' +``` + +To include a figure label in the element, set the `label` option. + +```javascript +var opts = { + 'label': 'fig:fig1', + 'src': 'https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@master/docs/img/fig1.svg' +}; + +var html = createElement( opts ); +// returns '
\n \n
\n
' +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var createElement = require( '@stdlib/_tools/markdown/img-svg-figure' ); + +var opts = { + 'className': 'fig', + 'align': 'center', + 'label': 'fig:padding', + 'src': 'https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@master/lib/node_modules/@stdlib/plot/vega/padding/ctor/docs/img/figure_padding.svg', + 'alt': 'A visualization showing padding margins.' +}; + +var html = createElement( opts ); + +console.log( html ); +// => '
\n A visualization showing padding margins.\n
\n
' +``` + +
+ + + +* * * + +
+ +## CLI + + + +
+ +### Usage + +```text +Usage: ghimgfig [options] + +Options: + + -h, --help Print this message. + -V, --version Print the package version. + --class name Element class name. Default: figure. + --align alignment Element alignment. Default: center. + --label label Figure label. + --src url Image source URL. + --alt text Alternative image text. +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```bash +$ ghimgfig --label 'fig:fig1' --src 'https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@master/docs/img/fig1.svg' +
+ +
+
+``` + +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/bin/cli b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/bin/cli new file mode 100755 index 000000000000..8a55636b8bf8 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/bin/cli @@ -0,0 +1,78 @@ +#!/usr/bin/env node + +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +'use strict'; + +// MODULES // + +var join = require( 'path' ).join; +var readFileSync = require( '@stdlib/fs/read-file' ).sync; +var CLI = require( '@stdlib/cli/ctor' ); +var createElement = require( './../lib' ); + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var flags; + var opts; + var cli; + + // Create a command-line interface: + cli = new CLI({ + 'pkg': require( './../package.json' ), + 'options': require( './../etc/cli_opts.json' ), + 'help': readFileSync( join( __dirname, '..', 'docs', 'usage.txt' ), { + 'encoding': 'utf8' + }) + }); + + // Get any provided command-line options: + flags = cli.flags(); + if ( flags.help || flags.version ) { + return; + } + + // Extract options... + opts = {}; + if ( flags[ 'class' ] ) { + opts.className = flags[ 'class' ]; + } + if ( flags.align ) { + opts.align = flags.align; + } + if ( flags.label ) { + opts.label = flags.label; + } + if ( flags.src ) { + opts.src = flags.src; + } + if ( flags.alt ) { + opts.alt = flags.alt; + } + console.log( createElement( opts ) ); // eslint-disable-line no-console +} + +main(); diff --git a/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/docs/usage.txt b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/docs/usage.txt new file mode 100644 index 000000000000..eab592f9caa1 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/docs/usage.txt @@ -0,0 +1,13 @@ + +Usage: ghimgfig [options] + +Options: + + -h, --help Print this message. + -V, --version Print the package version. + --class name Element class name. Default: figure. + --align alignment Element alignment. Default: center. + --label label Figure label. + --src url Image source URL. + --alt text Alternative image text. + diff --git a/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/etc/cli_opts.json b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/etc/cli_opts.json new file mode 100644 index 000000000000..eec1774e0a78 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/etc/cli_opts.json @@ -0,0 +1,21 @@ +{ + "string": [ + "class", + "align", + "label", + "src", + "alt" + ], + "boolean": [ + "help", + "version" + ], + "alias": { + "help": [ + "h" + ], + "version": [ + "V" + ] + } +} diff --git a/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/examples/index.js b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/examples/index.js new file mode 100644 index 000000000000..8b87c7d3e78e --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/examples/index.js @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +'use strict'; + +var createElement = require( './../lib' ); + +var opts = { + 'className': 'fig', + 'align': 'center', + 'label': 'fig:padding', + 'src': 'https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@master/lib/node_modules/@stdlib/plot/vega/padding/ctor/docs/img/figure_padding.svg', + 'alt': 'A visualization showing padding margins.' +}; + +var html = createElement( opts ); + +console.log( html ); +// => '
\n A visualization showing padding margins.\n
\n
' diff --git a/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/lib/defaults.json b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/lib/defaults.json new file mode 100644 index 000000000000..91fa4ac4eee4 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/lib/defaults.json @@ -0,0 +1,7 @@ +{ + "className": "figure", + "align": "center", + "label": "", + "src": "", + "alt": "" +} diff --git a/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/lib/index.js b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/lib/index.js new file mode 100644 index 000000000000..26ca996544b9 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/lib/index.js @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +'use strict'; + +/** +* Generate an HTML string for displaying an SVG figure as an image in a GitHub Markdown file. +* +* @module @stdlib/_tools/markdown/img-svg-figure +* +* @example +* var createElement = require( '@stdlib/_tools/markdown/img-svg-figure' ); +* +* var opts = { +* 'className': 'figure', +* 'align': 'center', +* 'label': 'fig:padding', +* 'src': 'https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@master/lib/node_modules/@stdlib/plot/vega/padding/ctor/docs/img/figure_padding.svg', +* 'alt': 'A visualization showing padding margins.' +* }; +* var html = createElement( opts ); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/lib/main.js b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/lib/main.js new file mode 100644 index 000000000000..33e3f1a01e3d --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/lib/main.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +'use strict'; + +// MODULES // + +var copy = require( '@stdlib/utils/copy' ); +var defaults = require( './defaults.json' ); +var validate = require( './validate.js' ); +var render = require( './render.js' ); + + +// MAIN // + +/** +* Generates an HTML string for displaying an SVG figure as an image in a GitHub Markdown file. +* +* @param {Options} [options] - function options +* @param {string} [options.className='figure'] - element class name +* @param {string} [options.align='center'] - element alignment +* @param {string} [options.label] - figure label +* @param {string} [options.src] - image source URL +* @param {string} [options.alt] - alternative image text +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options +* @returns {string} HTML string +* +* @example +* var opts = { +* 'className': 'figure', +* 'align': 'center', +* 'label': 'fig:padding', +* 'src': 'https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@master/lib/node_modules/@stdlib/plot/vega/padding/ctor/docs/img/figure_padding.svg', +* 'alt': 'A visualization showing padding margins.' +* }; +* var html = createElement( opts ); +* // returns +*/ +function createElement( options ) { + var opts; + var err; + opts = copy( defaults ); + if ( arguments.length ) { + err = validate( opts, options ); + if ( err ) { + throw err; + } + } + return render( opts ); +} + + +// EXPORTS // + +module.exports = createElement; diff --git a/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/lib/render.js b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/lib/render.js new file mode 100644 index 000000000000..20b2e257c0bb --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/lib/render.js @@ -0,0 +1,80 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +'use strict'; + +// MAIN // + +/** +* Renders an HTML string. +* +* ## Notes +* +* Example output: +* +* ```text +*
+* A visualization showing padding margins. +*
+*
+* ``` +* +* @private +* @param {Options} opts - render options +* @param {string} opts.className - element class name +* @param {string} opts.align - element alignment +* @param {string} opts.label - figure label +* @param {string} opts.src - image source URL +* @param {string} opts.alt - alternative image text +* @returns {string} HTML string +*/ +function render( opts ) { + var str = ''; + + str += '=0.10.0", + "npm": ">2.7.0" + }, + "keywords": [ + "stdlib", + "tools", + "create", + "element", + "figure", + "fig", + "visualization", + "chart", + "plot", + "markdown", + "mdown", + "md", + "gfm", + "github", + "gh", + "render", + "image", + "img", + "svg", + "html" + ] +} diff --git a/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/test/test.cli.js b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/test/test.cli.js new file mode 100644 index 000000000000..4ec2d9539027 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/test/test.cli.js @@ -0,0 +1,170 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var exec = require( 'child_process' ).exec; +var tape = require( 'tape' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var IS_WINDOWS = require( '@stdlib/assert/is-windows' ); +var readFileSync = require( '@stdlib/fs/read-file' ).sync; +var EXEC_PATH = require( '@stdlib/process/exec-path' ); + + +// VARIABLES // + +var fpath = resolve( __dirname, '..', 'bin', 'cli' ); +var opts = { + 'skip': IS_BROWSER || IS_WINDOWS +}; + + +// FIXTURES // + +var PKG_VERSION = require( './../package.json' ).version; + + +// TESTS // + +tape( 'command-line interface', function test( t ) { + t.ok( true, __filename ); + t.end(); +}); + +tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { + var expected; + var cmd; + + expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { + 'encoding': 'utf8' + }); + cmd = [ + EXEC_PATH, + fpath, + '--help' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); + } + t.end(); + } +}); + +tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { + var expected; + var cmd; + + expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { + 'encoding': 'utf8' + }); + cmd = [ + EXEC_PATH, + fpath, + '-h' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); + } + t.end(); + } +}); + +tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + fpath, + '--version' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); + } + t.end(); + } +}); + +tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + fpath, + '-V' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); + } + t.end(); + } +}); + +tape( 'the command-line interface generates an HTML string for rendering an SVG figure in GitHub Markdown', opts, function test( t ) { + var expected; + var cmd; + + cmd = [ + EXEC_PATH, + fpath, + '--class \'figure\'', + '--align \'center\'', + '--label \'fig:padding\'', + '--src \'https://cdn.jsdelivr.net/gh/stdlib-js/repo@branch/docs/img/fig.svg\'', + '--alt \'Visualization of padding.\'' + ]; + expected = '
\n Visualization of padding.\n
\n
\n'; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), expected, 'expected value' ); + t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); + } + t.end(); + } +}); diff --git a/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/test/test.js b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/test/test.js new file mode 100644 index 000000000000..ac7e96dfe896 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/test/test.js @@ -0,0 +1,126 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); +var createElement = require( './../lib' ); + + +// FUNCTIONS // + +function setup() { + return { + 'className': 'figure', + 'align': 'center', + 'label': 'fig:padding', + 'src': 'https://cdn.jsdelivr.net/gh/stdlib-js/repo@branch/docs/img/fig.svg', + 'alt': 'Visualization of padding.' + }; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof createElement, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid `options` argument', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + [], + noop + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws when provided ' + values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + createElement( value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid option', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + null, + void 0, + true, + false, + [], + {}, + noop + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws when provided ' + values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var opts = setup(); + opts.label = value; + createElement( opts ); + }; + } +}); + +tape( 'the function returns an HTML string for rendering an SVG figure in GitHub Markdown', function test( t ) { + var expected; + var actual; + + expected = '
\n Visualization of padding.\n
\n
'; + actual = createElement( setup() ); + + t.strictEqual( actual, expected, 'returns a HTML string' ); + t.end(); +}); + +tape( 'if not provided an option, the function will set a corresponding HTML attribute to either a default value (if one exists) or an empty string', function test( t ) { + var expected; + var actual; + + expected = '
\n \n
\n
'; + actual = createElement(); + + t.strictEqual( actual, expected, 'returns a HTML string' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/test/test.render.js b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/test/test.render.js new file mode 100644 index 000000000000..599f38d33c9e --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/test/test.render.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var render = require( './../lib/render.js' ); + + +// FUNCTIONS // + +function setup() { + return { + 'className': 'figure', + 'align': 'center', + 'label': 'fig:padding', + 'src': 'https://cdn.jsdelivr.net/gh/stdlib-js/repo@branch/docs/img/fig.svg', + 'alt': 'Visualization of padding.' + }; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof render, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a string', function test( t ) { + var str = render( setup() ); + t.strictEqual( typeof str, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an HTML string for rendering an SVG figure in GitHub Markdown', function test( t ) { + var expected; + var actual; + + expected = '
\n Visualization of padding.\n
\n
'; + actual = render( setup() ); + + t.strictEqual( actual, expected, 'returns a HTML string' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/test/test.validate.js b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/test/test.validate.js new file mode 100644 index 000000000000..28610df87e57 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/markdown/img-svg-figure/test/test.validate.js @@ -0,0 +1,226 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var validate = require( './../lib/validate.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof validate, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided an `options` argument which is not an object, the function returns a type error', function test( t ) { + var values; + var err; + var i; + + values = [ + '5', + 5, + NaN, + null, + true, + false, + void 0, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + err = validate( {}, values[i] ); + t.ok( err instanceof TypeError, 'returns a type error when provided ' + values[i] ); + } + t.end(); +}); + +tape( 'if provided a `className` option which is not a string primitive, the function returns a type error', function test( t ) { + var values; + var err; + var i; + + values = [ + 5, + NaN, + null, + true, + false, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + err = validate( {}, { + 'className': values[i] + }); + t.ok( err instanceof TypeError, 'returns a type error when provided ' + values[i] ); + } + t.end(); +}); + +tape( 'if provided an `align` option which is not a string primitive, the function returns a type error', function test( t ) { + var values; + var err; + var i; + + values = [ + 5, + NaN, + null, + true, + false, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + err = validate( {}, { + 'align': values[ i ] + }); + t.ok( err instanceof TypeError, 'returns a type error when provided ' + values[i] ); + } + t.end(); +}); + +tape( 'if provided a `label` option which is not a string primitive, the function returns a type error', function test( t ) { + var values; + var err; + var i; + + values = [ + 5, + NaN, + null, + true, + false, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + err = validate( {}, { + 'label': values[i] + }); + t.ok( err instanceof TypeError, 'returns a type error when provided ' + values[i] ); + } + t.end(); +}); + +tape( 'if provided a `src` option which is not a string primitive, the function returns a type error', function test( t ) { + var values; + var err; + var i; + + values = [ + 5, + NaN, + null, + true, + false, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + err = validate( {}, { + 'src': values[i] + }); + t.ok( err instanceof TypeError, 'returns a type error when provided ' + values[i] ); + } + t.end(); +}); + +tape( 'if provided an `alt` option which is not a string primitive, the function returns a type error', function test( t ) { + var values; + var err; + var i; + + values = [ + 5, + NaN, + null, + true, + false, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + err = validate( {}, { + 'alt': values[i] + }); + t.ok( err instanceof TypeError, 'returns a type error when provided ' + values[i] ); + } + t.end(); +}); + +tape( 'the function returns `null` if all options are valid', function test( t ) { + var opts; + var err; + var obj; + + obj = {}; + + opts = { + 'className': 'fig', + 'align': 'left', + 'label': 'fig', + 'src': 'https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@master/docs/img/fig.svg', + 'alt': 'Visualization' + }; + + err = validate( obj, opts ); + + t.strictEqual( err, null, 'returns expected value' ); + + t.deepEqual( obj, opts, 'updates destination object' ); + t.end(); +}); + +tape( 'the function ignores unrecognized options', function test( t ) { + var opts; + var err; + + opts = {}; + err = validate( opts, { + 'beep': 'boop', + 'a': { + 'b': 'c' + } + }); + t.strictEqual( err, null, 'returns expected value' ); + t.deepEqual( opts, {}, 'destination object is empty' ); + t.end(); +});