0.0.2 • Published 8 months ago

rollup-plugin-ternary-replacement v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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 nameConfig typeConfig appointmentConfig values
excludeArrayList of file/directory patterns that should be excluded from plugin launch
excludeExtentionsArrayList of file extensions that should be excluded from plugin launch
includeSourceMapBooleanenable source map flag
nonNullMergesOnlyBooleantransform assignments disable flag
assignmentsOnlyBooleantransform non-null merges disable flag

License

MIT