source: trip-planner-front/node_modules/union-value/index.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 700 bytes
Line 
1'use strict';
2
3var isObject = require('is-extendable');
4var union = require('arr-union');
5var get = require('get-value');
6var set = require('set-value');
7
8module.exports = function unionValue(obj, prop, value) {
9 if (!isObject(obj)) {
10 throw new TypeError('union-value expects the first argument to be an object.');
11 }
12
13 if (typeof prop !== 'string') {
14 throw new TypeError('union-value expects `prop` to be a string.');
15 }
16
17 var arr = arrayify(get(obj, prop));
18 set(obj, prop, union(arr, arrayify(value)));
19 return obj;
20};
21
22function arrayify(val) {
23 if (val === null || typeof val === 'undefined') {
24 return [];
25 }
26 if (Array.isArray(val)) {
27 return val;
28 }
29 return [val];
30}
Note: See TracBrowser for help on using the repository browser.