Alignment of a string
Perl 6, 195 186 177 132 bytes

-41 bytes thanks to nwellnhof!



{-&gt;\b,\c{$!={!c*(b-$0.comb)/($0-1||1)+1};S:g{[(\S+)[\s|$]&lt;?{b&gt;=$0.ords&amp;&amp;.$!%%1}&gt;]+|(\S**{b})}=$0.join(' 'x.$!).fmt("%{b*c||-b}s
")}}


Try it online!

Anonymous code block that takes input curried, e.g. f('text')(length, direction). Uses the values -1,0,1 as left, middle and right respectively.