@sync-in/server
Version:
The secure, open-source platform for file storage, sharing, collaboration, and sync
105 lines (104 loc) • 3.06 kB
JavaScript
/*
* Copyright (C) 2012-2025 Johan Legrand <johan.legrand@sync-in.com>
* This file is part of Sync-in | The open source file sync and share solution
* See the LICENSE file for licensing details
*/ // eslint-disable-next-line no-control-regex
;
Object.defineProperty(exports, "__esModule", {
value: true
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: Object.getOwnPropertyDescriptor(all, name).get
});
}
_export(exports, {
get capitalizeString () {
return capitalizeString;
},
get createSlug () {
return createSlug;
},
get currentDate () {
return currentDate;
},
get currentTimeStamp () {
return currentTimeStamp;
},
get decodeUrl () {
return decodeUrl;
},
get encodeUrl () {
return encodeUrl;
},
get forbiddenChars () {
return forbiddenChars;
},
get isValidFileName () {
return isValidFileName;
},
get objectPropertyFromString () {
return objectPropertyFromString;
},
get popFromObject () {
return popFromObject;
},
get regExpInvalidFileName () {
return regExpInvalidFileName;
},
get regExpNumberSuffix () {
return regExpNumberSuffix;
},
get regExpPreventPathTraversal () {
return regExpPreventPathTraversal;
}
});
const regExpInvalidFileName = /^(?:CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])$|[<>:"/\\|?*\x00-\x1f\x80-\x9f]/;
const regExpPreventPathTraversal = /^(\.\.(\/|\\|$))+/;
const regExpNumberSuffix = /-\d+$/;
const forbiddenChars = '\\ / : * ? " < > |';
function isValidFileName(fileName) {
if (regExpInvalidFileName.test(fileName)) {
throw new Error('Forbidden characters');
}
}
function currentTimeStamp(date, ms = false) {
return Math.floor((date ? date : new Date()).getTime() / (ms ? 1 : 1000));
}
function currentDate(value) {
return new Date((value ? value : new Date().toISOString()).split('T')[0]);
}
function createSlug(input, replaceCount = false) {
const r = input.toLowerCase().trim().replace(/[\s_-]+/g, '-').replace(/^-+|-+$/g, '').normalize('NFD').replace(/[\u0300-\u036f]/g, '');
if (replaceCount) return r.replace(regExpNumberSuffix, '');
return r;
}
function popFromObject(key, object) {
const item = object[key];
delete object[key];
return item;
}
function encodeUrl(url) {
return url.split('/').map((e)=>encodeURIComponent(e)).join('/');
}
function decodeUrl(url) {
return url.split('/').map((e)=>decodeURIComponent(e)).join('/');
}
function objectPropertyFromString(obj, property) {
const a = property.split('.');
let o = obj;
for(let i = 0, n = a.length; i < n; i++){
const k = a[i];
if (k in o) {
o = o[k];
} else {
return null;
}
}
return o;
}
function capitalizeString(value) {
return value.charAt(0).toUpperCase() + value.slice(1);
}
//# sourceMappingURL=shared.js.map