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

unix-terminal-emulator

v4.0.3

Published

Emulates a Unix terminal inside the DOM!

Downloads

35

Readme

Terminal Emulator

ci (build and test) coverage issues npm score dependencies minified size downloads license

Preview

NPM Repository - CodeSandbox example

Inspired by TypewriterJS.


Installation

You can install it via your preferred package manager:

npm i --save unix-terminal-emulator
yarn add unix-terminal-emulator

You can use the CDN version for simple imports in HTML:

<script src="https://unpkg.com/unix-terminal-emulator@latest/dist/core.js"></script>

Documentation

Checkout the wiki of this repository for the documentation. Generated with TypeDoc!

Example usage

For more advanced examples, please click this link.

Browser

import UnixTerminalEmulator from "unix-terminal-emulator"

const terminal = new UnixTerminalEmulator()
const command = {
	text: "echo Hello, World!",
	writeSpeed: "neutral",
	output: "Hello, World!",
	pauseBeforeOutput: 500,
}
terminal.writeCommand(command).run(() => {
	console.log("Done!")
})

React

import React from "react"
import UnixTerminalEmulator from "unix-terminal-emulator"

export default function App() {
	const command = {
		text: "echo Hello, World!",
		writeSpeed: "neutral",
		output: "Hello, World!",
		pauseBeforeOutput: 500,
	}
	return (
		<div className="App">
			<UnixTerminalEmulator
				onInit={emulator => {
					emulator.writeCommand(command).run(() => {
						console.log("Done!")
					})
				}}
			/>
		</div>
	)
}

Do's and don'ts

Below are a few examples of do's and don'ts regarding building a command sequence.

const terminal = new UnixTerminalEmulator()

:heavy_check_mark: Chain the commands you want to run in sequence before calling run (this is by design):

// Chaining commands is by design
terminal
	.writeCommand({
		text: "echo foo",
		writeSpeed: "neutral",
		output: "foo",
		pauseBeforeOutput: 500,
	})
	.pause(1000)
	.writeCommand({
		text: "echo bar",
		writeSpeed: "neutral",
		output: "bar",
		pauseBeforeOutput: 500,
	})
	.run()

:heavy_check_mark: Call the sequence building commands in a non-chain fashion, as long as the run method is called last (this is by design):

terminal.writeCommand({
	text: "echo foo",
	writeSpeed: "neutral",
	output: "foo",
	pauseBeforeOutput: 500,
})
terminal.pause(1000)
terminal.writeCommand({
	text: "echo bar",
	writeSpeed: "neutral",
	output: "bar",
	pauseBeforeOutput: 500,
})
terminal.run()

:warning: Adding commands to the sequence BEFORE run has finished will queue them for the current sequence (this is timing dependent and not recommended).

terminal
	.writeCommand({
		text: "echo foo",
		writeSpeed: "neutral",
		output: "foo",
		pauseBeforeOutput: 500,
	})
	.run()
// The command added bellow will be added to the current sequence
terminal.writeCommand({
	text: "echo bar",
	writeSpeed: "neutral",
	output: "bar",
	pauseBeforeOutput: 500,
})
// The command bellow in the setTimeout will not run in the first sequence, a new call to the run method is required in order to run it
setTimeout(() => {
	terminal.writeCommand({
		text: "echo baz",
		writeSpeed: "neutral",
		output: "baz",
		pauseBeforeOutput: 500,
	})
}, 10000)

:x: Calling the run method on a terminal instance before the previous call has finished will result in unexpected behavior

terminal
	.writeCommand({
		text: "echo foo",
		writeSpeed: "neutral",
		output: "foo",
		pauseBeforeOutput: 500,
	})
	.writeCommand({
		text: "echo bar",
		writeSpeed: "neutral",
		output: "bar",
		pauseBeforeOutput: 500,
	})
	.run()
terminal.run() // this brakes the sequence and will result in unexpected behavior

:x: Creating 2 terminal instances with the same wrapper and cursor ID will result in unexpected behavior

const terminal1 = new UnixTerminalEmulator({
	wrapperId: "same-wrapper-id",
	cursorId: "same-cursor-id",
})
const terminal2 = new UnixTerminalEmulator({
	wrapperId: "same-wrapper-id",
	cursorId: "same-cursor-id",
})
terminal1
	.writeCommand({
		text: "echo foo",
		writeSpeed: "neutral",
		output: "foo",
		pauseBeforeOutput: 500,
	})
	.run()
terminal2
	.writeCommand({
		text: "echo foo",
		writeSpeed: "neutral",
		output: "foo",
		pauseBeforeOutput: 500,
	})
	.run()

Performance

Bellow are performance charts based on different versions of the app. Click here for a detailed explanation about how the performance was tested. Click here for an interactive version of the graphs.

| Time per Run in MS | Time per Command in MS | | ------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | | Time per run in MS graph of all versions | Time per command in MS graph of all versions |