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-requirejs-obfuscate

v0.1.3

Published

Obfuscate requirejs package names

Downloads

4

Readme

grunt-requirejs-obfuscate

Obfuscate requirejs package names

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 grunt-requirejs-obfuscate --save-dev

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

grunt.loadNpmTasks('grunt-requirejs-obfuscate');

The "requirejs_obfuscate" task

Overview

This plugin will obfuscate your package path names consistently, even across multiple files (if you're using a multi-file requirejs site, for instance).

It uses a salted SHA1 hash, truncated to 6 characters, and ensures the first character in any hash to be a letter.

This plugin is meant to be run on compiled requirejs code. I recommend cleaning up the compile directory of unnecessary files before running this task using grunt-contrib-clean.

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

grunt.initConfig({
  requirejs_obfuscate: {
    options: {
        dir: 'www/js',
        salt: 'salt',
        root: 'com',
        length: 6,
        quotes: 'double',
        exclude: [
            'lib/require.js',
            'lib/jquery-2.0.3.js'
        ],
        output: false
    }
  },
})

Options

options.dir

Type: String

This must be set to the folder where your compiled requirejs files are. From your require.js options.js file, combine dir and baseUrl without a trailing slash.

options.salt

Type: String Default value: 'salt'

This is the salt that will be used to hash each of your package paths and classes.

options.root

Type: String

This is required. It must be set to the root folder where your packages reside. This does not currently support multiple root packages.

options.length

Type: Integer Default value: 6

The length of each hash. Allows a range of 3-16 characters. Higher numbers reduce chance of duplicates. The default value of 6 seems like a safe length for most projects.

options.quotes

Type: String Default value: 'double'

Set this to whatever your package paths are wrapped with (single or double quotes). You can also set this to "'" or '"'. For example, uglify converts single quotes into double quotes, so if you are not uglifying your code, you might set this to "single" and if you are, you would leave this out or set it to "double".

options.exclude

Type: Array Default value: []

This is an array of files to exclude from hashing. Most of the time you won't need to set this to anything, but you never know.

options.output

Type: Boolean Default value: false

Set to true if you want to see each package path and their respective hashes output into the terminal.

Usage Examples

Default Options

In this example, your compiled files are in the "src/js" directory and your package root is "app".

grunt.initConfig({
  options: {
      dir: 'src/js',
      root: 'app'
  }
})

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

This code does not currently have any unit tests. It could probably also use some better methodology to find and replace hashes, such as more advanced regex.

I have tested this on a real project with multiple files and it works perfectly.

TODO: Prevent duplicate hashes for the filename part (just in case).

Release History

0.1.0 - Initial Release 0.1.2 - Added some extra options 0.1.3 - Remove package debug loggin