Skip to content

Commit f45b583

Browse files
committed
Add script for rendering an embedded compatibility table
1 parent 8de6933 commit f45b583

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

scripts/render/embed.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* @license MIT
3+
*
4+
* Copyright (c) 2023 Python Data APIs Consortium.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
/* eslint-disable no-underscore-dangle, node/no-unpublished-require */
26+
27+
'use strict';
28+
29+
// MODULES //
30+
31+
var objectKeys = require( '@stdlib/utils-keys' );
32+
var replace = require( '@stdlib/string-replace' );
33+
var TMPL = require( './../templates' );
34+
var renderCompat = require( './compat.js' );
35+
36+
37+
// MAIN //
38+
39+
/**
40+
* Renders HTML content for provided compatibility data.
41+
*
42+
* @private
43+
* @param {Object} data - compatibility data
44+
* @param {string} maxVersion - maximum version
45+
* @returns {(string|null)} HTML string
46+
*/
47+
function render( data, maxVersion ) {
48+
var name;
49+
var out;
50+
var d;
51+
52+
// Get the API name:
53+
name = objectKeys( data )[ 0 ];
54+
d = data[ name ];
55+
56+
// Check whether the API satisfies version constraints:
57+
if ( maxVersion !== '*' && d.__compat.version_added > maxVersion ) {
58+
return null;
59+
}
60+
// Render compatibility data:
61+
out = replace( TMPL.COMPAT_WRAPPER_EMBED, '{{TABLE}}', renderCompat( d, name, maxVersion ) );
62+
out = replace( out, '{{LEGEND}}', TMPL.LEGEND );
63+
64+
return out;
65+
}
66+
67+
68+
// EXPORTS //
69+
70+
module.exports = render;

0 commit comments

Comments
 (0)