npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@a-la/export

v1.5.0

Published

A set of rules for ÀLaMode to transpile ES6 export statements into module.exports assignments.

Downloads

71

Readme

@a-la/export

npm version

@a-la/export is a a set of rules for Àlamode to transpile ESM modules' export statements into CJS modules' module.exports statements in Node.js.

yarn add @a-la/export

Table Of Contents

API

The ÀLaImport is the default export and an array containing a sequence of rules for Replaceable.

import ÀLaExport from '@a-la/import'

Output Example

The set of rules changes export to module.exports statements. module.exports will be assigned the value of the default export if it is present, and all named exports will be assigned to module.exports after that.

/**
 * Example 1.
 */
export const example1 = async () => {
  console.log('named export 1')
}

/**
 * Example 2.
 */
export function example2() {
  console.log('named export 2')
}

/**
 * Example 3.
 */
function example3() {
  console.log('named export 3')
}

/**
 * Example 4.
 */
const example4 = async () => {
  console.log('named export 4')
}

export { example3, example4 as alias4 }

/**
 * Default Class Example.
 */
export default class Example {
  /**
   * A constructor for the example.
   * @constructor
   */
  constructor() {
    console.log('default export')
  }
}



/**
 * Example 1.
 */
       const example1 = async () => {
  console.log('named export 1')
}

/**
 * Example 2.
 */
       function example2() {
  console.log('named export 2')
}

/**
 * Example 3.
 */
function example3() {
  console.log('named export 3')
}

/**
 * Example 4.
 */
const example4 = async () => {
  console.log('named export 4')
}



/**
 * Default Class Example.
 */
               class Example {
  /**
   * A constructor for the example.
   * @constructor
   */
  constructor() {
    console.log('default export')
  }
}


module.exports = Example
module.exports.example1 = example1
module.exports.example2 = example2
module.exports.example3 = example3
module.exports.alias4 = example4

Unnamed Default

When there's an unnamed default such as export default class {} or export default async function () {}, it will be replaced in place. Since all named exports will be assigned at the end anyway, there shouldn't be a problem.

export function example1() {}

export default class {
  /**
   * An unnamed default class.
   */
  constructor() {}
}

export function example2() {}
function example1() {}

module.exports=class {
  /**
   * An unnamed default class.
   */
  constructor() {}
}

       function example2() {}

module.exports.example1 = example1
module.exports.example2 = example2

Export From

When exporting from another module, some private internal variables are created. It is currently not possible to export a default either as named, or as default from more than one module.

export const example = () => {}

export {
  default,
  example2,
  example3 as alias3,
} from 'test'


const example = () => {}





const $test = require('test');


module.exports = $test
module.exports.example = example
module.exports.example2 = $test.example2
module.exports.alias3 = $test.example3
export const example = () => {}

export {
  default as example2,
} from 'test'
const example = () => {}



const $test = require('test');


module.exports.example = example
module.exports.example2 = $test

Limitations

  • If the default export is a primitive type such as boolean or number, it is not possible to use named exports as well, because module.exports will be binded to the primitive, and further assignments to module.exports.namedExport will not have any effect.

    module.exports = 'STRING' // primitive (string)
    module.exports.example = function () {}
    console.log(module.exports.example) // undefined
  • Serial exports of declarations are not possible as it's difficult to parse them using a regular expression.

    // not possible
    export const
      a = 'test',
      b = () => {}
  • When using the export from statement, a private variable for the targeted module will be created, e.g., export { default } from test will create const $test = require('test') variable, therefore a collision could happen if a variable with such name was declared in the code.

Checklist

  • [x] export { name1, name2, …, nameN };

  • [x] export { variable1 as name1, variable2 as name2, …, nameN };

  • [x] export let name1, name2, …, nameN; // also var, const

  • [ ] export let name1 = …, name2 = …, …, nameN; // also var, const

  • [x] export function FunctionName(){...}

  • [x] export class ClassName {...}

  • [x] export default expression;

  • [x] export default function (…) { … } // also class, function*

  • [x] export default function name1(…) { … } // also class, function*

  • [x] export { name1 as default, … };

  • [ ] export * from …;

  • [x] export { name1, name2, …, nameN } from …;

  • [x] export { import1 as name1, import2 as name2, …, nameN } from …;

  • [x] export { default } from …;

  • [ ] Make sure that comments like export function(/* string */ adc) {} are functional.

Positions Preservation

The transform will attempt to preserve line and column numbers as they are for easier generation of source maps by alamode. In future, this might change.

Copyright