New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@fxjs/handbag

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fxjs/handbag

require resources directly 👝

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-86.96%
Maintainers
1
Weekly downloads
 
Created
Source

👝 @fxjs/handbag

Build Status NPM version

Pre-requisite

  • fibjs >= 0.26.0

Usage

npm install @fxjs/handbag

Sample

register one compiler for .pug file

const fxHandbag = require('@fxjs/handbag')

const fpug = require('fib-pug')
function registerPugAsHtml (vbox) {
    const compilerOptions = {
        filters: {
            typescript: require('jstransformer-typescript').render,
            stylus: require('jstransformer-stylus').render,
        }
    }

    fxHandbag.vboxUtils.setCompilerForVbox(vbox, {
        suffix: '.pug',
        compiler: (buf, info) => fxHandbag.vboxUtils.wrapAsString(
            fpug.renderFile(info.filename, compilerOptions)
        )
    })
}

const vm = require('vm')

vbox = new vm.SandBox(moduleHash)
registerPugAsHtml(vbox)

// just require one pug as rendered html string
const renderedHtml = vbox.require('./test.pug', __dirname)

you can also do like this:

const compilerOptions = {
    filters: {
        typescript: require('jstransformer-typescript').render,
        stylus: require('jstransformer-stylus').render,
    }
}

const vbox = new vm.SandBox(moduleHash)
fxHandbag.registers.pug.registerPugAsHtml(vbox, { compilerOptions })

const renderedHtml = vbox.require('./test.pug', __dirname)

APIs

vboxUtils

vboxUtils is some basic operation for one vbox generated by new vm.SandBox(...)

setCompilerForVbox(vbox: Class_SandBox, options: SetCompilerForVBoxOptions)

set one compiler function for vbox, the compiler is used for vbox.setModuleCompiler.

interface SetVboxOptions {
    suffix: string|string[],
    compiler: Function,
    compile_to_iife_script?: boolean
}

registers

Common Option

register functions support options below:

{
    // compilerOptions passed to render of register.
    compilerOptions: {...},
    // timeout that module keep required file id, if it is 0, keep module always
    burnout_timeout: {...}
}

plain.registerAsPlain(vbox, options)

  • options.suffix: default ['.txt']

register compiler to require file as its plain text

pug.registerPugAsRender(vbox, options)

  • options.suffix: default ['.pug', '.jade']

register compiler to require pug file as pug renderer

pug.registerPugAsHtml(vbox, options)

  • options.suffix: default ['.pug', '.jade']

register compiler to require pug file as rendered html

stylus.registerStylusAsCss(vbox, options)

  • options.suffix: default ['.styl', '.stylus']

register compiler to require stylus file as rendered html

typescript.registerTypescriptAsModule(vbox, options)

  • options.suffix: default ['.ts']

register compiler to require typescript file as one valid module

typescript.registerTypescriptAsPlainJavascript(vbox, options)

  • options.suffix: default ['.ts']

register compiler to require typescript file as plain javascript string.

rollup.registerAsModule(vbox, options)

  • options.suffix: default ['.ts', '.tsx']
  • options.rollup

register compiler to require typescript file as module.

require

rollup.registerAsPlainJavascript(vbox, options)

  • options.suffix: default ['.ts', '.tsx']
  • options.rollup

register compiler to require typescript file as rolluped plain javascript string.

require

vue.registerVueAsRollupedJavascript(vbox, options)

  • options.suffix: default ['.vue']
  • options.rollup
  • options.rollupPluginVueOptions: default {}, options passwd to rollup-plugin-vue
  • options.transpileLib: default 'babel'
    • any value equals to false: no transpile
    • 'babel': transpile component with babel
    • 'buble': transpile component with buble

register compiler to require typescript file as rolluped plain javascript string

NOTICE it's not recommend use async/await in vue component, if you do so, the transpiled vue component's size would be large.

it would compile vue component js to 'es5' by default. If <script lang="ts"> set, it always transpile component js with typescript

require

image.registerImageAsBase64(vbox, options)

  • options.suffix: default ['.png', '.jpg', '.jpeg', '.gif', '.bmp']

register compiler to require image file as base64 string

Others

registerOptions.rollup

There's register based on rollup, its registerOptions has those options:

  • options.rollup.bundleConfig: default {}, config passed to
    • const bundle = rollup.rollup({...})
  • options.rollup.writeConfig: default {}, config passed to
    • bundle.write({...})
    • bundle.generate({...})
  • options.rollup.onGenerateUmdName: default (buf, info) => 's'. generate name for rollup's umd/iife mode

registerOptions.burnout_timeout

In some cases, we want vbox to remove required module by ID after burnout_timeout.

For example, you are developing one website's user profile page, which rendered from path/user-profile.pug, you serve it with http.Server and mq.Routing, and require the pug file as require('path/user-profile.pug', __dirname) with special vbox generated by registers in @fxjs/handbag or by your own manual registering. You change the pug file, then you wish the next calling to require('path/user-profile.pug', __dirname) would return the latest file resource. So, you need remove the required content every other times(such as 300ms), which is burnout_timeout.

All reigsters's option in @fxjs/handbag supports burnout_timeout option : )

License

GPL-3.0

Copyright (c) 2018-present, Richard

Keywords

FAQs

Package last updated on 06 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc