JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 22
  • Score
    100M100P100Q52176F

export for nodejs or web like a boss, easy, fast, & tiny.

Package Exports

  • likeaboss

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (likeaboss) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

๐Ÿ•ด likeaboss

NPM version MIT License fliphub

export like a boss with functions, dynamic and static requires, and module support; easy, fast & tiny.

works with:

  • ๐Ÿ“ผ es5
  • ๐Ÿฌ es6+
  • ๐ŸŒŠ typescript
  • ๐Ÿ—ผ babel
  • ๐Ÿ•ธ web
  • ๐Ÿ”™๐Ÿ”š node
  • other?

๐Ÿ“ฆ usage

yarn add likeaboss
npm i likeaboss --save

๐ŸŒ documentation

๐Ÿ”ฌ tests

๐Ÿ“˜ examples

screen shot 2017-04-24 at 4 48 22 pm

โ›“ fluent fn

const Export = require('likeaboss')

function fn(options, callback) {
  // magical things when called as a function
}

const Canada = {canada: true}

exports = module.exports = Export.export(module.exports)
  .fn(fn)
  .props({Canada})
  .end()

fluent fn with requires

dynamic and static requires, dynamic requires only are required when they are used

see the tests

const Export = require('likeaboss')

function fn() {
  console.log('called as a function')
}

exports = module.exports = Export.export(module.exports)
  .dir(__dirname)
  .fn(fn)
  .dynamics('src', ['Boss'])
  .dynamics('src/plugins', ['BossPlugin'])
  .dynamics('', [{path: 'package.json', name: 'pkg'}])
  .statics('', ['Statics'])
  .end()
๐Ÿฆ importing:

requires ./eh/src/Boss.js

  import {Boss} from './eh'
  import eh from './eh'

  eh('callable as a function!')
  console.log(Boss)

  // requires the BossPlugin
  console.log(eh.plugins.BossPlugin)

object fn with requires

same as with fluent, but using object syntax

const Export = require('likeaboss')

exports = module.exports = Export.from({
  target: module.exports,
  dir: __dirname,
  fn: func,
  props: {Eh, Canada},
  dynamics: {
    'src': ['Boss'],
    'src/plugins': ['BossPlugin'],
  },
  statics: {
    '': ['Statics'],
  },
})

๐Ÿ‘ฝ exports

file size (~700 bytes)

from

// imports the `from` static fn
const from = require('likeaboss/from')

const Export = require('likeaboss')

generate

๐Ÿšงโš— warning, experimental

// export.js
const gen = require('likeaboss/gen')

function fn(options, callback) { /* magic */ }

const Eh = {eh: true}
const Canada = {canada: true}

exports = module.exports = Exports.export()
  .dir(__dirname)
  .fn(fn)
  .dynamics('src', ['Boss'])
  .dynamics('src/plugins', ['BossPlugin'])
  .statics('', ['Statics'])
  .props({Eh, Canada})
  .web('eh')
  .end()
  .toString()

console.log(exports)

// outputs exporting string
// node export.js > index.js

โš–๏ธ benchmark

using ๐Ÿ‹๏ธโ›“ bench-chain

screen shot 2017-04-24 at 5 51 21 am
optimized x 30,975 ops/sec ยฑ13.48% (50 runs sampled)
fluent x 20,434 ops/sec ยฑ3.52% (73 runs sampled)

times with last example

  • console.log({}): ~ โฒ 35000ms / 35ms
  • fluent: ~ โฒ 1300 microseconds / 1.3ms
  • optimized: ~ โฒ 400 microseconds / .4ms
  • module.exports = {}: ~ โฒ 200 microseconds / .2ms

๐Ÿญ output

example generated output pseudo code

function fn() {}
const ex = {
  Eh: {eh: true},
  Canada: {canada: true},
  Boss: 'boss',
  plugins: {},
  Statics: {static: true},
  __esModule: true,
}

Object.defineProperty(ex.plugins, 'BossPlugin', {
  get() {
    return 'boss'
  },
})

ex.default = ex

Object.assign(fn, ex)