├── .eslintignore ├── .gitignore ├── src └── renderers │ ├── index.js │ ├── english-strings.js │ └── mdn-feature-table.js ├── .travis.yml ├── webpack.config.js ├── .eslintrc.json ├── CODE_OF_CONDUCT.md ├── contribute.json ├── README.md ├── package.json ├── bin └── render.js └── LICENSE /.eslintignore: -------------------------------------------------------------------------------- 1 | bin/* 2 | dist/* 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | /dist/ 3 | -------------------------------------------------------------------------------- /src/renderers/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 'mdnFeatureTable': require('./mdn-feature-table.js') 3 | } 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "8" 4 | script: 5 | - npm install 6 | - npm run lint 7 | 8 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | target: 'node', 3 | entry: './bin/render.js', 4 | output: { 5 | filename: 'main.js' 6 | }, 7 | mode: 'development' 8 | }; 9 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "standard", 3 | "env": { 4 | "es6": "true" 5 | }, 6 | "rules": { 7 | "no-template-curly-in-string": "warn" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Community Participation Guidelines 2 | 3 | This repository is governed by Mozilla's code of conduct and etiquette guidelines. 4 | For more details, please read the 5 | [Mozilla Community Participation Guidelines](https://www.mozilla.org/about/governance/policies/participation/). 6 | 7 | ## How to Report 8 | 9 | For more information on how to report violations of the Community Participation 10 | Guidelines, please read our 11 | [How to Report](https://www.mozilla.org/about/governance/policies/participation/reporting/) 12 | page. 13 | -------------------------------------------------------------------------------- /contribute.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "browser-compat-toolkit", 3 | "description": "Toolkit for visualizing and editing MDN's browser compatibility data", 4 | "repository": { 5 | "url": "https://github.com/mdn/browser-compat-toolkit", 6 | "license": "MPL-2.0" 7 | }, 8 | "participate": { 9 | "home": "https://developer.mozilla.org/", 10 | "docs": "https://github.com/mdn/browser-compat-toolkit", 11 | "mailing-list": "https://discourse.mozilla.org/c/mdn", 12 | "irc": "irc://irc.mozilla.org/mdn" 13 | }, 14 | "keywords": [ 15 | "MDN", 16 | "BCD", 17 | "browser", 18 | "compat", 19 | "data", 20 | "tables" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Browser Compat Toolkit 2018 2 | --- 3 | 4 | [![Build Status](https://travis-ci.org/mdn/browser-compat-toolkit.svg?branch=master)](https://travis-ci.org/mdn/browser-compat-toolkit) 5 | 6 | Toolkit for visualizing and editing MDN's browser compatibility data. 7 | 8 | This was developed at the 9 | [Paris 2018 Hack on MDN](https://hacks.mozilla.org/2018/03/hack-on-mdn-building-useful-tools-with-browser-compatibility-data/). 10 | It is an interesting proof-of-concept, but there was not a clear path to using 11 | it for rendering compatibility tables on 12 | [MDN Web Docs](https://developer.mozilla.org), or to help contributors to 13 | the 14 | [browser-compat-data (BCD) project](https://github.com/mdn/browser-compat-data). 15 | Without MDN staff sponsorship, this repository has not kept up with BCD 16 | development. Feel free to use these ideas for your own BCD integration. 17 | 18 | Some goals of the proof of concept: 19 | 20 | * Render MDN's compat tables from code in this repo. 21 | * Allow GitHub reviewers to see tables. 22 | * Allow contributors to view and edit compat data. 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mdn-browser-compat-toolkit", 3 | "version": "0.0.1", 4 | "description": "Toolkit for visualizing and editing MDN's browser compatibility data", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "render": "node ./bin/render.js", 9 | "lint": "./node_modules/.bin/eslint --ignore-path .eslintignore src/*" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/mdn/browser-compat-toolkit.git" 14 | }, 15 | "keywords": [ 16 | "MDN", 17 | "BCD", 18 | "browser", 19 | "compat", 20 | "data", 21 | "tables" 22 | ], 23 | "author": "MDN Web Docs", 24 | "license": "MPL-2.0", 25 | "bugs": { 26 | "url": "https://github.com/mdn/browser-compat-toolkit/issues" 27 | }, 28 | "homepage": "https://github.com/mdn/browser-compat-toolkit", 29 | "devDependencies": { 30 | "mdn-browser-compat-data": "^0.0.31", 31 | "eslint": "^4.19.0", 32 | "eslint-config-standard": "^11.0.0", 33 | "eslint-plugin-import": "^2.9.0", 34 | "eslint-plugin-node": "^6.0.1", 35 | "eslint-plugin-promise": "^3.7.0", 36 | "eslint-plugin-standard": "^3.0.1", 37 | "webpack": "^4.1.1", 38 | "webpack-cli": "^2.0.12" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /bin/render.js: -------------------------------------------------------------------------------- 1 | 2 | function render(dataOrString, renderer, configuration) { 3 | 4 | /* Convert a string to the BCD data */ 5 | let data = undefined; 6 | if (typeof dataOrString === 'string' || dataOrString instanceof String) { 7 | const dataParts = dataOrString.split('.'); 8 | data = require('mdn-browser-compat-data'); 9 | dataParts.forEach((elem) => { 10 | if (!data.hasOwnProperty(elem)) { 11 | throw new Error(`Unable to find data for "${dataOrString}" at "${elem}".`); 12 | } 13 | data = data[elem]; 14 | }); 15 | } else { 16 | data = dataOrString; 17 | } 18 | return renderer(data, configuration); 19 | } 20 | 21 | function usage() { 22 | const usageString = `Render a feature as an HTML table. 23 | 24 | Usage: 25 | npm run render [depth] [aggregateMode] 26 | 27 | Options: 28 | 29 | featurePath: Dotted path to feature 30 | depth: Traversal depth 31 | 32 | Examples: 33 | 34 | npm run render webextensions.api.alarms 35 | npm run --silent render webextensions.api.alarms > test.html 36 | npm run render http.status.404 37 | npm run render webextensions.api.alarms 3 38 | `; 39 | console.log(usageString); 40 | } 41 | 42 | 43 | function main() { 44 | const renderers = require('../src/renderers/index.js'); 45 | const query = process.argv[2]; 46 | const depth = process.argv[3] || 1; 47 | 48 | if (query === undefined) { 49 | usage(); 50 | process.exit(0); 51 | } 52 | 53 | const html = render( 54 | query, 55 | renderers.mdnFeatureTable, 56 | { 57 | 'query': query, 58 | 'depth': depth, 59 | }); 60 | console.log(html); 61 | } 62 | 63 | module.exports = render; 64 | if (require.main === module) main(); 65 | -------------------------------------------------------------------------------- /src/renderers/english-strings.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 'bc_history_head': 'Implementation Notes', 3 | 'bc_icon_name_altname': 'Alternate Name', 4 | 'bc_icon_name_chrome': 'Chrome', 5 | 'bc_icon_name_chrome_android': 'Chrome for Android', 6 | 'bc_icon_name_deprecated': 'Deprecated', 7 | 'bc_icon_name_desktop': 'Desktop', 8 | 'bc_icon_name_disabled': 'Disabled', 9 | 'bc_icon_name_edge': 'Edge', 10 | 'bc_icon_name_edge_mobile': 'Edge Mobile', 11 | 'bc_icon_name_experimental': 'Experimental', 12 | 'bc_icon_name_firefox': 'Firefox', 13 | 'bc_icon_name_firefox_android': 'Firefox for Android', 14 | 'bc_icon_name_footnote': 'Notes', 15 | 'bc_icon_name_ie': 'Internet Explorer', 16 | 'bc_icon_name_mobile': 'Mobile', 17 | 'bc_icon_name_nodejs': 'Node.js', 18 | 'bc_icon_name_non-standard': 'Non-standard', 19 | 'bc_icon_name_opera': 'Opera', 20 | 'bc_icon_name_opera_android': 'Opera for Android', 21 | 'bc_icon_name_prefix': 'Prefixed', 22 | 'bc_icon_name_safari': 'Safari', 23 | 'bc_icon_name_safari_ios': 'iOS Safari', 24 | 'bc_icon_name_samsunginternet_android': 'Samsung Internet', 25 | 'bc_icon_name_server': 'Server', 26 | 'bc_icon_name_webview_android': 'Android webview', 27 | 'bc_icon_title_altname': 'Uses the non-standard name: $1$', 28 | 'bc_icon_title_deprecated': 'Deprecated. Not for use in new websites.', 29 | 'bc_icon_title_disabled': 'User must explicitly enable this feature.', 30 | 'bc_icon_title_experimental': 'Experimental. Expect behavior to change in the future.', 31 | 'bc_icon_title_footnote': 'See implementation notes', 32 | 'bc_icon_title_non-standard': 'Non-standard. Expect poor cross-browser support.', 33 | 'bc_icon_title_prefix': 'Requires the vendor prefix: $1$', 34 | 'feature': 'Feature', 35 | 'feature_basicsupport': 'Basic support', 36 | 'legend': 'Legend', 37 | 'legend_altname': 'Uses a non-standard name.', 38 | 'legend_deprecated': 'Deprecated. Not for use in new websites.', 39 | 'legend_disabled': 'User must explicitly enable this feature.', 40 | 'legend_experimental': 'Experimental. Expect behavior to change in the future.', 41 | 'legend_footnote': 'See implementation notes.', 42 | 'legend_non-standard': 'Non-standard. Expect poor cross-browser support.', 43 | 'legend_prefix': 'Requires a vendor prefix or different name for use.', 44 | 'supportsLong_no': 'No support', 45 | 'supportsLong_partial': 'Partial support', 46 | 'supportsLong_unknown': 'Compatibility unknown', 47 | 'supportsLong_yes': 'Full support', 48 | 'supportsShort_no': 'No', 49 | 'supportsShort_partial': 'Partial', 50 | 'supportsShort_unknown': '?', 51 | 'supportsShort_unknown_title': 'Compatibility unknown; please update this.', 52 | 'supportsShort_yes': 'Yes', 53 | 'supportsShort_yes_title': 'Please update this with the earliest version of support.', 54 | 'no_data_found': 'No compatibility data found. Please contribute data for "${query}" (depth: ${depth}) to the MDN compatibility data repository.' 55 | } 56 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | -------------------------------------------------------------------------------- /src/renderers/mdn-feature-table.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Migrated from https://github.com/mdn/kumascript/master/macros/CompatBeta.ejs 4 | 5 | Run as render(data, configuration), where config gives rendering configuration. 6 | 7 | Required configuration: 8 | 9 | - query: The full querystring for the data, such as webextensions.api.alarms 10 | 11 | Optional configuration: 12 | 13 | - depth: How deep subfeatures should be added to the table 14 | - strings: Replacements for the default strings, such as localized strings 15 | - forMDNURL: The MDN URL that the table will be displayed on. 16 | If given, use relative links, but avoid linking to that page. 17 | If omitted (default), use external links to MDN. 18 | 19 | Sample: 20 | 21 | render(bcd.webextensions.api.alarms, {'query': 'webextensions.api.alarms'}); 22 | */ 23 | 24 | // import * as defaultStrings from './english-strings' 25 | 26 | const defaultStrings = require('./english-strings') 27 | 28 | const browsers = { 29 | 'desktop': ['chrome', 'edge', 'firefox', 'ie', 'opera', 'safari'], 30 | 'mobile': ['webview_android', 'chrome_android', 'edge_mobile', 'firefox_android', 'opera_android', 'safari_ios', 'samsunginternet_android'], 31 | 'server': ['nodejs'], 32 | 'webextensions-desktop': ['chrome', 'edge', 'firefox', 'opera'], 33 | 'webextensions-mobile': ['firefox_android'] 34 | } 35 | 36 | /* The rendering function */ 37 | function render (compatData, configuration) { 38 | const query = configuration.query 39 | const depth = configuration.depth || 1 40 | const forMDNURL = configuration.forMDNURL 41 | const category = query.split('.')[0] 42 | let legendItems = new Set() // entries will be unique 43 | let output = '' 44 | let strings = defaultStrings 45 | 46 | for (var key in configuration.strings) { 47 | strings[key] = configuration.strings[key] 48 | } 49 | 50 | let bcCategory = 'web' 51 | let platforms = ['desktop', 'mobile'] 52 | let displayBrowers = [...browsers['desktop'], ...browsers['mobile']] 53 | 54 | if (category === 'javascript') { 55 | bcCategory = 'js' 56 | displayBrowers.push(...browsers['server']) 57 | platforms.push('server') 58 | } 59 | if (category === 'webextensions') { 60 | bcCategory = 'ext' 61 | displayBrowers = [...browsers['webextensions-desktop'], ...browsers['webextensions-mobile']] 62 | platforms = ['webextensions-desktop', 'webextensions-mobile'] 63 | } 64 | 65 | /* Gather a flat list of features */ 66 | let features = [] 67 | if (compatData.__compat) { 68 | let feature = compatData.__compat 69 | feature.description = strings['feature_basicsupport'] 70 | const identifier = query.split('.').pop() 71 | features.push({[identifier]: feature}) 72 | } 73 | traverseFeatures(compatData, depth, '', features) 74 | 75 | if (features.length > 0) { 76 | output = '' 84 | } else { 85 | let errString = strings['no_data_found'].replace('${query}', query).replace('${depth}', depth) 86 | output = errString 87 | } 88 | 89 | return output 90 | } 91 | 92 | /* 93 | Get features that should be displayed according to the query and the depth setting 94 | Flatten them into a features array 95 | */ 96 | function traverseFeatures (obj, depth, identifier, features) { 97 | depth-- 98 | if (depth >= 0) { 99 | for (let i in obj) { 100 | if (!!obj[i] && typeof (obj[i]) === 'object' && i !== '__compat') { 101 | if (obj[i].__compat) { 102 | features.push({[identifier + i]: obj[i].__compat}) 103 | } 104 | traverseFeatures(obj[i], depth, i + '.', features) 105 | } 106 | } 107 | } 108 | } 109 | 110 | /* 111 | * Rendering functions! 112 | */ 113 | function writeCompatHead (strings, platforms, displayBrowers) { 114 | let output = '' 115 | output += writeCompatPlatformsRow(strings, platforms) 116 | output += writeCompatBrowsersRow(strings, displayBrowers) 117 | output += '' 118 | return output 119 | } 120 | 121 | function writeCompatPlatformsRow (strings, platforms) { 122 | let output = '' 123 | output += '' 124 | 125 | for (let platform of platforms) { 126 | let platformCount = Object.keys(browsers[platform]).length 127 | let platformId = platform.replace('webextensions-', '') 128 | output += `` 129 | output += writeIcon(strings, platformId) 130 | output += '' 131 | } 132 | 133 | output += '' 134 | return output 135 | } 136 | 137 | function writeCompatBrowsersRow (strings, displayBrowers) { 138 | let output = '' 139 | output += '' 140 | for (let browser of displayBrowers) { 141 | output += `` 142 | output += writeIcon(strings, browser) 143 | output += '' 144 | } 145 | output += '' 146 | return output 147 | } 148 | 149 | function writeCompatBody (strings, features, forMDNURL, displayBrowers, legendItems) { 150 | let output = '' 151 | output += writeCompatFeatureRow(strings, features, forMDNURL, displayBrowers, legendItems) 152 | output += '' 153 | return output 154 | } 155 | 156 | function writeCompatFeatureRow (strings, features, forMDNURL, displayBrowers, legendItems) { 157 | let output = '' 158 | for (let row of features) { 159 | output += '' 160 | let feature = Object.keys(row).map((k) => row[k])[0] 161 | output += `${writeFeatureName(strings, row, feature, forMDNURL, legendItems)}` 162 | output += `${writeCompatCells(strings, feature.support, displayBrowers, legendItems)}` 163 | output += '' 164 | } 165 | return output 166 | } 167 | 168 | /* Write a icon with localized hover text */ 169 | function writeIcon (strings, iconSlug, replacer, isLegend) { 170 | let iconName = stringOrKey(strings, 'bc_icon_name_' + iconSlug).replace('$1$', replacer) 171 | let iconTitle = stringOrKey(strings, 'bc_icon_title_' + iconSlug).replace('$1$', replacer) 172 | if (isLegend) { 173 | iconName = strings['legend_' + iconSlug] 174 | iconTitle = iconName 175 | } 176 | // there is no iconTitle, fall back to iconName 177 | if (iconTitle === 'bc_icon_title_' + iconSlug) { 178 | iconTitle = iconName 179 | } 180 | let output = '' 181 | output += `` 182 | output += `${iconName}` 183 | output += `` 184 | output += '' 185 | return output 186 | } 187 | 188 | function writeFeatureName (strings, row, feature, forMDNURL, legendItems) { 189 | let desc = '' 190 | let featureIcons = '' 191 | let experimentalIcon = '' 192 | let deprecatedIcon = '' 193 | let nonStandardIcon = '' 194 | let label = Object.keys(row)[0] 195 | 196 | if (feature.description) { 197 | // Basic support or unnested features need no prefixing 198 | if (label.indexOf('.') === -1) { 199 | desc += feature.description 200 | // otherwise add a prefix so that we know where this belongs to (e.g. "parse: ISO 8601 format") 201 | } else { 202 | desc += `${label.slice(0, label.lastIndexOf('.'))}: ${feature.description}` 203 | } 204 | } else { 205 | desc += `${Object.keys(row)[0]}` 206 | } 207 | if (feature.mdn_url) { 208 | let href = feature.mdn_url 209 | if (forMDNURL) { 210 | // Convert to relative MDN url 211 | href = feature.mdn_url.replace('https://developer.mozilla.org', '') 212 | let mdnSlug = forMDNURL.split('/docs/')[1] 213 | if (href === '/docs/' + mdnSlug) { 214 | // Don't link to the current page 215 | href = '' 216 | } 217 | } 218 | if (href !== '') { 219 | desc = `${desc}` 220 | } 221 | } 222 | 223 | if (feature.hasOwnProperty('status')) { 224 | if (feature.status.experimental === true) { 225 | experimentalIcon = writeIcon(strings, 'experimental') 226 | legendItems.add('experimental') 227 | } 228 | if (feature.status.deprecated === true) { 229 | deprecatedIcon = writeIcon(strings, 'deprecated') 230 | legendItems.add('deprecated') 231 | } 232 | if (feature.status.standard_track === false) { 233 | nonStandardIcon = writeIcon(strings, 'non-standard') 234 | legendItems.add('non-standard') 235 | } 236 | if (experimentalIcon || deprecatedIcon || nonStandardIcon) { 237 | featureIcons += '
' 238 | featureIcons += experimentalIcon 239 | featureIcons += deprecatedIcon 240 | featureIcons += nonStandardIcon 241 | featureIcons += '
' 242 | } 243 | } 244 | return desc + featureIcons 245 | } 246 | 247 | /* Use the key if no string is defined */ 248 | function stringOrKey (strings, key) { 249 | return strings[key] || key 250 | } 251 | 252 | /* 253 | Returns the string to appear in the table cell, like "Yes", "No" or "?", "Partial" 254 | or the version number 255 | 256 | `added` and `removed` are either null, true, false or a string containing a version number 257 | `partial` is either null, true, or false indicating partial_implementation 258 | */ 259 | function getCellString (strings, added, removed, partial) { 260 | let output = '' 261 | switch (added) { 262 | case null: 263 | output = ` 264 | ${strings['supportsShort_unknown']} 265 | ` 266 | break 267 | case true: 268 | output = ` 270 | ${strings['supportsLong_yes']} 271 | 272 | ${strings['supportsShort_yes']}` 273 | break 274 | case false: 275 | output = ` 277 | ${strings['supportsLong_no']} 278 | 279 | ${strings['supportsShort_no']}` 280 | break 281 | default: 282 | output = ` 284 | ${strings['supportsLong_yes']} 285 | 286 | ${added}` 287 | } 288 | if (removed) { 289 | output = ` 291 | ${strings['supportsLong_no']} 292 | ` 293 | // We don't know when supported started 294 | if (typeof (added) === 'boolean' && added) { 295 | output += '?' 296 | } else { // We know when 297 | output += added 298 | } 299 | output += ' — ' 300 | // We don't know when supported ended 301 | if (typeof (removed) === 'boolean' && removed) { 302 | output += '?' 303 | } else { // We know when 304 | output += removed 305 | } 306 | // removed wins over partial 307 | } else if (partial) { 308 | output = ` 310 | ${strings['supportsLong_partial']} 311 | ` 312 | // Display "Partial" instead of "Yes", "No", or "?" if we have no version string 313 | if (typeof (added) !== 'string') { 314 | output += strings['supportsShort_partial'] 315 | } else { 316 | output += added 317 | } 318 | } 319 | return output 320 | } 321 | 322 | /* 323 | Given the support information for a browser, this returns 324 | a CSS class to apply to the table cell. 325 | 326 | `supportData` is a (or an array of) support_statement(s) 327 | */ 328 | function getSupportClass (supportInfo) { 329 | let cssClass = 'unknown' 330 | 331 | if (Array.isArray(supportInfo)) { 332 | // the first entry should be the most relevant/recent and will be treated as "the truth" 333 | checkSupport(supportInfo[0].version_added, 334 | supportInfo[0].version_removed, 335 | supportInfo[0].partial_implementation) 336 | } else if (supportInfo) { // there is just one support statement 337 | checkSupport(supportInfo.version_added, 338 | supportInfo.version_removed, 339 | supportInfo.partial_implementation) 340 | } else { // this browser has no info, it's unknown 341 | return 'unknown' 342 | } 343 | 344 | function checkSupport (added, removed, partial) { 345 | if (added === null) { 346 | cssClass = 'unknown' 347 | } else if (added) { 348 | cssClass = 'yes' 349 | if (removed) { 350 | cssClass = 'no' 351 | } 352 | } else { 353 | cssClass = 'no' 354 | } 355 | if (partial && !removed) { 356 | cssClass = 'partial' 357 | } 358 | } 359 | 360 | return cssClass 361 | } 362 | 363 | /* 364 | Generate the note for a browser flag or preference 365 | First checks version_added and version_removed to create a string indicating when 366 | a preference setting is present. Then creates a (browser specific) string 367 | for either a preference flag or a compile flag. 368 | 369 | // TODO Need to localize this 370 | 371 | `supportData` is a support_statement 372 | `browserId` is a compat_block browser ID 373 | */ 374 | function writeFlagsNote (supportData, browserId) { 375 | let output = '' 376 | 377 | const firefoxPrefs = ' To change preferences in Firefox, visit about:config.' 378 | const chromePrefs = ' To change preferences in Chrome, visit chrome://flags.' 379 | 380 | if (typeof (supportData.version_added) === 'string') { 381 | output = `From version ${supportData.version_added}` 382 | } 383 | 384 | if (typeof (supportData.version_removed) === 'string') { 385 | if (output) { 386 | output += ' ' 387 | output += `until version ${supportData.version_removed} (exclusive)` 388 | } else { 389 | output = `Until version ${supportData.version_removed} (exclusive)` 390 | } 391 | } 392 | 393 | let start = 'This' 394 | if (output) { 395 | output += ':' 396 | start = ' this' 397 | } 398 | 399 | start += ' feature is behind the ' 400 | 401 | let flagsText = '' 402 | let settings = '' 403 | 404 | for (let i = 0; i < supportData.flags.length; i++) { 405 | let flag = supportData.flags[i] 406 | let nameString = `${flag.name}` 407 | 408 | // value_to_set is optional 409 | let valueToSet = '' 410 | if (flag.value_to_set) { 411 | valueToSet = ` (needs to be set to ${flag.value_to_set})` 412 | } 413 | 414 | let typeString = '' 415 | if (flag.type === 'preference') { 416 | switch (browserId) { 417 | case 'firefox': 418 | case 'firefox_android': 419 | settings = firefoxPrefs 420 | break 421 | case 'chrome': 422 | case 'chrome_android': 423 | settings = chromePrefs 424 | break 425 | } 426 | typeString = ` preference${valueToSet}` 427 | } 428 | 429 | if (flag.type === 'compile_flag') { 430 | typeString = ` compile flag${valueToSet}` 431 | } 432 | 433 | if (flag.type === 'runtime_flag') { 434 | typeString = ` runtime flag${valueToSet}` 435 | } 436 | 437 | flagsText += nameString + typeString 438 | 439 | if (i !== supportData.flags.length - 1) { 440 | flagsText += ' and the ' 441 | } else { 442 | flagsText += '.' 443 | } 444 | } 445 | 446 | output += start + flagsText + settings 447 | 448 | return output 449 | } 450 | 451 | /* 452 | Generates icons for the main cell 453 | `supportData` is a support_statement 454 | 455 | */ 456 | function writeCellIcons (strings, support, legendItems) { 457 | let output = '
' 458 | 459 | if (Array.isArray(support)) { 460 | // the first entry should be the most relevant/recent and will be used for the main cell 461 | support = support[0] 462 | } 463 | if (support.prefix) { 464 | output += writeIcon(strings, 'prefix', support.prefix) + ' ' 465 | legendItems.add('prefix') 466 | } 467 | 468 | if (support.notes) { 469 | output += writeIcon(strings, 'footnote') + ' ' 470 | legendItems.add('footnote') 471 | } 472 | 473 | if (support.alternative_name) { 474 | output += writeIcon(strings, 'altname', support.alternative_name) + ' ' 475 | legendItems.add('altname') 476 | } 477 | 478 | if (support.flags) { 479 | output += writeIcon(strings, 'disabled') + ' ' 480 | legendItems.add('disabled') 481 | } 482 | 483 | output += '
' 484 | 485 | return output 486 | } 487 | 488 | /* 489 | Create notes section 490 | 491 | `supportData` is a support_statement 492 | `browserId` is a compat_block browser ID 493 | 494 | */ 495 | function writeNotes (strings, support, browserId, legendItems) { 496 | let output = '' 567 | 568 | return output 569 | } 570 | 571 | /* 572 | For a single row, write all the cells that contain support data. 573 | (That is, every cell in the row except the first, which contains 574 | an identifier for the row, like "Basic support". 575 | 576 | */ 577 | function writeCompatCells (strings, supportData, displayBrowers, legendItems) { 578 | let output = '' 579 | 580 | for (let browserNameKey of displayBrowers) { 581 | let needsNotes = false 582 | let support = supportData[browserNameKey] 583 | let supportInfo = '' 584 | if (support) { 585 | if (Array.isArray(support)) { 586 | // Take first support data 587 | supportInfo += getCellString(strings, 588 | support[0].version_added, 589 | support[0].version_removed, 590 | support[0].partial_implementation) 591 | needsNotes = true 592 | } else { 593 | supportInfo += getCellString(strings, 594 | support.version_added, 595 | support.version_removed, 596 | support.partial_implementation) 597 | if (support.notes || support.prefix || support.flags || support.alternative_name) { 598 | needsNotes = true 599 | } 600 | } 601 | } else { // browsers are optional in the data, display them as "?" in our table 602 | supportInfo += getCellString(strings, null) 603 | } 604 | 605 | let supportClass = getSupportClass(support) 606 | output += `${supportInfo}` 614 | 615 | if (needsNotes) { 616 | output += writeCellIcons(strings, support, legendItems) 617 | output += writeNotes(strings, support, browserNameKey, legendItems) 618 | } 619 | output += '' 620 | } 621 | 622 | return output 623 | } 624 | 625 | function writeLegend (strings, legendItems) { 626 | let output = '
' 627 | output += `

${strings['legend']}

` 628 | output += '
' 629 | 630 | let sortOrder = ['support_yes', 'support_partial', 'support_no', 'support_unknown', 631 | 'experimental', 'non-standard', 'deprecated', 632 | 'footnote', 'disabled', 'altname', 'prefix'] 633 | let sortedLegendItems = Array.from(legendItems).sort(function (a, b) { 634 | return sortOrder.indexOf(a) - sortOrder.indexOf(b) 635 | }) 636 | 637 | for (let item of sortedLegendItems) { 638 | // handle supprt cells 639 | if (item.indexOf('support_') !== -1) { 640 | let supportType = item.substring(item.indexOf('_') + 1) 641 | output += `
642 | 644 | ${strings['supportsLong_' + supportType]} 645 |   646 |
` 647 | output += `
${strings['supportsLong_' + supportType]}
` 648 | // handle icons 649 | } else { 650 | output += `
${writeIcon(strings, item, '', true)}
` 651 | output += `
${strings['legend_' + item]}
` 652 | } 653 | } 654 | 655 | output += '
' 656 | output += '
' 657 | return output 658 | } 659 | 660 | module.exports = render 661 | --------------------------------------------------------------------------------