source: frontend/node_modules/tough-cookie/lib/validators.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/* ************************************************************************************
2Extracted from check-types.js
3https://gitlab.com/philbooth/check-types.js
4
5MIT License
6
7Copyright (c) 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Phil Booth
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in all
17copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25SOFTWARE.
26
27************************************************************************************ */
28"use strict";
29
30/* Validation functions copied from check-types package - https://www.npmjs.com/package/check-types */
31
32const toString = Object.prototype.toString;
33
34function isFunction(data) {
35 return typeof data === "function";
36}
37
38function isNonEmptyString(data) {
39 return isString(data) && data !== "";
40}
41
42function isDate(data) {
43 return isInstanceStrict(data, Date) && isInteger(data.getTime());
44}
45
46function isEmptyString(data) {
47 return data === "" || (data instanceof String && data.toString() === "");
48}
49
50function isString(data) {
51 return typeof data === "string" || data instanceof String;
52}
53
54function isObject(data) {
55 return toString.call(data) === "[object Object]";
56}
57function isInstanceStrict(data, prototype) {
58 try {
59 return data instanceof prototype;
60 } catch (error) {
61 return false;
62 }
63}
64
65function isUrlStringOrObject(data) {
66 return (
67 isNonEmptyString(data) ||
68 (isObject(data) &&
69 "hostname" in data &&
70 "pathname" in data &&
71 "protocol" in data) ||
72 isInstanceStrict(data, URL)
73 );
74}
75
76function isInteger(data) {
77 return typeof data === "number" && data % 1 === 0;
78}
79/* End validation functions */
80
81function validate(bool, cb, options) {
82 if (!isFunction(cb)) {
83 options = cb;
84 cb = null;
85 }
86 if (!isObject(options)) options = { Error: "Failed Check" };
87 if (!bool) {
88 if (cb) {
89 cb(new ParameterError(options));
90 } else {
91 throw new ParameterError(options);
92 }
93 }
94}
95
96class ParameterError extends Error {
97 constructor(...params) {
98 super(...params);
99 }
100}
101
102exports.ParameterError = ParameterError;
103exports.isFunction = isFunction;
104exports.isNonEmptyString = isNonEmptyString;
105exports.isDate = isDate;
106exports.isEmptyString = isEmptyString;
107exports.isString = isString;
108exports.isObject = isObject;
109exports.isUrlStringOrObject = isUrlStringOrObject;
110exports.validate = validate;
Note: See TracBrowser for help on using the repository browser.