Miss any of our Open RFC calls?Watch the recordings here! »

ember-string-parameterize

0.2.1 • Public • Published

Ember.String.parameterize Build Status

A javascript method (with an ember.js wrapper) to transform a string so that it may be used as part of a 'pretty' / SEO friendly URL. Similar to ActiveSupport's parameterize inflector.

This is useful for creating slugs for your Ember.js routes. So useful that this feature was merged into Ember core with a feature flag, but later removed due to potential API bloat. Voice your opinion if you want it back, or, just use this!

Usage

Include ember-string-parameterize.js after ember.js in your app.

Or using package managers:

bower install ember-string-parameterize
npm install ember-string-parameterize

Examples

With Ember

'My favorite movies.'.parameterize();
//=> 'my-favorite-movies'
 
'some_underscored_string'.parameterize();
//=> 'some-underscored-string'
 
'100 ways Ember.js is better than Angular'.parameterize();
//=> '100-ways-emberjs-is-better-than-angular'
 
'#emberjs Core Team Meeting Minutes - 2014/12/06'.parameterize();
//=> 'emberjs-core-team-meeting-minutes-2014-12-06'

Limit the number of words

'100 ways Ember.js is better than Angular'.parameterize(5);
//=> '100-ways-emberjs-is-better'
 
'100 ways Ember.js is better than Angular'.parameterize(-2);
//=> '100-ways-emberjs-is-better'

When Ember.EXTEND_PROTOTYPES is disabled

Ember.String.parameterize('Using without extending prototypes!');
//=> 'using-without-extending-prototypes'
 
Ember.String.parameterize('Using without extending prototypes!', 3);
//=> 'using-without-extending'

Vanilla JS

It will also expose StringParameterize to the browser's window object or node.js

StringParameterize('I work without Ember.js');
//=> 'i-work-without-emberjs'
 
StringParameterize('I work without Ember.js', 2);
//=> 'i-work'

Keywords

Install

npm i ember-string-parameterize

DownloadsWeekly Downloads

208

Version

0.2.1

License

MIT

Last publish

Collaborators

  • avatar