New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@aspiesoft/cwsclib

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aspiesoft/cwsclib

A compression library for strings, that recognizes common words, and creates references to them.

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Common Word String Compression Library

npm version GitHub top language GitHub license

npm downloads npm downloads jsDelivr hits (GitHub)

paypal

A compression library for strings, that recognizes common words, and creates references to them

A compression library for strings, that recognizes common words, and creates references to them. Because these word references are built within the cdn, they should get cached and reduce the amount of data sent to the client.

This algorithm checks if the string got smaller or larger at each step, and does Not add methods that become larger than the original result from the last method. The algorithm attempts to reduce repeating words, and generate utf8 character based references to allow fast decompression.

Usually decompression is faster than compression, as compression should make the string as small as possible, and decompression is usually when you actually need the string.

Installation

node.js


npm install @aspiesoft/cwsclib

# or with no optional dependencies
npm install @aspiesoft/cwsclib --no-optional

cdn


<!-- Optional: add secondary compression (will detect automatically) -->
<script src="https://cdn.jsdelivr.net/gh/nodeca/pako@1.0.11/dist/pako.min.js" charset="utf-8"></script>


<!-- Note: charset="utf-8" is necessary for the script to use utf-8 character references properly -->
<script src="https://cdn.jsdelivr.net/gh/AspieSoft/cwscLib@1/script.min.js" charset="utf-8"></script>

Usage


// require only if using node.js
const cwscLib = require('@aspiesoft/cwsclib');

let str = 'the cdn.jsdelivr.net javascript engine built in year 2020 by aspiesoft';

let compressed = cwscLib.compress(str, 9).toString(); // output: §1:0><qU> <&> <*b> <NŒ> <Xx> in <l‰> 2020 by <-2>

let decompressed = cwscLib.decompress(compressed); // output: the cdn.jsdelivr.net javascript engine built in year 2020 by aspiesoft

// note: the compressed string may appear different, if you add an optional compression after this compression (depending on if it gets smaller)


let speed = 1; // any number between 0 and 9
/*
  speed = 1 (fastest)
  speed = 9 (best) (default)
*/

let compression = cwscLib.compress(str, speed);
/*
  output: {
    comp: '0><qU> <&> <*b> <NŒ> <Xx> in <l‰> 2020 by <-2>',
    ver: 1,
    compType: 0,
    toString: [Function: toString],
    toJSON: [Function: toJSON],
    decomp: [Function: decomp]
  }
*/

compression.toJSON(); // output: compression object without functions (useful for storing json)

compression.decomp(); // output: original string
cwscLib.decompress(compression); // output: original string
cwscLib.decompress(compression.toJSON()); // output: original string


cwscLib.compress('11111 222 33 4444444 5555555555 6 7 888888888888 999999999999').toString(); // output: §1:1>2:1 0:2 33 4:4 7:5 6 7 9:8 9:9

Keywords

FAQs

Package last updated on 13 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc