Skip to content

Instantly share code, notes, and snippets.

@fpinzn
Created June 10, 2014 10:40
Show Gist options
  • Save fpinzn/11a4dc53dabf3be7a173 to your computer and use it in GitHub Desktop.
Save fpinzn/11a4dc53dabf3be7a173 to your computer and use it in GitHub Desktop.
{head, group-by, lines, take-while} = require 'prelude-ls'
fs = require 'fs'
#aliases
CL = console.log
#returns the lines in the N level of indentation
# Usage: indentificator file [level]
# If no level is provided all levels will be printed
# TODO: receive char-value (tab-space equivalency)as an arg of the program
char-value = {'\t': 1, ' ': 0.5}
file = process.argv[2]
level = process.argv[3]
# INPUT transformation
indentation-grouper= (a)->
char0 = head a
char0-count = take-while (in ['\t',' ']), a .length
char0-count * char-value[char0]
#PROCESS
fs.readFile "./#{file}", 'utf8', (err, data)->
groups = group-by indentation-grouper, lines data
#Remove the group of the lines that don't have indentation
delete groups[NaN]
CL if level? then groups[level] else groups
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment