Initial commit

This commit is contained in:
2025-03-07 19:22:02 +01:00
commit 4a98255d83
55743 changed files with 5280367 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
BSD 3-Clause License
Copyright (c) 2016, Mermade Software
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+3
View File
@@ -0,0 +1,3 @@
# oas-kit-common
Common utility functions for oas-kit
+137
View File
@@ -0,0 +1,137 @@
'use strict';
const sjs = require('fast-safe-stringify');
const colour = process.env.NODE_DISABLE_COLORS ?
{ red: '', yellow: '', green: '', normal: '' } :
{ red: '\x1b[31m', yellow: '\x1b[33;1m', green: '\x1b[32m', normal: '\x1b[0m' };
function uniqueOnly(value, index, self) {
return self.indexOf(value) === index;
}
function hasDuplicates(array) {
return (new Set(array)).size !== array.length;
}
function allSame(array) {
return (new Set(array)).size <= 1;
}
function deepEquals(obj1, obj2) {
function _equals(obj1, obj2) {
return sjs.stringify(obj1) === sjs.stringify(Object.assign({}, obj1, obj2));
}
return _equals(obj1, obj2) && _equals(obj2, obj1);
}
function compressArray(arr) {
let result = [];
for (let candidate of arr) {
let dupe = result.find(function(e,i,a){
return deepEquals(e,candidate);
});
if (!dupe) result.push(candidate);
}
return result;
}
function distinctArray(arr) {
return (arr.length === compressArray(arr).length);
}
function firstDupe(arr) {
return arr.find(function(e,i,a){
return arr.indexOf(e)<i;
});
}
/**
* simple hash implementation based on https://stackoverflow.com/a/7616484/1749888
* @param {string} s - string to hash
* @returns {number} numerical hash code
*/
function hash(s) {
let hash = 0;
let chr;
if (s.length === 0) return hash;
for (let i = 0; i < s.length; i++) {
chr = s.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
}
String.prototype.toCamelCase = function camelize() {
return this.toLowerCase().replace(/[-_ \/\.](.)/g, function (match, group1) {
return group1.toUpperCase();
});
}
const parameterTypeProperties = [
'format',
'minimum',
'maximum',
'exclusiveMinimum',
'exclusiveMaximum',
'minLength',
'maxLength',
'multipleOf',
'minItems',
'maxItems',
'uniqueItems',
'minProperties',
'maxProperties',
'additionalProperties',
'pattern',
'enum',
'default'
];
const arrayProperties = [
'items',
'minItems',
'maxItems',
'uniqueItems'
];
const httpMethods = [
'get',
'post',
'put',
'delete',
'patch',
'head',
'options',
'trace'
];
function sanitise(s) {
s = s.replace('[]','Array');
let components = s.split('/');
components[0] = components[0].replace(/[^A-Za-z0-9_\-\.]+|\s+/gm, '_');
return components.join('/');
}
function sanitiseAll(s) {
return sanitise(s.split('/').join('_'));
}
module.exports = {
colour: colour,
uniqueOnly: uniqueOnly,
hasDuplicates: hasDuplicates,
allSame: allSame,
distinctArray: distinctArray,
firstDupe: firstDupe,
hash: hash,
parameterTypeProperties: parameterTypeProperties,
arrayProperties: arrayProperties,
httpMethods: httpMethods,
sanitise: sanitise,
sanitiseAll: sanitiseAll
};
+28
View File
@@ -0,0 +1,28 @@
{
"name": "oas-kit-common",
"version": "1.0.8",
"description": "Common utility functions for oas-kit",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"openapi",
"swagger",
"oas",
"utility"
],
"author": "Mike Ralphson",
"dependencies": {
"fast-safe-stringify": "^2.0.7"
},
"license": "BSD-3-Clause",
"repository": {
"type": "git",
"url": "https://github.com/Mermade/oas-kit.git"
},
"bugs": {
"url": "https://github.com/mermade/oas-kit/issues"
},
"gitHead": "d45ad2a14dede9aa5175d5815cbbba4e75191e82"
}