From 0a16d9238f05eadde9c8a5ea8b8ec6b85b91aac1 Mon Sep 17 00:00:00 2001 From: peroman86 Date: Wed, 18 Jul 2018 15:09:31 +0300 Subject: [PATCH] CamelCast to kebab-case --- lib/inflection.js | 20 ++++++++++++++++++++ test/inflection.js | 7 +++++++ 2 files changed, 27 insertions(+) diff --git a/lib/inflection.js b/lib/inflection.js index 650e90b..54dcb25 100644 --- a/lib/inflection.js +++ b/lib/inflection.js @@ -960,6 +960,26 @@ }, + /** + * This function adds kebabize support to every String object. + * @public + * @function + * @param {String} str The subject string. + * @returns {String} Return camel cased words into kebab-case form. + * @example + * + * var inflection = require( 'inflection' ); + * + * inflection.kebabize( 'MessageBusProperty' ); // === 'message-bus-property' + */ + kebabize : function ( str ){ + str = inflector.underscore( str ); + str = inflector.dasherize( str ); + + return str; + }, + + /** * This function adds classification support to every String object. diff --git a/test/inflection.js b/test/inflection.js index 6c5af28..0ace4ec 100644 --- a/test/inflection.js +++ b/test/inflection.js @@ -213,6 +213,13 @@ describe( 'test .tableize', function (){ }); }); +describe( 'test .kebabize', function (){ + it( 'should kebabize the given word', function (){ + inflection.kebabize( 'people' ).should.equal( 'people' ); + inflection.kebabize( 'MessageBusProperty' ).should.equal( 'message-bus-property' ); + }); +}); + describe( 'test .classify', function (){ it( 'should classify the given word', function (){ inflection.classify( 'message_bus_properties' ).should.equal( 'MessageBusProperty' );