New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

inlinable

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inlinable

JavaScript code inlining utilities

latest
Source
npmnpm
Version
0.8.2
Version published
Weekly downloads
13
-71.11%
Maintainers
1
Weekly downloads
 
Created
Source

Inlinable

Quickstart

First, add the package as dev dependency:

npm install -D inlinable

Then use the default export in any JavaScript module to flag an expression as candidate for inlining:

import __inlinable from 'inlinable';

// Inline the contents of `resources/METADATA`
const metadata = __inlinable((ctx) => {
  const path = ctx.enclosing(import.meta.url).resourcePath('METADATA');
  return ctx.readTextFile(path);
});

Then run the command below to inline all candidates found in matching files:

$ inlinable replace lib/**/*.js

This works best when run automatically after TypeScript compilation within a package.json script:

  "scripts": {
    "build": "tsc -p src && inlinable replace"
    // ...
  }

How does it work?

In the simple case, inlinable replace runs each inlinable function as if it was an IIFE and substitutes the original value with its JSONified return value. Additionally, the inlinable import is removed. In the example above, the final code will look like:

const metadata = "...METADATA contents...";

It's also possible to run the code directly. __inlinable is guaranteed to produce the same result as the inlined version when the inlined functions do not rely on side-effects. This is typically useful for running tests.

Keywords

inline

FAQs

Package last updated on 25 Apr 2025

Related posts