dreamerslab / node.inflection Goto Github PK
View Code? Open in Web Editor NEWA port of inflection-js to node.js module
License: MIT License
A port of inflection-js to node.js module
License: MIT License
Hi,
We are using http://docs.sequelizejs.com/en/latest/ which uses this library and have found that it is taking the word Media and turning it into Medium.
var inflection = require("inflection")
var modelName = "Media"
console.log(inflection.pluralize(modelName)) // ==> Media
console.log(inflection.singularize(modelName)) // ==> Medium
I'm using the (ngInflection) [https://github.com/konsumer/ngInflection] angularjs wrapper for this node.inflection and i'm hitting some problems due to the way angular filters evaluate a variable that is expecting a promise to resolve.
I have a div in an ng-repeat with with a static class plus a dynamic class like this:
dasherize : function ( str ){
return str.replace( space_or_underbar, '-' );
},
After:
dasherize : function ( str ){
if(str) {
return str.replace( space_or_underbar, '-' );
} else {
return str;
}
},
This works because when the promise resolves to a value, the filter is fired again.
Hi, I would like to inform you that I've ported your package to meteor - https://github.com/katrotz/meteor-inflector
$ var inflection = require('inflection')
$ inflection.pluralize('education')
'education'
$ inflection.pluralize('education') === 'educations'
false
In line with v1.4.2 of inflection, I believe that in general "business" can be pluralized to "businesses".
Here's an example of the plural use from the good ol' BBC: http://www.bbc.co.uk/news/uk-30008546
"Business" is countable in some uses of the word and uncountable in other uses. But "businesses" is certainly a word you hear often (and correctly!) in common speech.
I notice someone else has raised an issue about the plural of "access" (#31). That's similar in that it's a word which has both countable and uncountable uses, but I think the uncountable uses are far more common.
I guess it's arguable either way, but I suspect I won't be the only one to update to inflection v1.5 and find that my code breaks due to the disappearance of "businesses"!
Just returns original string
Hey there,
Maybe in the readme you could explain what sort of issues come up when you extend the prototype. Is it specific to Node?
rb
inflection.pluralize('media') // => 'media'
inflection.singularize('media') // => 'medium'
Howdy,
Seems like v1.3.7 translates 'meta' to 'metum' -- presumably following 'data' to 'datum' logic. Previous behavior was 'meta' => 'metas'.
I just added this to the singular_rules
array and it fixes it:
[ new RegExp( '(quiz)zes$', 'gi' ), '$1' ],
[ new RegExp( 'ss$', 'gi' ), 'ss' ],
[ new RegExp( 's$', 'gi' ), '' ]
inflection.underscore("Apple Tree Lake"); // "apple _tree _lake" should be "apple_tree_lake"
inflection.underscore("Apple 20 Tree Lake"); // "apple 20 _tree _lake" should be "apple_20_tree_lake"
It's seeing v1.7.0 as the latest: https://www.npmjs.com/package/inflection
inflection.singularize('minus') => 'minu'
Expecting just "minus"
The plural of "nucleus" should be "nuclei". The rare plural form "nucleuses" should also be recognized to be singularized correctly.
Current behavior:
inflection.singularize("nucleus") // "nucleu" (wrong)
inflection.singularize("nucleuses") // "nucleuse" (wrong)
inflection.singularize("nuclei") // "nuclei" (wrong)
inflection.pluralize("nucleus") // "nucleus" (wrong)
inflection.pluralize("nucleuses") // "nucleuses" (correct)
inflection.pluralize("nuclei") // "nucleis" (wrong)
The specific line in question is in file lib/inflection.js line 141 and the error is:
Error: Parsing file /home/...../lib/inflection.js: Line 141: Comprehension Error
I suspect it's because of their parser and its improperly parsing the list of words which look like JavaScript keywords. I confirmed and the package.json is refering to the latest npm version.
I know that this is not technically your issue, but it could easily be resolved by concatenating strings that contain keywords on that line.
Thoughts?
Getting this error:
W20130926-16:57:37.896(4)? (STDERR) /home/bline/.meteor/tools/3cba50c44a/lib/node_modules/fibers/future.js:173
W20130926-16:57:37.897(4)? (STDERR) throw(ex);
W20130926-16:57:37.897(4)? (STDERR) ^
W20130926-16:57:37.899(4)? (STDERR) TypeError: object is not a function
W20130926-16:57:37.900(4)? (STDERR) at Object.inflector.resetInflections (packages/underscore-inflection/lib/underscore.inflection.js:161)
I modified package.js and added
api.use('underscore', where);
just above the api.add_files
line and that seems to have fixed the issue.
This is with meteor 0.6.5.1
This is not what I expected:
> require('inflection').underscore('Table of Contents')
'table of _contents'
> require('inflection').pluralize('bonus')
'bonus'
This should return "bonuses"
coffee> inflection.camelize 'frame-set'
'Frame-set'
Am I doing something wrong here? I'd expect to see 'FrameSet'.
correct result should be datum
pluralize('datum') // data
singularize('data') // data
the pluralize
module handles this case correctly, if that helps
Is this the intended behavior?
When I run inflection.dasherize('helloThere')
I get hellothere
instead of hello-there
.
Currently, inflection.singularize('focus')
== "focu".
Focus should remain singular, and "foci" and "focuses" should probably be added as exceptions for the plural.
https://github.com/dreamerslab/node.inflection/blob/master/lib/inflection.js#L350
^(m|wom)en$
and ^(m|wom)an$
?
right now it's inflector.pluralize("woman") // -> womans
The plural of fish is fish!
I see fish on the list of "unaccountable" words commented out... A little help please.
console.log(inflection.pluralize('Materia'));
result: 'Materia'
Expected
expect(dasherize('TestMe')).to.equal('test-me')
Actual
expect(dasherize('TestMe')).to.equal('TestMe')
Hey would you mind adding your inflection library to Bower?
http://twitter.github.com/bower/
All you need to do is run this command in your project root:
bower register inflection git://github.com/dreamerslab/node.inflection
Then it should be possible to install with:
bower install inflection
Bower should use your package.json
to find the right file to download, but if you want to get more specific you could add this component.json
file to the root of your project:
{
"name": "inflection",
"version": "x",
"main": "./lib/inflection.js"
}
Cheers.
I noticed camelize
does not support converting dashcase to camelcase, should it?
Example:
const inflection = require('inflection')
inflection.camelize('foo-bar') // 'Foo-bar'
I expected the example above to return FooBar
.
Per https://github.com/bower/bower.json-spec, "main"
should "not include minified files."
Updating this to conform to spec would be helpful for debugging in a dev environment. Bower dependencies are typically minified by developers themselves anyway.
inflection.singularize('Saves') => 'Safe'
Expecting "Save"
I'd be happy to do a pr to fix. not sure where to best make the change though. uncountable_words
is described as being nouns, but it seems a good fit for that array. thoughts?
Hey there!
I just found inflection.underscore('_')
returns ''
(an empty string).
I bet it's a bug since this method should add, not remove, underscores.
Once confirmed by the author, I'm happy to implement a fix.
Hi there, sequelize/sequelize reporting in. We recently switched from lingo to inflection for internal pluralization and singularization. So far it has been working out great, but version 1.4.1 gives an error in our test suite.
inflection.singularize('street');
In version 1.3.8 it gave street
, while 1.4.1 gives stroot
. Singularization of streets works fine, so the problem only occurs when singularizing an already singular word. Is there any defined behaviour for that?
It seems a method is missing from this tool that would make all of the characters UPPERCASE.
I didn't see anything in the readme about this, and please forgive me if I've overlooked some explanation as to why this hasn't already been included.
fork: https://github.com/dmiro/node.inflection
Doesn't seem to work en Node 0.8.9 .
Error "TypeError: Object # has no method '_apply_rules'"
In inflection.js, I replaced where it appears "this._apply_rules" with "inflector._apply_rules" and seems to work properly.
genera is the proper pluralization on genus.
Strings that are prefixed with an underscore for some reason make the low_first_letter
flag unusable.
Is this the desired effect or a bug?
inflection.camelize('_foo_bar', false);
// FooBar
inflection.camelize('_foo_bar', true);
// FooBar
There is no singular or plural for the word 'about'. I guess for such cases it should return the word as it is.
@ben-lin Please look into it and notify if this is worth considering.
i.singularize('canvases'); // "canvase", should be "canvas"
i.pluralize('canvas'); // "canvas", should be "canvases" (US et al) or "canvasses" (UK et al)
Incorrect pluralization for: human
, aircraft
.
Correct the spelling of "seperate" to "separate" wherever found. In particular, in Readme.md.
(Mnemonic: there is "a rat" in separate.)
When I use singularize
on the word status it results in statu.
I've come across a use case where it would be helpful to know if a word is either singular or plural. I couldn't see an immediate way to do this with the library. How could we implement this? Would this be in the scope of the library?
var inflection = require('inflection');
console.log(inflection.pluralize('grammar'));
// "grammar" instead of expected "grammars"
I've seen that this package is based on wiktionary.
The grammar page does mention: grammar (countable and uncountable, plural grammars)
I noticed this when defining a 'grammar' model with the ORM Sequelize which has inflection as a dependency. Also, it seems that the issue comes from this package itself and not from rails.
inflection.titleize("x-men:-the-last-stand")
"X-Men:-the-Last-Stand"
Loading development environment (Rails 4.2.7.1)
irb(main):001:0> ActiveSupport::Inflector.titleize("x-men:-the-last-stand")
=> "X Men: The Last Stand"
Loading development environment (Rails 5.1.1)
irb(main):001:0> ActiveSupport::Inflector.titleize("x-men:-the-last-stand")
=> "X Men: The Last Stand"
(line 26 of lib/inflection.js)
In http://en.wiktionary.org/wiki/access says that the plural of access is accesses.
Thank you for your attention.
Hey,
Camelizing an already camelcased variable shouldn't convert every character to lower case. I imagine it does that because FOO_BAR
might be expected to camelize as fooBar
. But still, the camelized version of fooBar_Baz
should be fooBarBaz
, not foobarBaz
as it is now.
Consider the next code snippet:
import { transform } from 'inflection'
transform('TestMe', ['underscore', 'dasherize'])
Expected result:
test-me
Actual result:
TestMe
The issue is in transform
implementation:
This function expects this
to be an instance of library but in provided case this
is always a window because of ES6 destructuring
https://github.com/dreamerslab/node.inflection/blob/master/lib/inflection.js#L1068
Code
var name = 'canvas' var pluralName = inflections.pluralize(name) var singularName = inflections.singularize(name)
expect
pluralName -> canvasses
singularName -> canvas
result
pluralName -> canvas
singularName -> canva
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.