Giter VIP home page Giter VIP logo

harnocode's Introduction

Harnocode

Reformats JavaScript code to look like an ASCII-art picture of your choice. Like this:

                   const                          esprima   =
               require('esprima');            const   escodegen =
             require( 'escodegen') ;        const fs=require('fs');
           exports.harnocode=function(    code,mask,options){options=
          options||{ };const  format= {  safeConcatenation  :  true  ,
         escapeless:true,semicolons:true,renumber:true,quotes:'single'}
         ;code=escodegen.generate(esprima.parse(code),{format:format});
         const tokens=tokenize(code);const lines=splitMaskToGroups(mask
         );let  tokenIndex= 0; let groupIndex =0; let result =[ ];let
         splitStrings=options. splitStrings===undefined?false: options.
          splitStrings;let safe=options.safe===undefined?true:options.
           safe;function processMask(){return lines.map(groups=>{let
             lineResult=[ ];let  offset= 0;if( tokenIndex>=tokens .
              length)return ;groups .forEach (( group,i )=> {let
                groupWidth=group[0].length;let isBeforeNewline=i
                  ==groups.length -1;if( group.index<offset ){
                    groupWidth -= offset- group .index ; if(
                      groupWidth <= 0  ) return ; }  let
                        groupTokens=takeTokens (tokens ,
                          groupWidth , tokenIndex  , {
                            isBeforeNewline , safe ,
                              splitStrings}); let
                                groupTokensJustified
                                  = justify  (
                                    groupTokens
                                         ,

The code should stay functional after the transformation.

"Harnocode" (ukr. гарнокод) means "beautiful code" in the Ukrainian language.

Examples:

Here are functional copies of harnocode's source code formatted with itself:

Installation

$ npm install -g harnocode

Usage

Command-line:

$ harnocode ./examples/lodash.heart.js --mask masks/ubuntu.txt --split-long-lines > lodash.ubuntu.js

See

$ harnocode

for the full list of available options.

Node.js:

TODO

Converting images to masks

TODO

About

Harnocode v1 was written in ClojureScript during the DOU Hackathon on 21-22 February, 2015.

Harnocode v2 is a rewrite in a pure JavaScript. It adds support for ECMAScript 2019, npm module and a command-line tool.

harnocode's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

0xspiridono

harnocode's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.