Skip to content

Commit ea876d6

Browse files
committed
Limit set function to the scope where it is used
1 parent 3127185 commit ea876d6

2 files changed

Lines changed: 14 additions & 22 deletions

File tree

lib/helper.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,6 @@ function get (obj, path) {
118118
return obj;
119119
}
120120

121-
/**
122-
* Set a nested property of an object.
123-
*
124-
* @param { object } obj The object to modify.
125-
* @param { string[] } path The path to the property.
126-
* @param { any } value The value to set.
127-
*/
128-
function set (obj, path, value) {
129-
const valueKey = path.pop();
130-
for (const key of path) {
131-
let nested = obj[key];
132-
if (!nested) {
133-
nested = {};
134-
obj[key] = nested;
135-
}
136-
obj = nested;
137-
}
138-
obj[valueKey] = value;
139-
}
140-
141121
/**
142122
* Deduplicate an array by a given key callback.
143123
* Item properties are merged recursively and with the preference for last defined values.
@@ -171,7 +151,6 @@ module.exports = {
171151
mergeDuplicatesPreferLast: mergeDuplicatesPreferLast,
172152
numberToLetterSequence: numberToLetterSequence,
173153
numberToRoman: numberToRoman,
174-
set: set,
175154
splitClassesAndIds: splitClassesAndIds,
176155
trimCharacter: trimCharacter
177156
};

lib/html-to-text.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const selderee = require('selderee');
66

77
const { BlockTextBuilder } = require('./block-text-builder');
88
const defaultFormatters = require('./formatter');
9-
const { limitedDepthRecursive, mergeDuplicatesPreferLast, set } = require('./helper');
9+
const { limitedDepthRecursive, mergeDuplicatesPreferLast } = require('./helper');
1010

1111
// eslint-disable-next-line import/no-unassigned-import
1212
require('./typedefs');
@@ -241,6 +241,19 @@ function handleDeprecatedOptions (options) {
241241
selectorDefinitions.push(...tagDefinitions);
242242
}
243243

244+
function set (obj, path, value) {
245+
const valueKey = path.pop();
246+
for (const key of path) {
247+
let nested = obj[key];
248+
if (!nested) {
249+
nested = {};
250+
obj[key] = nested;
251+
}
252+
obj = nested;
253+
}
254+
obj[valueKey] = value;
255+
}
256+
244257
function copyFormatterOption (source, format, target) {
245258
if (options[source] === undefined) { return; }
246259
for (const definition of selectorDefinitions) {

0 commit comments

Comments
 (0)