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

export-context

v0.0.10

Published

Get the methods that are not exports as context. these methods becomes possible operations, such as unit testing

Downloads

15

Readme

export-context

export-context

Build Status

A method that has not been export can be run via the context. It will be able to unit test of unexport methods. Further, if necessary of dom can test by creating a document in global. Esnext code is transpile using the babel.

install

npm install export-context --save-dev

# or if using yarn

yarn

setup

import ExportContext from 'export-context';

// configure option
const options = {
    basePath: './',
    babel: {
        presets: ['latest'],
        plugins: ['transform-runtime']
    },
    dom: true,
    html: '<div class="box">example</div>',
    vm: {
        filename: <string>,
        lineOffset: <number>,
        columnOffset: <number>,
        displayErrors: <boolean>,
        timeout: <number>,
        breakOnSigint: <boolean>
    }
};

const modules = {
    '_': 'lodash',
    '$': 'jquery'
};

const html = '<span class="comment">example commnet</span>';

const exportContext = new ExportContext;

// add dependent modules setting
exportContext.addModules(modules);

// add html code
exportContext.addHtml(html);

// get context
const ctx = exportContext.run('TARGET/FILE/PATH.js', options);

// ctx has unexported method
// ... some code ...

// clear sandbox dom settings
exportContext.clear()

If the environment variable NODE_ENV is specified, it is reflected in the global variable and window object

// set process.env.NODE_ENV = 'test'

global.NODE_ENV // => test
window.NODE_ENV // => test

API

setFilepath(filePath = '')

Set default load file path

addModules(modules = {}, sandbox = {})

Add the module to require at the time of context run.

addHtml(html = '')

Add the html to the context that you want to run.

clear()

Remove the dom in the global from the execution context.

run(filePath = '', options = {})

Run the contents of the passed file path. You can have the option, if necessary. Executed context will be returned. The options are as follows.

If already in the path has been set (using the setfilePath()), run(options) method can be performed only in the only option.

Options

basePath

Specify the directory to be a base to load the file to be executed. (default: Projectroot).

babel

Code using esnext will run transformer pile in the babel. You can set the options to be passed to the babel. (default: null)

dom

If you run the code using DOM, please be true to this option. To provide the necessary properties to global, you will be able to use the dom api. (default: null)

html

If you want to set a pre-html adds html. (default: null)

example

see at below.

License

MIT License