Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aretecode/likeaboss
export for nodejs or web like a boss, easy, fast, fluent, & tiny.
https://github.com/aretecode/likeaboss
babel boss dynamic export exports fluent module typescript
Last synced: 4 days ago
JSON representation
export for nodejs or web like a boss, easy, fast, fluent, & tiny.
- Host: GitHub
- URL: https://github.com/aretecode/likeaboss
- Owner: aretecode
- Created: 2017-04-24T23:52:47.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-04-25T10:23:54.000Z (over 7 years ago)
- Last Synced: 2024-10-04T18:46:51.478Z (about 1 month ago)
- Topics: babel, boss, dynamic, export, exports, fluent, module, typescript
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# ๐ด likeaboss
[![NPM version][likeaboss-npm-image]][likeaboss-npm-url]
[![MIT License][license-image]][license-url]
[![fliphub][gitter-badge]][gitter-url]
[![fluents][fluents-image]][fluents-url][likeaboss-npm-image]: https://img.shields.io/npm/v/likeaboss.svg
[likeaboss-npm-url]: https://npmjs.org/package/likeaboss
[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat
[license-url]: https://spdx.org/licenses/MIT
[gitter-badge]: https://img.shields.io/gitter/room/fliphub/pink.svg
[gitter-url]: https://gitter.im/fliphub/Lobby
[fluents-image]: https://img.shields.io/badge/โ-fluent-9659F7.svg
[fluents-url]: https://www.npmjs.com/package/flipchain> 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
```bash
yarn add likeaboss
npm i likeaboss --save
```## [๐ documentation](./docs)
## [๐ฌ tests](./tests)
## [๐ examples](./examples)```js
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](#output)
only used when the "import"er / client does
```js
import {PluginEh} from 'your-lib'
```or
```js
import ClassOrFunction from 'your-lib'
const {PluginEh} = ClassOrFunction
```## [๐ณ diving deeper examples](./examples)
#### โ fluent function export
```js
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](./test)
```js
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`
```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
```js
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)
```js
Exports.module(module).props({Canada}).end()
```# ๐ฝ exports
> file size (~700 bytes)### from
```js
// imports the `from` static fn
const from = require('likeaboss/from')const Export = require('likeaboss')
```### generate
> ๐งโ warning, experimental
```js
// 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](./bench)
using [๐๏ธโ bench-chain](https://www.npmjs.com/package/bench-chain)```js
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](#object-fn-with-requires)
- `console.log({})`: ~ โฒ 35000ms / 35ms
- fluent: ~ โฒ 1300 microseconds / 1.3ms
- optimized: ~ โฒ 400 microseconds / .4ms
- `exports = module.exports = ...`: ~ โฒ 100-200 microseconds / .1ms-.2ms# ๐ญ
### [output](./examples/example-output-pseudo.js)> example generated output pseudo code
```js
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)
```