Skip to content

Commit

Permalink
Added lpad and rpad
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfetter committed Feb 14, 2020
1 parent 5b9e63e commit 11b12f0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/builtin.jq
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ def ascii_downcase:
def ascii_upcase:
explode | map( if 97 <= . and . <= 122 then . - 32 else . end) | implode;

def lpad(string;len;fill):
if len == 0 then string else (fill * len)[0:len] + string end;
def rpad(string;len;fill):
if len == 0 then string else string + (fill * len)[0:len] end;

# Streaming utilities
def truncate_stream(stream):
. as $n | null | stream | . as $input | if (.[0]|length) > $n then setpath([0];$input[0][$n:]) else empty end;
Expand Down

0 comments on commit 11b12f0

Please sign in to comment.