rollup-plugin-ternary-replacement
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

rollup-plugin-ternary-replacement v0.0.2


Brief annotation

"rollup-plugin-ternary-replacement" is a plugin for popular web-applications builder called "rollup". This plugin can help developers to make their web-applications more compatible by replacing some of new ECMAScript features such as "??" operator by ternary operators. Replacing will be done automatically if plugin function call have been placed into rollup plugins configuration. Plugin convertion is performed without violating program logic and program flow disruptions. Different optional parameters allow to configurate plugin for developer's own needs. For example, developer can choose specific group of features that should be rapleced, or exclude certain files from conversion process. Plugin works correctly with both vanilla ECMAScript and framework syntax (also included jsx/tsx syntax).

Installation with npm

npm install --save-dev rollup-plugin-ternary-replacement

Installation with yarn

yarn add --dev rollup-plugin-ternary-replacement

Importing

import replace from "rollup-plugin-ternary-replacement"

Importing types

import rollupPluginTernaryReplacement from "rollup-plugin-ternary-replacement/types"

Table of contents

Simple example

Replacing all admissible features with ternary operators.

import replace from "rollup-plugin-ternary-replacement";

export default [
  input: "index.js",
  output: [
    {
      file: "dist/index.js",
      format: "es",
    },
  ],
  plugins: [replace()],
];

Example with config

Replacing only logical assignments with ternary operators in particular files.

import replace from "rollup-plugin-ternary-replacement";

const config = {
  exclude: ["excess-file.js"],
  assignmentsOnly: true,
};

export default [
  input: "index.js",
  output: [
    {
      file: "dist/index.js",
      format: "es",
    },
  ],
  plugins: [replace(config)],
];

Config list

Config name Config type Config appointment Config values
exclude Array List of file/directory patterns that should be excluded from plugin launch
excludeExtentions Array List of file extensions that should be excluded from plugin launch
includeSourceMap Boolean enable source map flag
nonNullMergesOnly Boolean transform assignments disable flag
assignmentsOnly Boolean transform non-null merges disable flag

License

MIT

Package Sidebar

Install

npm i rollup-plugin-ternary-replacement

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

50.5 kB

Total Files

8

Last publish

Collaborators

  • danyaridiger