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

likeaboss

v0.1.4

Published

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

Downloads

39

Readme

🕴 likeaboss

NPM version MIT License fliphub fluents

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

works with:

  • 📼 es5
  • 🍬 es6+
  • 🌊 typescript
  • 🗼 babel
  • 🕸 web
  • 🔙🔚 node
  • other?

📦 usage

yarn add likeaboss
npm i likeaboss --save

🌐 documentation

🔬 tests

📘 examples

const Export = require('likeaboss')

const pkg = require('./package.json')

// export directly on the module without module.exports
// or do `exports = module.exports = ` when using .export
Export
  .module(module)

  // main export to be decorated
  .main(ClassOrFunction)

  // export for web usage when needed
  .web('your-lib-name')

  // load dynamic
  .dir(__dirname + '/your-dist-folder')

  // and all other props you want to use
  .props({version: pkg.version})

  // only `required` when used
  .dynamics([
    {name: 'PluginEh', path: '/PluginEh'},
    {name: 'PluginOh', path: '/PluginOh'},
  ])

  // finish
  .end()

dynamics

see the output

only used when the "import"er / client does

import {PluginEh} from 'your-lib'

or

 import ClassOrFunction from 'your-lib'
 const {PluginEh} = ClassOrFunction

🕳 diving deeper examples

⛓ fluent function export

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 function 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'],
  },
})

module

no need to reassign exports and modules ([exports] is optional 2nd arg)

Exports.module(module).props({Canada}).end()

👽 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

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
  • exports = module.exports = ...: ~ ⏲ 100-200 microseconds / .1ms-.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)