UNPKG

3.1 kBJavaScriptView Raw
1"use strict";
2/**
3 * Simple utility functions
4 * @module util
5 */
6var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7 if (k2 === undefined) k2 = k;
8 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9}) : (function(o, m, k, k2) {
10 if (k2 === undefined) k2 = k;
11 o[k2] = m[k];
12}));
13var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14 Object.defineProperty(o, "default", { enumerable: true, value: v });
15}) : function(o, v) {
16 o["default"] = v;
17});
18var __importStar = (this && this.__importStar) || function (mod) {
19 if (mod && mod.__esModule) return mod;
20 var result = {};
21 if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22 __setModuleDefault(result, mod);
23 return result;
24};
25var __importDefault = (this && this.__importDefault) || function (mod) {
26 return (mod && mod.__esModule) ? mod : { "default": mod };
27};
28Object.defineProperty(exports, "__esModule", { value: true });
29exports.isOneOf = exports.removeNilProperties = exports.deprecate = void 0;
30const curry_1 = __importDefault(require("lodash/curry"));
31const isNil_1 = __importDefault(require("lodash/isNil"));
32const omitBy_1 = __importDefault(require("lodash/omitBy"));
33const log = __importStar(require("./log"));
34/**
35 * Mark a piece of code as deprecated.
36 *
37 * Each deprecation notice for a given name and version combination will
38 * only be printed once.
39 *
40 * @param {string} name - the name of the function / method / class to deprecate
41 * @param {string} version - the version after which the code will be marked
42 * as deprecated
43 * @param {string} [alternative] - the function / method / class to use instead
44 * of this deprecated code
45 *
46 * @alias module:util
47 */
48exports.deprecate = (() => {
49 const warned = new Set();
50 return (name, version, alternative) => {
51 const key = `${name}-${version}`;
52 if (warned.has(key))
53 return;
54 warned.add(key);
55 let message = `${name} is deprecated after version ${version} and will be removed in a future release.`;
56 if (alternative)
57 message += ` Use ${alternative} instead.`;
58 log.warn(message);
59 };
60})();
61/**
62 * Remove properties whose values are `null` or `undefined`
63 *
64 * @param {Object} obj - object to update
65 * @returns {Object} a shallow clone of the object with `null` and `undefined`
66 * properties removed
67 *
68 * @alias module:util
69 */
70exports.removeNilProperties = (obj) => omitBy_1.default(obj, isNil_1.default);
71/**
72 * Test if a value is included in a list of items
73 *
74 * This is a curried function - https://lodash.com/docs/4.17.11#curry
75 *
76 * @param {Array} collection - the list of items to check against
77 * @param {Object} val - the item to check for in the collection
78 * @returns {boolean}
79 *
80 * @alias module:util
81 * @kind function
82 */
83exports.isOneOf = curry_1.default((collection, val) => collection.includes(val), 2);
84//# sourceMappingURL=util.js.map
\No newline at end of file