Skip to content

Commit

Permalink
⚰️ Remove some unused string methods
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Feb 14, 2024
1 parent d4792f8 commit 42d5fdf
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 194 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Add new operators to the JavaScript tokenizer
* Replace `Object.hasOwnProperty.call` calls with `Object.hasOwn`
* Add support for underscores in numbers to the tokenizer
* Remove some unused string methods

## 0.8.18 (2024-01-19)

Expand Down
153 changes: 1 addition & 152 deletions lib/inflections.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,111 +389,6 @@ defString(function modelName(postfix) {
return str;
});

/**
* Turn a string into a model name, with controller postfix
*
* @author Jelle De Loecker <[email protected]>
* @since 0.1.4
* @version 0.1.4
*
* @return {String}
*/
defString(function modelClassName() {

var result;

if (Collection.String.prototype.endsWith.call(this, 'Model')) {
result = this.slice(0, this.length - 5);
} else {
result = this;
}

result = Collection.String.prototype.modelName.call(result);

return result + 'Model';
});

/**
* Turn a string into a controller name
*
* @author Jelle De Loecker <[email protected]>
* @since 0.0.1
* @version 0.1.4
*
* @param {String} postfix The string to postfix to the name
*
* @return {String}
*/
defString(function controllerName(postfix) {

var str = this,
underscores,
capitals,
lower;

lower = str.toLowerCase();

if (lower === 'app') return 'App';
else if (lower === 'static') return 'Static';

if (postfix === true) postfix = 'Controller';

capitals = !!S.capitals(str);
underscores = !!(str.indexOf('_') > -1);

// If there already are capitals, underscore the string
if (capitals) {
str = S.underscore(str);
underscores = true;
}

// If there still are underscores, or there are no capitals,
// we need to camelize the string
if (underscores || !capitals) {
str = S.camelize(str);
}

if (S.endsWith(str, 'Controller')) {
str = str.slice(0, str.length-10);
}

// Do not pluralize 'static'
if (!S.endsWith(str, 'Static')) {
str = S.pluralize(str);
}

// Append the postfix
if (postfix) {
str = S.postfix(str, postfix);
}

return str;
});

/**
* Turn a string into a controller name, with controller postfix
*
* @author Jelle De Loecker <[email protected]>
* @since 0.1.4
* @version 0.1.4
*
* @return {String}
*/
defString(function controllerClassName() {

var result;

if (Collection.String.prototype.endsWith.call(this, 'Controller')) {
result = this.slice(0, this.length - 10);
} else {
result = this;
}

result = Collection.String.prototype.controllerName.call(result);

return result + 'Controller';
});

/**
* Camelize a string
*
Expand Down Expand Up @@ -800,26 +695,6 @@ defString(function titleize(alwaysCapitalize) {
return str;
});

/**
* Removes module names leaving only class names (Ruby style)
* Example: "Message::Bus::Properties".demodulize() == "Properties"
*
* @author Jelle De Loecker <[email protected]>
* @since 0.0.1
* @version 0.1.0
*
* @return {String}
*/
defString(function demodulize() {

var str = this,
str_arr = str.split('::');

str = str_arr[str_arr.length - 1];

return str;
});

/**
* Renders strings into their underscored plural form
*
Expand Down Expand Up @@ -862,8 +737,7 @@ defString(function classify() {
* @return {String}
*/
defString(function foreign_key(dropIdUbar) {
var str = S.demodulize(this);
str = S.underscore(str);
let str = S.underscore(this);
str += ((dropIdUbar) ? ('') : ('_')) + 'id';
return str;
});
Expand Down Expand Up @@ -916,29 +790,4 @@ defString(function ordinalize() {
str = str_arr.join(' ');

return str;
});

/**
* De-pluginify a string
*
* @author Jelle De Loecker <[email protected]>
* @since 0.0.1
* @version 0.0.1
*
* @return {Boolean}
*/
defString(function deplugin(str) {

var s = this.split('.'),
any = false;
obj = {plugin: '', item: '', model: '', field: '', name: ''};

if (typeof s[1] != 'undefined') {
obj.plugin = obj.model = obj.name = s[0];
obj.item = obj.field = s[1];
} else {
obj.item = obj.field = s[0];
}

return obj;
});
42 changes: 0 additions & 42 deletions test/inflections.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,6 @@ describe('String Inflections', function() {
});
});

describe('#modelClassName()', function() {
it('should return the model name representation of the string, with the Model postfix', function() {
assert.strictEqual('news'.modelClassName(), 'NewsModel');
assert.strictEqual('newsModel'.modelClassName(), 'NewsModel');
assert.strictEqual('news_model'.modelClassName(), 'NewsModel');
assert.strictEqual('user'.modelClassName(), 'UserModel');
assert.strictEqual('app'.modelClassName(), 'AppModel');
});
});

describe('#controllerName(postfix)', function() {
it('should return the controller name representation of the string', function() {

assert.strictEqual('app'.controllerName(), 'App');
assert.strictEqual('static'.controllerName(), 'Static');

assert.strictEqual('news'.controllerName(), 'News');
assert.strictEqual('user'.controllerName(), 'Users');
assert.strictEqual('contact_info'.controllerName(), 'ContactInfos');
});
});

describe('#controllerClassName(postfix)', function() {
it('should return the controller name representation of the string, with the Controller postfix', function() {

assert.strictEqual('app'.controllerClassName(), 'AppController');
assert.strictEqual('static'.controllerClassName(), 'StaticController');

assert.strictEqual('news'.controllerClassName(), 'NewsController');
assert.strictEqual('newsController'.controllerClassName(), 'NewsController');
assert.strictEqual('news_controller'.controllerClassName(), 'NewsController');
assert.strictEqual('user'.controllerClassName(), 'UsersController');
assert.strictEqual('contact_info'.controllerClassName(), 'ContactInfosController');
});
});

describe('#camelize(lowFirstLetter)', function() {
it('should return the camelized representation of the string', function() {
assert.strictEqual('this_is_a_test'.camelize(), 'ThisIsATest');
Expand Down Expand Up @@ -125,12 +89,6 @@ describe('String Inflections', function() {
});
});

describe('#demodulize()', function() {
it('should remove module names leaving only class names', function() {
assert.strictEqual("Message::Bus::Properties".demodulize(), 'Properties');
});
});

describe('#tableize()', function() {
it('should return the underscored plural form of the string', function() {
assert.strictEqual('MyUser'.tableize(), 'my_users');
Expand Down

0 comments on commit 42d5fdf

Please sign in to comment.