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

robscure

v1.0.13

Published

Obfuscates modules defined using R.js

Downloads

1

Readme

robscure

GruntJs task to further minify and obfuscate the keys defined using R.js https://www.npmjs.com/package/robscure

Premise

R.js is an implementation for dependencies management, freely inspired by RequireJs and Angular dependency injection mechanism. https://github.com/RobertoPrevato/R.js R.js has a syntax which is similar to the one of RequireJs, but follows a different approach and aims at simplicity.

R(key, dependencies, function); to define an object with its dependencies

R(key); to require an object

R([key1, key2, key3, ...]) to require an array of objects

robscure is a GruntJs task to further minify and obfuscate the keys defined using R.js. Example: Let's imagine a single web application which includes multiple bundled and minified JavaScript files, for different parts of the application.

  • common.min.js -> common functions
  • profile.min.js -> for profile page
  • settings.min.js -> for settings page
  • [...]

Normally after minification the keys of the modules would stay in clear, so:

R("model", [], function () { ... });
R("dashboard", ["model"], function () { ... });

Using robscure task is possible to further obfuscate the code, obtaining something like:

R("♥", [], function () { ... });
R("♪", ["♥"], function () { ... });

Limitations

robscure doesn't support the following: variable keys: module keys must be constant strings.

//NOT supported:
var a = "somekey";
R(a, [], function () { ... });
R("some-module", [a], function (dep) { ... });

dynamic dependencies: module dependencies must be a constant array

//NOT supported:
var deps = [];
deps.push(aKey);
R("module-name", deps, function () { ... });

calls to R function using .call or .apply

//NOT supported:
R.call(null, "module-name", [], function { ... });
R.apply(null, ["module-name", [], function { ... }]);

Getting Started

This plugin requires Grunt ~0.4.5

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install robscure --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('robscure');

The "robscure" task

Overview

In your project's Gruntfile, add a section named robscure to the data object passed into grunt.initConfig().

grunt.initConfig({
  robscure: {
    website: {
      // these are all the built or minified files of all areas: the task will look for each
      // for each file, a new file will be generated, with obfuscated module names
      areas: [
        "../scripts/main.min.js",
        "../scripts/area-one.min.js",
        "../scripts/area-two.min.js",
        "../scripts/area-three.min.js"
      ],

      // allows to specify whether an exception should be thrown if duplicated modules names are found across multiple areas (default: true)
      exceptionIfDuplicated: true,

      // the suffix to use for generated files (default: ".obs")
      fileSuffix: ".obs"
    }
  }
});

Options

options.areas

Type: Array

Array containing paths to all the built or minified files of all areas: the task will look for all modules defined in all areas, and for each file generate a new file with obfuscated dependencies. It is recommended to use minified files, not built files.

options.fileSuffix

Type: String Default value: .obs

Suffix to apply to output filenames.

options.getFileName

Type: Function Default value: null

If specified, allows to define a function that returns a filename for new files.

options.chars

Type: String Default value: Я♪♫♦♥♠♣zyxwvutsrqponmlkjihgfedcba_^][ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#!`

Characters that can compose the modules key.

options.exceptionIfDuplicated

Type: Boolean Default value: true

A boolean indicating whether to throw an exception if duplicated modules definitions are found across all input files. When defininig multiple modules, it's important to avoid to accidentally override modules defined in different files.

Usage Examples

Default Options

In this example four minified files that relate to different areas of the application are processed to obfuscate the modules definitions in all of them. In details, the task performs the following operations:

  1. reads the contents of each input file
  2. lists all modules defined in all files
  3. assigns to each module a new key
  4. for each input file generates a new file, with contents in which the module names have been replaced with the new keys
grunt.initConfig({
  robscure: {
    website: {
      areas: [
        "../scripts/main.min.js",
        "../scripts/area-one.min.js",
        "../scripts/area-two.min.js",
        "../scripts/area-three.min.js"
      ]
    }
  }
});

The names of the output files are obtained adding a suffix to each input file name, so it is only necessary to specify the input files path.

Release History

2015-05-30 first version released