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

magicpatch

v0.12.4

Published

Adds IPython / Jupyter magic commands to IJavascript

Downloads

72

Readme

Magic Patch Logo

Build Status Coverage Status

magicpatch makes the Jupyter IJavascript kernel as close as possible to the IPython experience by adding %magic commands, !shell execution, {variable} substitution, and more! You can find examples in this Jupyter notebook.

Install

# IJavascript should already be installed before installing magicpatch
npm install -g magicpatch
magicpatch-install

Quick Demo

Demo Image

More demos here.

Table of Contents

Features

Wherever possible, this module tries to duplicate the features of IPython experience.

%magic

Magic commands traditionally start with % because it isn't a valid operator in Python. This package adds a number of default magics and allows you too define your own using the %addmagic command or through the $$.addMagic global function.

As a quick introduction to magics, here's a simple example of the %echo magic:

See the built in magics sectiono below for magics included in this package, or while running Jupyter you can use %lsmagic to list the names of all the magics or %quickref to get a quick guide to all the magics.

!cmd

Shell commands can be run quickly by starting the line with !. For example, !ls will run the command ls in the underlying shell and show the output.

var assignment

The output of magics can be assigned to variables. For example, mod = %require myPackage would load the myPackage npm module and assign the results to the variable mod.

{var} substitution

Variables can be used as inputs to magics by wrapping them in curly braces. For example, %echo {myVar} will print the contents of myVar.

help: ?%magic, %magic?, ??%magic, %magic??

If you want to know what a magic does, you can quickly get documentation using ? or ??. For example %echo? will print the documentation for the %echo magic, and %echo?? will print the source code for the %echo magic.

input caching

Input is cached in the global In and _ih arrays, where In[0] was the first text that you ran in your notebook. You can also access the last three inputs through the _i, _ii, and _iii global variables.

output caching

Similar to input caching, the output of your last three commands is stored in _, __, and ___. Note that there is no global Out array due to memory usage concerns.

%%cellmagic

Cell magics allow the entire Jupyter cell to be treated differently. For example %%script bash will treat the rest of the cell as a bash script. You can find a demo in this notebook.

%automagic

By default, all magics require the leading special symbol %, but you can turn that off for convenience using %automagic on. With automagic turned on, %echo can simply be typed echo.

Built in Magics

To date, the following magics have been added:

Line Magics

  • %addmagic (magicpatch only)
  • %automagic
  • %cat
  • %cd
  • %cp
  • %dhist
  • %dirs
  • %echo (magicpatch only)
  • %env
  • %hist
  • %history
  • %inspect (magicpatch only)
  • %load
  • %loadjs (magicpatch only)
  • %loadpy
  • %ls
  • %lsmagic
  • %mkdir
  • %mv
  • %notify (magicpatch only)
  • %npm
  • %pip
  • %popd
  • %pushd
  • %pwd
  • %quickref
  • %report (magicpatch only)
  • %require (magicpatch only)
  • %rm
  • %rmdir
  • %sx
  • %who
  • %whos

Cell Magics

  • %%script

Adding Magics

Adding your own magics is as easy as calling %addmagic %yourmagicname yourMagicFunction from Jupyter or $$.addMagic("%yourmagicname", {fn: yourMagicFunction}) from a module. Your magic will be passed an array of strings that were passed in on the command line. Similar to process.argv the first string is always your command name. For more advanced usage, such as adding documentation for your magic, creating cell magics, or accessing magicpatch internals to create fancy magics, refer to the AddingMagics.md documentation.

Contributions

This is a community project! All bug fixes, new magics, and contributions are welcome. I really want to encourage people to add new magics -- anything that helps people develop faster or have more fun would be a worthwhile contribution.

Contributors and participants are expected to be good humans. No jerks allowed.