Socket
Socket
Sign inDemoInstall

@babel/plugin-transform-literals

Package Overview
Dependencies
81
Maintainers
5
Versions
66
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @babel/plugin-transform-literals

Compile ES2015 unicode string and number literals to ES5


Version published
Weekly downloads
24M
decreased by-1.24%
Maintainers
5
Install size
10.7 kB
Created
Weekly downloads
 

Package description

What is @babel/plugin-transform-literals?

The @babel/plugin-transform-literals package is a plugin for Babel, a JavaScript compiler, that transforms modern JavaScript literal syntax into a form compatible with older JavaScript engines. This includes transforming template literals, binary literals, octal literals, and Unicode string literals into strings and numbers that can be understood by environments that do not support these features natively.

What are @babel/plugin-transform-literals's main functionalities?

Template Literals Transformation

Converts template literals into string concatenation to ensure compatibility with older JavaScript engines.

`Hello, ${name}!` -> 'Hello, ' + name + '!'

Binary Literals Transformation

Transforms binary literals into their decimal number equivalents.

0b101001 -> 41

Octal Literals Transformation

Converts octal literals into their decimal number equivalents.

0o755 -> 493

Unicode String Literals Transformation

Transforms Unicode string literals into escaped sequences compatible with older JavaScript engines.

'\u{1F680}' -> '\uD83D\uDE80'

Other packages similar to @babel/plugin-transform-literals

Readme

Source

@babel/plugin-transform-literals

Compile ES2015 unicode string and number literals to ES5

Example

In

var b = 0b11; // binary integer literal
var o = 0o7; // octal integer literal
const u = 'Hello\u{000A}\u{0009}!'; // unicode string literals, newline and tab

Out

var b = 3; // binary integer literal
var o = 7; // octal integer literal
const u = 'Hello\n\t!'; // unicode string literals, newline and tab

Installation

npm install --save-dev @babel/plugin-transform-literals

Usage

.babelrc

{
  "plugins": ["@babel/plugin-transform-literals"]
}

Via CLI

babel --plugins @babel/plugin-transform-literals script.js

Via Node API

require("@babel/core").transform("code", {
  plugins: ["@babel/plugin-transform-literals"]
});

Keywords

FAQs

Last updated on 15 May 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc