Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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 2.1.1 to 2.1.2

21

index.js

@@ -5,2 +5,4 @@ 'use strict';

var REGEXP_INTEGER = /^\d+$/;
var optionNames = ['transformations', 'propPath', 'dictPath', 'force'];

@@ -15,4 +17,4 @@

* @param {string[]} [options.transformations] - If omitted, {@link Synonomous.prototype.transformations} serves as a default.
* @param {string} [options.propPath] - If omitted, {@link Synonomous.prototype.propPath} serves as a default.
* @param {string} [options.dictPath] - If omitted, {@link Synonomous.prototype.dictPath} serves as a default.
* @param {string|string[]} [options.propPath] - If omitted, {@link Synonomous.prototype.propPath} serves as a default.
* @param {string|string[]} [options.dictPath] - If omitted, {@link Synonomous.prototype.dictPath} serves as a default.
* @param {boolean} [options.force=false] - If truthy, new property values override existing values; else new values are discarded.

@@ -70,3 +72,3 @@ * @constructor

*
* @type {undefined|string[]}
* @type {undefined|string|string[]}
* @memberOf Synonomous#

@@ -144,6 +146,10 @@ */

var drilldownContext = drilldown(obj, this.dictPath),
decoratingObjectItself = drilldownContext === obj,
force = this.force;
propNames.forEach(function(propName) {
if (force || !(propName in drilldownContext)) {
if (
!(decoratingObjectItself && REGEXP_INTEGER.test(propName)) &&
(force || !(propName in drilldownContext))
) {
drilldownContext[propName] = item;

@@ -161,3 +167,3 @@ }

*
* That is, each element is either iteself converted to a string; or is an object with a property named by following `propPath` which is converted to a string.
* That is, each element is either itself converted to a string; or is an object with a property named by following `propPath` which is converted to a string.
*

@@ -168,4 +174,5 @@ * For each element, all transformers named in `this.transformations` are run on that string.

* Specifically: All the resulting unique non-blank "synonyms" are added as properties to the array with the value of the property being a reference to the element (if it was an object) or a copy of the element (if it was a string), subject to the following rules:
* 1. Duplicate synonyms are not added.
* 1. Duplicate synonyms are not added (unless `this.force` is truthy).
* 2. Blank synonyms are not added.
* 3. Integer synonyms are not added because they are indistinguishable from and may clash with array indexes.
* * _When `this.transformations` is an non-array object:_

@@ -177,3 +184,3 @@ * **Create a new property inside the element for each transformation.**

* 1. Adds synonyms for all elements of `list`.
* 2. `list` and `index` are promoted to the 1st and 2nd parameter positions, respectively.
* 2. `list` and `propPath` are promoted to the 1st and 2nd parameter positions, respectively.
* @param {(string|Object.<string, string>)[]} list - Array whose element(s) to make synonyms of _and_ the object to decorate. If `this.dictPath` is defined, then decorate `list[this.dictPath]` instead (created as needed).

@@ -180,0 +187,0 @@ * @param {string} [propPath=this.propPath] - Name of the property in each element of `list` to make synonyms of. If defined _and_ list element is an object, adds synonyms of `list[propPath]` as string; else adds synonyms of the list element itself as string.

{
"name": "synonomous",
"version": "2.1.1",
"version": "2.1.2",
"description": "Decorate an array instance with synonyms of its elements",

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

@@ -239,2 +239,3 @@ # synonomous

* **2.1.2** - `decorate` no longer adds integer synonyms because they are indistinguishable from and may clash with array indexes. (This is aimed at the `verbatim` transformer; the `toCamelCase` and `toAllCaps` transformers never return integer synonyms because they always prepend a `$` character to synonyms beginning with a digit.)
* **2.1.1** — Added `force` property to force overwriting existing property values with new values. Otherwise new values are discarded.

@@ -249,3 +250,3 @@ * **2.1.0** — `transformations` property can now be an object as well an array of strings. The keys of the object name the transformers. The values are not used by `decorateObject` but are used by `decorateArray` to add new string properties to each element.

* Added `decorate` method and `dictPath` property.
* Changed `propPath` property to `propPath`. _(Breaking change if property used.)_
* Changed `propName` property to `propPath`. _(Breaking change if property used.)_
* Changed optional constructor params to a single `options` object. _(Breaking change if params were used.)_

@@ -252,0 +253,0 @@ * Moved transformers to their own file. _(Breaking change if you want to override and exsiting transformer or add a custom transformer.)_

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