Skip to content

Plugin that replaces non-null merge and logical assignments with ternary operators

License

Notifications You must be signed in to change notification settings

danyaridiger/rollup-plugin-ternary-replacement

Repository files navigation

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

About

Plugin that replaces non-null merge and logical assignments with ternary operators

Resources

License

Stars

Watchers

Forks

Packages

No packages published