Icontem

File: lib/util/str.js

Recommend this page to a friend!
  Classes of Harcharan Singh  >  Node Input Validator  >  lib/util/str.js  >  Download  
File: lib/util/str.js
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Node Input Validator
Validate submitted input values in Node.js
Author: By
Last change:
Date: 10 months ago
Size: 502 bytes
 

Contents

Class file image Download
exports.camelToSentance = function camelToSentance(str) {
  return str.replace(/([A-Z]+)/g, ' $1').trimLeft().toLowerCase();
};

exports.snakeToSentance = function snakeToSentance(str) {
  return str.replace(/_/g, ' ');
};

exports.trim = function trim(string, char = ' ') {
  let str = string;

  if (str.charAt(0) === char) {
    str = str.substr(1, str.length);
  }

  const len = str.length;

  if (str.charAt(len - 1) === char) {
    str = str.substr(0, len - 1);
  }

  return str.toString();
};