Socket
Socket
Sign inDemoInstall

babel-plugin-prismjs

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-prismjs - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0

59

lib/getComponents.js

@@ -22,2 +22,14 @@ "use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
/**
* @param {string} type
* @returns {(name: string) => string}
*/
var getPath = function getPath(type) {

@@ -28,12 +40,37 @@ return function (name) {

};
/**
* @param {string} dep
* @returns {boolean}
*/
var isPlugin = function isPlugin(dep) {
return _components["default"].plugins[dep] != null;
};
/**
* @param {string} type
* @param {string} name
* @returns {boolean}
*/
var getNoCSS = function getNoCSS(type, name) {
return _components["default"][type][name].noCSS;
return !!_components["default"][type][name].noCSS;
};
/**
* @param {string} theme
* @returns {string}
*/
var getThemePath = function getThemePath(theme) {
if (theme.includes('/')) {
var _theme$split = theme.split('/'),
_theme$split2 = _slicedToArray(_theme$split, 2),
themePackage = _theme$split2[0],
themeName = _theme$split2[1];
return "".concat(themePackage, "/themes/prism-").concat(themeName, ".css");
}
if (theme === 'default') {

@@ -50,2 +87,12 @@ theme = 'prism';

var getLanguagePath = getPath('languages');
/**
* @param {Options} [options]
* @returns {string[]}
*
* @typedef Options
* @property {string[] | 'all'} [languages]
* @property {string[]} [plugins]
* @property {string} [theme]
* @property {boolean} [css]
*/

@@ -62,2 +109,8 @@ var _default = function _default() {

if (languages === 'all') {
languages = Object.keys(_components["default"].languages).filter(function (l) {
return l !== 'meta';
});
}
return [].concat(_toConsumableArray((0, _dependencies["default"])(_components["default"], [].concat(_toConsumableArray(languages), _toConsumableArray(plugins))).getIds().reduce(function (deps, dep) {

@@ -72,5 +125,7 @@ // Plugins can have language dependencies.

return [].concat(_toConsumableArray(deps), add);
}, [])), _toConsumableArray(css && theme ? [getThemePath(theme)] : []));
},
/** @type {string[]} */
[])), _toConsumableArray(css && theme ? [getThemePath(theme)] : []));
};
exports["default"] = _default;

2

package.json
{
"name": "babel-plugin-prismjs",
"version": "2.0.1",
"version": "2.1.0",
"description": "A babel plugin to use PrismJS with standard bundlers.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -41,5 +41,5 @@ # babel-plugin-prismjs [![Build Status](https://travis-ci.org/mAAdhaTTah/babel-plugin-prismjs.svg?branch=master)](https://travis-ci.org/mAAdhaTTah/babel-plugin-prismjs)

* `languages`: Array of languages to include in the bundle. Those languages can be found [here](http://prismjs.com/#languages-list).
* `languages`: Array of languages to include in the bundle or `"all"` to include all languages. Those languages can be found [here](http://prismjs.com/#languages-list).
* `plugins`: Array of plugins to include in the bundle. Those plugins can be found [here](http://prismjs.com/#plugins).
* `theme`: Name of theme to include in the bundle. Themes can be found [here](http://prismjs.com/). Use `lower-kebab-case` for the theme name, e.g. `solarized-light`.
* `theme`: Name of theme to include in the bundle. Themes can be found [here](http://prismjs.com/).
* `css`: Boolean indicating whether to include `.css` files in the result. Defaults to `false`. If `true`, `import`s will be added for `.css` files. Must be `true` in order for `theme` to work.

@@ -0,11 +1,34 @@

/* eslint-disable valid-jsdoc */
import config from 'prismjs/components.js';
import getLoader from 'prismjs/dependencies.js';
/**
* @param {string} type
* @returns {(name: string) => string}
*/
const getPath = type => name =>
`prismjs/${config[type].meta.path.replace(/\{id\}/g, name)}`;
/**
* @param {string} dep
* @returns {boolean}
*/
const isPlugin = dep => config.plugins[dep] != null;
const getNoCSS = (type, name) => config[type][name].noCSS;
/**
* @param {string} type
* @param {string} name
* @returns {boolean}
*/
const getNoCSS = (type, name) => !!config[type][name].noCSS;
/**
* @param {string} theme
* @returns {string}
*/
const getThemePath = theme => {
if (theme.includes('/')) {
const [themePackage, themeName] = theme.split('/');
return `${themePackage}/themes/prism-${themeName}.css`
}
if (theme === 'default') {

@@ -23,14 +46,30 @@ theme = 'prism';

export default ({ languages = [], plugins = [], theme, css = false } = {}) => [
...getLoader(config, [...languages, ...plugins]).getIds().reduce((deps, dep) => {
// Plugins can have language dependencies.
const add = [isPlugin(dep) ? getPluginPath(dep) : getLanguagePath(dep)];
/**
* @param {Options} [options]
* @returns {string[]}
*
* @typedef Options
* @property {string[] | 'all'} [languages]
* @property {string[]} [plugins]
* @property {string} [theme]
* @property {boolean} [css]
*/
export default ({ languages = [], plugins = [], theme, css = false } = {}) => {
if (languages === 'all') {
languages = Object.keys(config.languages).filter(l => l !== 'meta');
}
if (css && isPlugin(dep) && !getNoCSS('plugins', dep)) {
add.unshift(getPluginPath(dep) + '.css');
}
return [
...getLoader(config, [...languages, ...plugins]).getIds().reduce((deps, dep) => {
// Plugins can have language dependencies.
const add = [isPlugin(dep) ? getPluginPath(dep) : getLanguagePath(dep)];
return [...deps, ...add];
}, []),
...(css && theme ? [getThemePath(theme)] : [])
];
if (css && isPlugin(dep) && !getNoCSS('plugins', dep)) {
add.unshift(getPluginPath(dep) + '.css');
}
return [...deps, ...add];
}, /** @type {string[]} */([])),
...(css && theme ? [getThemePath(theme)] : [])
];
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc