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

animate-compress-fills

v1.0.3

Published

Compresses strings that is inside the js file published from Adobe Animate

Downloads

3

Readme

Animate. Compress Fills

Compresses strings that is inside the js file published from Adobe Animate

When publishing a project, Adobe Animate creates a js file with a bunch of different information. The module searches for the same strings inside this js file and replaces them with variables.

Keep in mind that compression algorithm is not yet 100% optimized.

preview

Installation

npm install animate-compress-fills

Output example (part of...)

// ------------------
// Input
// ------------------
var mask_graphics_0 = new cjs.Graphics().p("EgEAA52MAAAhzrIIBAAMAAABzrg");
var mask_graphics_1 = new cjs.Graphics().p("EgEAA52MAAAhzrIIBAAMAAABzrg");
this.shape.graphics.f("#FFFFFF").s().p("ABNCMIAAh3IhFAAIgYAAIgPADIgKA");
this.shape_1.graphics.f("#FFFFFF").s().p("ABNCMIAAh3IhFAAIgYAAIgPADIgKA");

// ------------------
// Output
// ------------------
var _1 = "EgEAA52MAAAhzrIIBAAMAAABzrg", _2 = "#FFFFFF", _3 = "ABNCMIAAh3IhFAAIgYAAIgPADIgKA";
var mask_graphics_0 = new cjs.Graphics().p(_1);
var mask_graphics_1 = new cjs.Graphics().p(_1);
this.shape.graphics.f(_2).s().p(_3);
this.shape_1.graphics.f(_2).s().p(_3);

Usage

const path = require('path');
const glob = require('glob');
const chalk = require('chalk');
const lodash = require('lodash');
const {table, getBorderCharacters} = require('table');
const AnimateCompressFills = require('animate-compress-fills');

glob('test/**/!(*.cmp).js', (err, files) => {
   for(let i = 0, len = files.length; i < len; i++){

      let js_file = path.join(__dirname, files[i]);
      
      new AnimateCompressFills(js_file, js_file.replace(/\.js$/i, '.cmp.js'), random(0, 1))
      .then(data => {
         let table_data = [[chalk.white.bold('N'), chalk.white.bold('COMPRESSED'), chalk.white.bold('UGLIFIED'), chalk.white.bold('SIZE')]];

         let size = toKB(data.size.source);
         let size_compressed = toKB(data.size.compressed);
         let size_uglified = toKB(data.size.uglified);

         let diff = (size_compressed - size).toFixed(3) || 0;
         let percent = (diff / size * 100).toFixed(3);
         let compressed_str = numSign(diff);
         let compressed_perc = numPerc(percent);

         let diff2 = (size_uglified - size).toFixed(3) || 0;
         let percent2 = (diff2 / size * 100).toFixed(3);
         let uglified_str = size_uglified == 0 ? 'disabled' : numSign(diff2);
         let uglified_perc = size_uglified == 0 ? '' : numPerc(percent2);
         
         table_data.push([i + 1, compressed_str + '  ' + compressed_perc, uglified_str + '  ' + uglified_perc, (size).toFixed(3) + ' KB']);

         console.log('');
         if(data.status == 'skip'){
            console.log(' ' + chalk.white.bgMagenta.bold(' ' + data.message + ': '), path.basename(data.input_file));
         }else{
            console.log(' ' + chalk.white.bgGreen.bold(' ' + data.message + ': '), path.basename(data.input_file));
         }
         console.log(table(table_data, {columns: {0: {width: 3}, 1: {width: 25}, 2: {width: 25}, 3: {width: 11}}, border: getBorderCharacters('ramac')}));
      })
      .catch(err => {
         console.log(err);
      })
   }
});

function random(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

function toKB(n){
   return n / 1024 || 0;
}

function numSign(n){
   if(n > 0){
      return chalk.red.bold('+' + n + ' KB');
   }else if(n < 0){
      return chalk.green.bold(n + ' KB');
   }else{
      return '0 KB';
   }
}

function numPerc(p){
   if(p > 0){
      return chalk.white.bgRed.bold(' +' + p + ' % ');
   }else if(p < 0){
      return chalk.white.bgGreen.bold(' ' + p + ' % ');
   }else{
      return '0 %';
   }
}

Callback data structure:

{
   status         -> {String} 'ok', 'fail' or 'skip' if it's pointless to compress
   message        -> {String} Any text describing status
   input_file     -> {String} Source js file path
   output_file    -> {String} Output js file path
   js_content     -> {String} Modified js content
   size: {
      source       -> {Number} Original size
      compressed   -> {Number} When fills are compressed
      uglified     -> {Number} And when all uglified
   }
}

Additionally you can compress the whole file using UglifyJS:

new AnimateCompressFills(input_file, output_file, true);