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 7b5dce0
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(len;fill):
tostring | ($len - length) as $l | ($fill * $l)[:$l] + .;
def rpad(len;fill):
tostring | ($len - length) as $l | . + ($fill * $l)[:$l];

# 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 7b5dce0

Please sign in to comment.