Gathering detailed insights and metrics for nginflection
Gathering detailed insights and metrics for nginflection
Gathering detailed insights and metrics for nginflection
Gathering detailed insights and metrics for nginflection
npm install nginflection
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
31 Stars
55 Commits
6 Forks
2 Watching
1 Branches
4 Contributors
Updated on 12 Apr 2022
JavaScript (77.65%)
HTML (22.35%)
Cumulative downloads
Total Downloads
Last day
0%
69
Compared to previous day
Last week
7.1%
440
Compared to previous week
Last month
13.1%
1,983
Compared to previous month
Last year
-37.4%
34,335
Compared to previous year
2
4
Angular filters for inflection. You can combine the filters to get some pretty cool results with English-language words.
You can see it in action, here.
You can use this library with requirejs, browserify, bower, or plain browser-globals.
npm install --save nginflection
In your app-code:
1var angular = require('angular'); 2var inflection = require('inflection'); 3require('nginflection');
bower install --save ngInflection
Here is how to use it with CDNs & no module-management:
1<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"></script> 2<script src="https://cdn.rawgit.com/dreamerslab/node.inflection/master/inflection.min.js"></script> 3<script src="http://konsumer.github.io/ngInflection/dist/ngInflection.min.js"></script>
Download into your requirejs path, then do this:
1define(['angular', 'inflection', 'ngInflection'], function(angular, inflection){ 2 // do stuff here 3});
Once you have the code loaded, add it to your app, along with your other Angular dependencies:
1var app = angular.module('app', [ 2 'ngRoute', 3 'ngInflection' 4]);
Use it in your templates, like this:
1{{ myThing | pluralize | titleize }}
You can see more examples in index.html.
ngPluralize is useful for outputting numeric amounts of things. If the name of the thing is unknown, and could be plural or singular, and the amount is unknown, you can use ngInflection with ngPluralize to work out the permutations of the string. Here is a cool example:
1<ng-pluralize count="fruitCount" when="{ 2 '0': 'No {{fruitType | pluralize | titleize}}', 3 '1': 'One {{fruitType | singularize | titleize}}', 4 'other': '{} {{fruitType | pluralize | titleize}}'}"></ng-pluralize>
Here are all the filters available:
Output a plural of a string. Use it like this:
1{{ 'person' | pluralize }} outputs people.
Sometimes, you might want to use a special word when a singular is detected:
1{{ 'person' | pluralize:'best buds' }} outputs best buds.
Output a singlular of a string. Use it like this:
1{{ 'people' | singularize }} outputs person.
Sometimes, you might want to use a special word when a plural is detected:
1{{ 'people' | singularize:'best bud' }} outputs best bud.
Output a singular or plural of a string based on a number. Use it like this:
1{{ 'person' | inflect:0 }} outputs people.
1{{ 'people' | inflect:1 }} outputs person.
1{{ 'person' | inflect:2 }} outputs people.
You can also pass in special words for both singular and plural:
1{{ 'people' | inflect:1:'best bud':'bestest buds' }} outputs best bud.
1{{ 'people' | inflect:2:'best bud':'bestest buds' }} outputs bestest buds.
Output a camelize of a string. Use it like this:
1{{ 'Some cool stuff' | camelize }} outputs SomeCoolStuff.
You can also get the first letter lower-case, like this:
1{{ 'Some cool stuff' | camelize:true }} outputs someCoolStuff.
Output an underscored version of a string. Use it like this:
1{{ 'SomeCoolStuff' | underscore }} outputs some_cool_stuff.
Output a humanized version of a string. Use it like this:
1{{ 'some_cool_stuff' | humanize }} outputs Some cool stuff.
You might also want it not capitalized:
1{{ 'some_cool_stuff' | humanize:true }} outputs some cool stuff.
Output a first-letter-capitalized version of a string. Use it like this:
1{{ 'some_cool_stuff' | capitalize }} outputs Some_cool_stuff.
Output a dasherized version of a string. Use it like this:
1{{ 'some_cool_stuff' | dasherize }} outputs some-cool-stuff.
Output a titleized version of a string. Use it like this:
1{{ 'some_cool_stuff' | titleize }} outputs Some Cool Stuff.
Output a demodulized version of a string. Use it like this:
1{{ 'Cool::Stuff' | demodulize }} outputs Stuff.
Output a tableized version of a string. Use it like this:
1{{ 'CoolThing' | tableize }} outputs cool_things.
Output a classy version of a string. Use it like this:
1{{ 'cool_things' | classify }} outputs CoolThing.
Output a foreign_key version of a string. Use it like this:
1{{ 'cool_thing' | foreign_key }} outputs cool_thing_id.
You might want to join id to the string. Do that like this:
1{{ 'cool_thing' | foreign_key:true }} outputs cool_thingid.
Output an ordinalized version of a string. Use it like this:
1{{ 'the 1 pitch' | ordinalize }} outputs the 1st pitch.
I didn't include usage notes on these, because I couldn't think of good use-cases, but check out the original documentation, if these seem like something you want.
This lets us detect if an Array contains a given element. This did not seem super-useful in the context of an angular string filter, but you could probably use it in some clever way with an array of objects.
This will execute an array of transforms. Since you can pipe filters in angular templates, this is best used from the filter service, not in actual templates. It works like this:
1filter('manipulateThingFromApi', function($filter) { 2 return function(apiThing) { 3 //manipulate api things 4 return $filter('transform')(apiThing, ['pluralize', 'titleize']); 5 } 6}
To do the same things in a template, use Angular's pipe syntax, like so:
1{{ 'cool thing' | pluralize | titleize }} outputs Cool Things
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More