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

node-njsx

v1.0.2

Published

Write HTML template with dynamic Javascript!

Downloads

12

Readme

NJSX

image info

Use jsx in your web projects without React in a new and easy way!!

Table of Contents

Why?

I am really a fan of jsx syntax but i wanted to use jsx without react. So NJSX (New-JSX) has made.

JSX Syntax is really useful and handy when you are making template element in your web projects. You can do it in react very easily. But using njsx you can do it in no-react or pure html js projects.

Here is some example of N-JSX.

Using in Javascript DOM (Hard to read when component is big)

function userProfile(name, img_url) {
	//root container
	let container = document.createElement('div')
	container.setAttribute('class', 'user-profile')
	//profile pic element
	let profile = new Image()
	profile.src = img_url
	profile.height = 28
	profile.width = 28
	container.appendChild(profile)
	//name element
	let title = document.createElement('span')
	title.setAttribute('class', 'title')
	container.appendChild(title)
	document.body.appendChild(container)
}

userProfile("Kioma", "https://xyz.com/img.png")

Using template string (Unsafe in may case)

function userProfile(name, img_url) {
	//root container
	let container = document.createElement('div')
	container.setAttribute('class', 'user-profile')
	container.innerHTML = `
	<img src="${img_url}" height="28" width="28"/>
	<span class="title">${name}</span>
	`
	document.body.appendChild(container)
}

userProfile("Kioma", "https://xyz.com/img.png")

Using n-jsx (The easy and more readable way)

function userProfile(name, img_url) {
	//root container
	let container = <div class="user-profile">
		<img src={img_url} width="28" height="28"/>
		<span class="title">{name}</span>
	</div>
	document.body.appendChild(container)
}

userProfile("Kioma", "https://xyz.com/img.png")

Transpiled javascript form n-jsx

function userProfile(name, img_url) {
	let container = new (function () {
		this.node = document.createElement("div");
		this.node.class = "user-profile";
		this.node.append("\n\t\t");
		this.node.append(new (function () {
			this.node = document.createElement("img");
			this.node.src = img_url;
			this.node.width = "28";
			this.node.height = "28";
			return this.node;
		})());
		this.node.append("\n\t\t");
		this.node.append(new (function () {
			this.node = document.createElement("span");
			this.node.class = "title";
			this.node.append(name);
			return this.node;
		})());
		this.node.append("\n\t");
		return this.node;
	})();
	document.body.appendChild(container);
}
userProfile("Kioma", "https://xyz.com/img.png");

Installation

You can install this package via npm or yarn:

Usage

npm install node-njsx
# or
yarn add node-njsx

Using in projects

const njsx = require("node-njsx")

let my_jsx_code = `
let div = <div id="my_id">{new Date().toString()}</div>
document.body.append(div)
`
let js_code = njsx.toJS(my_jsx_code) // transpile into js code
let js_code = njsx.toAST(my_jsx_code) // get jsx ast generated by acorn.js
let js_code = njsx.toJSAST(my_jsx_code) // get transpiled javascipt ast 

Using the CLI

Install :

npm install node-njsx -g

Usages :

Transpile into js

njsx compile [filename] [output-filename] 

Transpile into js when changes happen.

njsx watch [filename] [output-filename]

Watch multiple files to transpile

njsx watch-more [file 1] [file 2] [file n] 

Examples

Check out the demo folder!