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

cubegenjs

v0.1.11

Published

Protecting and Optimizing your JavaScript Source Code

Downloads

686

Readme

CubegenJS

NPM Version NPM Downloads

Protecting and Optimizing your JavaScript Source Code.

When do you need this module?

  • Hide keys or secret algorithms in a project.
  • Want to detect if the project source code is changed.
  • Protecting application from illegal distribution.
  • Optimizing nodejs project source code.

Table of contents

Installation

This is a Node.js module available through the npm registry.

This module can be used on node or web projects develop with Node.js version 18.0 or higher.

Installation is done using the npm install command:

npm install --save-dev cubegenjs

or

yarn add --dev cubegenjs

Configuration and Usage

You need create two configuration files cg.builder.js and cb.protector.js.

Generate these files with the command:

npx cubegen init

After that, you have to select the target environment NodeJS or Web Browser based on your project type.

To use protector, you mush import cg.protector.js file in your project.

For example Express.js project in /src/index.js:

import express from 'express'
import '../cg.protector.js'

const app = express()
app.listen(3000, () => {
    ...
})

or React.js project in /src/App.jsx:

import { useState } from 'react'
import '../cg.protector.js'

function App() {
    ...
}

After everything is done, build your project with the command:

npx cubegen build

Options

The module use cg.builder.js and cb.protector.js files to define how the module works. Each properties and methods can be set according to your project needs.

Cubegen CLI

Cubegen provides a terminal interface to manage your project.

CLI options of npx cubegen:

-v, --version
-h, --help

commands:
init [options]          initialize cubegen configuration
build [options]         building your project to distribution code

options:
-r, --root <string>     relative root project directory (default: "./")

Cubegen Builder

The cg.builder.js file contains the rules for how your project will be transformed with bundlers and obfuscators.

appKey

Type: string Default: <generate by system>

Application key for generate private keys inner your code. You can use a custom random characters.

target

Type: string Default: <generate by system>

Target where your application will be run in production. Available options: node and browser

buildCommand

Type: string Default: npm run build

⚠️ Only available in web project.

Command to build your web project. The build command example: npm run build or yarn build.

codeBundlingOptions

Type: object Default: {}

⚠️ Only available in node project.

Bundler option to optimize your code with parcel.

Example:

codeBundlingOptions: {
    rootDir: './',
    outDir: './dist',
    entries: [
        'src/main.js',
        'src/worker.js'
    ],
    staticDirs: [
        'public',
        'storages'
    ],
    buildMode: 'production'
}

codeObfuscationOptions

Type: object Default: {}

Obfuscation option to obfuscate your protector code with javascript-obfuscator.

Example:

codeObfuscationOptions: {
    target: 'node',
    seed: '0fddc96ac6cad3b0',
    controlFlowFlattening: true,
    controlFlowFlatteningThreshold: 1,
    ...
    compact: true,
    simplify: true
}

See more option in https://github.com/javascript-obfuscator/javascript-obfuscator?tab=readme-ov-file#options

Cubegen Protector

The cg.protector.js file is the protection algorithm for your project. Your code in cg.protector.js will be fully obfuscated after the build process is complete.

onStart()

This method will be called after protector is started.

Example:

onStart(() => {
    console.log('Cubegen protector is starting.')
})

onDocumentLoaded()

⚠️ Only available in web project.

This method will be called after after DOM loaded.

Example:

onDocumentLoaded(() => {
    console.log('Web document is loaded.')
})

onDomainNotAllowed()

⚠️ Only available in web project.

This method will be called if site host is not in the whitelist.

Example only allow hosted web app in localhost:*:

const domainLockingOptions = {
    enabled: true,
    whitelist: [
        'localhost',
        'localhost:\\d+',
        '127.0.0.1:\\d+'
    ]
}
onDomainNotAllowed(domainLockingOptions, () => {
    window.location.host = 'https://your_site.com'
})

onModifiedCode()

⚠️ Only available in node project.

This method will be called if distributed code changed or not match with signiture.

Example:

const modifiedCodeOptions = {
    enabled: true
}
onModifiedCode(modifiedCodeOptions, () => {
    console.log('Source code is changed.')
    process.exit()
})

onIntervalCall()

This method will be called continuously.

Example:

const intervalCallOptions = {
    enabled: false,
    eventLoopInterval: 5000
}
onIntervalCall(intervalCallOptions, () => {
    // call monitoring service or do something
})

Support

The main forum for free and community support is the project Issues on GitHub.