JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q42389F
  • License MIT

convert to popular formats

Package Exports

  • encodify

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (encodify) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Encodify Build Status

Join the chat at https://gitter.im/npkumar/encodify

A small library providing utility methods to encode and decode to various code formats

NPM

Installation

npm install encodify --save

Usage

var encodify = require('encodify');

// Convert to Pig Latin Script
encodify.toPigLatin('glove').should.eql('oveglay');

// Convert to Roman Numeral
encodify.toRomanNumeral(55).should.eql('XXXXXV');

// Convert to NATO Code - French and German currently supported
encodify.toNATOCode('CODE').should.eql('Charlie Oscar Delta Echo');
encodify.toNATOCode('code', 'German').should.eql('Cäsar Otto Dora Emil');
encodify.toNATOCode('C.O D@E', 'FRENCH').should.eql('Célestin point Oscar espace Désiré arobase Eugène');

// Convert to Morse Code
encodify.toMorseCode('secret').should.eql('... . -.-. .-. . -');
encodify.toMorseCode('b.o@nd').should.eql('-... .-.-.- --- .--.-. -. -..');
encodify.toMorseCode('NPK').should.eql('-. .--. -.-');

// Convert from Morse Code
encodify.fromMorseCode('... . -.-. .-. . -').should.eql('secret');
encodify.fromMorseCode('.... .- .--. .--. -.-- -..-. -... .. .-. - .... -.. .- -.-- -..-. -. .--. -.-').should.eql('happy/birthday/npk');

// Convert to Binary Code
encodify.toBinary('I am the War Cheif!').should.eql('1001001 100000 1100001 1101101 100000 1110100 1101000 1100101 100000 1010111 1100001 1110010 100000 1000011 1101000 1100101 1101001 1100110 100001');
encodify.toBinary('&#@!').should.eql('100110 100011 1000000 100001');
encodify.toBinary(9).should.eql('111001');

// Convert from Binary Code
encodify.fromBinary('1001001 100000 1100001 1101101 100000 1110100 1101000 1100101 100000 1010111 1100001 1110010 100000 1000011 1101000 1100101 1101001 1100110 100001').should.eql('I am the War Cheif!');
encodify.fromBinary('100110 100011 1000000 100001').should.eql('&#@!');
encodify.fromBinary('111001').should.eql('9');

// Convert to list of Anagrams
encodify.toAnagrams('cod').should.eql(['cod', 'cdo', 'ocd', 'odc', 'dco', 'doc']);
encodify.toAnagrams('%*!').should.eql(['%*!', '%!*', '*%!', '*!%', '!%*', '!*%']);

// Convert to Spinal Case
encodify.toSpinalCase('thisIsSpinalTap').should.eql('this-is-spinal-tap');
encodify.toSpinalCase('This Is Spinal Tap').should.eql('this-is-spinal-tap');
encodify.toSpinalCase('The_Andy_Griffith_Show').should.eql('the-andy-griffith-show');

// Convert to Fibonacci Series
encodify.toFibonacci(10).should.eql([ 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 ]);
encodify.toFibonacci(3.9).should.eql([ 1, 1, 2 ]);

// Convert to Base DNA Pair
encodify.toDNABasePair('GGCC').should.eql('CCGG');
encodify.toDNABasePair('GaTcAatagc').should.eql('CTAGTTATCG');

// Convert to list of Prime numbers upto given specified number
encodify.toPrimes(10).should.eql([2, 3, 5, 7]);
encodify.toPrimes(30.97).should.eql([2, 3, 5, 7, 11, 13, 17, 19, 23, 29]);

// Calculate LCM of all values in an array
encodify.toLCM([330, 65, 15]).should.eql(4290);
encodify.toLCM([330, 90, 65, 55, 20, 15]).should.eql(25740);

// Calculate GCD of all values in an array
encodify.toGCD([45, 60, 330]).should.eql(15);
encodify.toGCD([25, 45, 60, 115, 330]).should.eql(5);

// Convert to flattened array from any multi dimensional array of varying level of nesting
encodify.toFlattenedArray([1, [], [3, [[4]]]]).should.eql([1, 3, 4]);
encodify.toFlattenedArray([1, [5, [6, [7, 8, [9]]]], [3, [[4]]]]).should.eql([1, 5, 6, 7, 8, 9, 3, 4]);

Tests

npm test

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. Feel free to add more conversions!

Release History

  • 0.1.0 Initial release