Comments (16)
@maku I think it would be a useful filters.
We can go this way...
string | rpad: string: length[optional]
rpad:
<p>{{ 'foo' | rpad: 'bar' }}</p>
<p>{{ 'foo' | rpad: 'bar': 2 }}</p>
<!--
barfoo
barbarfoo
lpad: same behaviour like rpad
pad:
<p>{{ 'foo' | pad: 'bar' }}</p>
<p>{{ 'foo' | pad: 'bar': 2 }}</p>
<!--
barfoobar
barbarfoobarbar
let me know what do you think...
from angular-filter.
Why in the world would we need something like that?
from angular-filter.
I would have thought the following variant (like in the following java lib)
https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html#leftPad(java.lang.String, int, java.lang.String)
e.g.
{{2 | leftPad:3:'0'}} --> 002
{{'abc' | leftPad:10:''}} --> ******abc
and so on
@mallowigi - I hope the reason why someone could need this func. is obvious
from angular-filter.
I can understand what @mallowigi means..
It's not a common situation, and we always could go this way...
for example:
rpad:
<p>{{ ('foo'|repeat:3) + 'bar' }}</p>
<!--result:
foofoofoobar
lpad:
<p>{{ 'bar' + ('foo'|repeat:3) }}</p>
<!--result:
barfoofoofoo
pad:
<p>{{ 'bar' | wrap: ('foo'|repeat:3) }}</p>
<!--result:
foofoofoobarfoofoofoo
It is just a matter of what we're prefer, keep angular-filter
thin and robust, or more huge with syntactic sugar etc..
It will be nice to hear more opinions...
from angular-filter.
I'd vote for thin and robust with a jaundiced eye towards including new things. Is there another way to solve the padding problem? It seems like the filter library is for handling groups (arrays) of objects, not single instance items. This example is single instance. How about a real-world group example? Also, in this case we are dealing with string transformation. Why not use .map on arrays and run it through a function to pad or wrap? Again, edge case vs. common plus bang for the buck.
from angular-filter.
I agree, this library shouldn't be a pot-pourri of what we can do with angular filters, but rather a collection of useful and common functions that everyone can encounter on a daily basis, such as map, omit, first, capitalize or join. Agreed, some of them are rarely used (such as fuzzy or striptags) and some of them could be easily replaced by other filters (startsWith, wrap...) but this was probably a result of a proof of concept during the early phases of development.
from angular-filter.
I think for all esoteric filters we should open another project (same as lodash-contrib or sugar-contrib) and keep this one clean.
from angular-filter.
@mallowigi nice suggestion, best of both worlds. I wonder if there are any current filters that could be migrated into the secondary library?
from angular-filter.
I don't think it will be possible, a lot of people are using "ngpipe" filters right now, just move them to another repository could be disastrous!
from angular-filter.
I agree with both of you guys, and appreciate your contributions here.
I think @codeedog right, and maybe we could deprecate unused filters.. we can open a new issue and discuss about that, asking people what they are thinking etc etc..
from angular-filter.
Sorry guys,
I thought when a filter like "wrap" is in the library then left/rightpad is not such a bad idea (btw, I can imagine how I work around wrap but not around the padding filter without providing a scope function)
from angular-filter.
Don't be sorry @maku, that's the point of discussion.
see above the 'work around' examples
e.g:
<p>{{ ('*'|repeat:10) + 'foo' }}</p>
<!--result:
**********foo
from angular-filter.
@a8m sorry thats not the point -> as I wrote:
{{2 | leftPad:3:'0'}} --> 002
{{'abc' | leftPad:10:''}} --> ******abc
and so on
which means that padding depends on the length of the input ...
from angular-filter.
I'm with @maku on this one - if we have it, it should pad to a certain length.
from angular-filter.
I think a padding would be a good idea. and I can certainly could find it useful in my projects.
from angular-filter.
+1 for the feature, padleft is very useful
from angular-filter.
Related Issues (20)
- Filter to format phone numbers HOT 2
- new filter: title case HOT 1
- 'split' filter for string to transform it as Array? HOT 3
- Getting false back on 'Every' Filter HOT 1
- New filters
- Unknown provider error for phoneUS HOT 2
- filterBy with boolean field is not working for me HOT 1
- Get length of filtered array HOT 2
- Filters Not Working on IE
- Issue with sum when using filter and map HOT 3
- KiB and MiB are wrongly used in place of kB and MB HOT 2
- chunkBy fires of digest every few seconds HOT 2
- BroupBy hide parent when filtering HOT 2
- bug with String.contains polyfill
- Where does not work for me if used alone or used with other filters.
- Caution: carefully use in hybrid app
- GroupBy Week, Month and Year
- ltrim and rtrim HOT 1
- good HOT 1
- ucfirst doesn't work with capitalized string HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-filter.