Socket
Socket
Sign inDemoInstall

synonomous

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

synonomous - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

54

index.js

@@ -17,6 +17,23 @@ 'use strict';

var REGEXP_LOWER_CASE_LETTER = /[a-z]/;
var REGEXP_WORD_SEPARATORS = /[\s\-_]*([^\s\-_])([^\s\-_]+)/g;
var WITH_CAPTIAL_LETTER = function(a, b, c) { return b.toUpperCase() + c; };
var REGEXP_CAPITAL_LETTERS = /[A-Z]+/g;
var WITH_PREFIXED_SPACE = ' $&';
var REGEXP_OVER_CAPITALIZED_WORDS = /([A-Z]+)([A-Z][a-z])/g;
var WITH_SEPARATE_WORDS = '$1 $2';
/** @typedef {function} Transformer
* @param {string} key
* @returns {string}
*/
/**
* @classdesc This object holds a list of transformations used by {@link Synonomous.prototype.getSynonyms} and {@link Synonomous.prototype.decorateList}.
*
* Additional transformer functions may be mixed into the prototype (or added to an instance).
* @classdesc This object holds a list of transformations used by {@link Synonomous.prototype.getSynonyms} and {@link Synonomous.prototype.decorateList}.
* @param {string[]} [transformations] - If omitted, {@link Synonomous.prototype.transformations} serves as a default.
*
* @param {string[]} [transformations] - If omitted, {@link Synonomous.prototype.transformations} serves as a default.
* @constructor

@@ -66,4 +83,2 @@ */

/** A transformer that returns its input converted to a string with ` + '' `.
* @param {string} key
* @returns {string}
* @memberOf Synonomous#

@@ -83,4 +98,3 @@ */

*
* @param {string} key
* @returns {string}
* @type {Transformer}
* @memberOf Synonomous#

@@ -102,4 +116,3 @@ */

*
* @param {string} key
* @returns {string}
* @type {Transformer}
* @memberOf Synonomous#

@@ -116,11 +129,26 @@ */

/**
* If `name` is a string and non-blank, returns an array containing unique non-blank converted names, which typically includes `name` (when `toString` transformer is active).
* @param {string} name
* @returns {string[]}
* A transformer that separates camel case or white-space-, hyphen-, or underscore-separated-words into truly separate words and capitalizing the first letter of each.
*
* This transformer is meant to create column headers from column names. It deliberating inserts spaces so the results are unsuitable as JavaScript identifiers.
* @type {Transformer}
* @memberOf Synonomous#
*/
getSynonyms: function(name) {
toTitle: function(key) {
return (REGEXP_LOWER_CASE_LETTER.test(key) ? key : key.toLowerCase())
.replace(REGEXP_WORD_SEPARATORS, WITH_CAPTIAL_LETTER)
.replace(REGEXP_CAPITAL_LETTERS, WITH_PREFIXED_SPACE)
.replace(REGEXP_OVER_CAPITALIZED_WORDS, WITH_SEPARATE_WORDS)
.trim();
},
/**
* If `name` is a string and non-blank, returns an array containing unique non-blank converted names.
* @param {string} name - String to make synonyms of.
* @parma {string[]} transformations - When provided, temporarily overrides `this.transformations`.
* @memberOf Synonomous#
*/
getSynonyms: function(name, transforations) {
var synonyms = [];
if (typeof name === 'string' && name) {
this.transformations.forEach(function(key) {
(transforations || this.transformations).forEach(function(key) {
if (typeof this[key] !== 'function') {

@@ -127,0 +155,0 @@ throw new ReferenceError('Unknown transformer "' + key + '"');

{
"name": "synonomous",
"version": "1.0.0",
"version": "1.0.1",
"description": "Transform strings into synonyms for list decoration",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -95,1 +95,6 @@ # synonomous

The `verbatim` transformer does not prepend `$`. Any results that are integers that would overwrite existing array indexes are not added as properties.
### Revision History
* **1.0.1** — Added `toTitle` transformer.
* **1.0.0** — Initial release.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc