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

grunt-at-class

v0.2.0

Published

Wrap any JavaScript file in an Aria Templates class definition.

Downloads

7

Readme

Wrap any JavaScript file in an Aria Templates class definition.

It allows to create either plain classes or a singleton.

Getting Started

This plugin requires Grunt ~0.4.4.

Install the plugin with npm install grunt-at-class or put it in your package.json and add the following line to your Gruntfile.js

grunt.loadNpmTasks("grunt-eco-amd");

The "at_class" task

at_class is a multitask that generates a JavaScript file with a class definition from a source file.

Task targets, files and options may be specified according to the grunt Configuring tasks guide.

Overview

In your project's Grunfile.js add a section named at_class to the object passed to grunt.initConfig().

at_class: {
	myLibrary: {
		src: ['path/to/the/library/to/wrap.js'],
		dest: 'target/wrappedLibrary.js',
		options: {
			singleton: true,
			exports: "myLibrary",
			classpath: "wrapped.Library",
			license: "path/to/library/license"
		}
	}
}

Options

classpath

Classpath of the generated Aria Templates class.

singleton

Wheter the generated class should be a singleton. Defaults to true.

exports

Name of the variable exported by the wrapped script.

If the generated class is a singleton, this variable will be accessible at the specified classpath, otherwise it'll be used as a constructor when an instance of that classpath is created.

license

Optional license header to include along with the source code.

Usage Examples

singleton

Given the following library

var trivial = (function () {
	return {
		getOne : function () {
			return 1;
		}
	}
})();

The following configuration

at_class: {
	myLibrary: {
		src: ['somewhere/trivial.js'],
		dest: 'target/trivial.js',
		options: {
			exports: "trivial",
			classpath: "wrapped.TrivialLibrary"
		}
	}
}

generates a class that can be used like this

Aria.load({
	classes : ["wrapped.TrivialLibrary"],
	oncomplete : function () {
		console.log(wrapped.TrivialLibrary.getOne());  // -> 1

		// trivial would be undefined
	}
})

simple class

The task can be used also to generate plain classes, consider the following example

var Useless = function (name) {
	this.name = name;
};

Useless.prototype.whoAmI = function () {
	return this.name;
};

The following configuration

at_class: {
	myLibrary: {
		src: ['somewhere/useless.js'],
		dest: 'target/useless.js',
		options: {
			exports: "Useless",
			classpath: "wrapped.UselessLibrary",
			singleton: false
		}
	}
}

generates a class that can be used like this

Aria.load({
	classes : ["wrapped.UselessLibrary"],
	oncomplete : function () {
		var robert = Aria.getClassInstance("wrapped.UselessLibrary", "Robert");
		var peter = Aria.getClassInstance("wrapped.UselessLibrary", "Peter");
		
		robert.whoAmI(); // -> Robert
		peter.whoAmI(); // -> Robert
	}
})

Release History

0.1.0

  • Creation of the project
  • Support singleton and plain class
  • Include license information

License

This project is licensed under the Apache License v2.0. Read the license here.