@coscine/app-util
Advanced tools
Comparing version 1.3.2 to 1.4.0
@@ -9,4 +9,6 @@ var LanguageUtil = /** @class */ (function () { | ||
switch (coscine.language.locale) { | ||
case 'de': return coscine.language.locale; | ||
default: return 'en'; | ||
case 'de': | ||
return coscine.language.locale; | ||
default: | ||
return 'en'; | ||
} | ||
@@ -39,9 +41,3 @@ }; | ||
GuidUtil.getProjectId = function () { | ||
var baseUrl = _spPageContextInfo.siteAbsoluteUrl; | ||
var splitUrl = baseUrl.split('/'); | ||
var projectUri = splitUrl[splitUrl.length - 1]; | ||
if (this.isValidGuid(projectUri)) { | ||
return projectUri; | ||
} | ||
return ''; | ||
return coscine.project.id; | ||
}; | ||
@@ -68,3 +64,111 @@ return GuidUtil; | ||
export { FileUtil, GuidUtil, LanguageUtil }; | ||
var LinkUtil = /** @class */ (function () { | ||
function LinkUtil() { | ||
} | ||
LinkUtil.getProjectSlug = function () { | ||
var baseUrl = _spPageContextInfo.siteAbsoluteUrl; | ||
var splitUrl = baseUrl.split('/'); | ||
var projectUri = splitUrl[splitUrl.length - 1]; | ||
return projectUri; | ||
}; | ||
LinkUtil.getHostName = function () { | ||
var hostName = window.location.hostname; | ||
if (hostName.indexOf(':') !== -1) { | ||
if (hostName.indexOf('https://') !== -1) { | ||
hostName = hostName.replace('https://', ''); | ||
} | ||
hostName = hostName.substr(0, hostName.indexOf(':')); | ||
} | ||
return hostName; | ||
}; | ||
LinkUtil.getRootLink = function (page, queryParams, hashTag) { | ||
if (page === void 0) { page = 'Home'; } | ||
if (queryParams === void 0) { queryParams = {}; } | ||
if (hashTag === void 0) { hashTag = ''; } | ||
return (this.formatLink('', page) + this.formatQueryParams(queryParams) + this.formatHashTag(hashTag)); | ||
}; | ||
LinkUtil.getProjectLink = function (page, queryParams, hashTag) { | ||
if (page === void 0) { page = 'Home'; } | ||
if (queryParams === void 0) { queryParams = {}; } | ||
if (hashTag === void 0) { hashTag = ''; } | ||
return (this.formatLink(this.getProjectSlug(), page) + | ||
this.formatQueryParams(queryParams) + | ||
this.formatHashTag(hashTag)); | ||
}; | ||
LinkUtil.getExternalProjectLink = function (projectSlug, page, queryParams, hashTag) { | ||
if (projectSlug === void 0) { projectSlug = this.getProjectSlug(); } | ||
if (page === void 0) { page = 'Home'; } | ||
if (queryParams === void 0) { queryParams = {}; } | ||
if (hashTag === void 0) { hashTag = ''; } | ||
return (this.formatLink(projectSlug, page) + | ||
this.formatQueryParams(queryParams) + | ||
this.formatHashTag(hashTag)); | ||
}; | ||
LinkUtil.redirectToRoot = function (page, queryParams, hashTag) { | ||
if (page === void 0) { page = 'Home'; } | ||
if (queryParams === void 0) { queryParams = {}; } | ||
if (hashTag === void 0) { hashTag = ''; } | ||
window.location.href = this.getRootLink(page, queryParams, hashTag); | ||
}; | ||
LinkUtil.redirectToProject = function (page, queryParams, hashTag) { | ||
if (page === void 0) { page = 'Home'; } | ||
if (queryParams === void 0) { queryParams = {}; } | ||
if (hashTag === void 0) { hashTag = ''; } | ||
window.location.href = this.getProjectLink(page, queryParams, hashTag); | ||
}; | ||
LinkUtil.redirectToExternalProject = function (projectSlug, page, queryParams, hashTag) { | ||
if (projectSlug === void 0) { projectSlug = this.getProjectSlug(); } | ||
if (page === void 0) { page = 'Home'; } | ||
if (queryParams === void 0) { queryParams = {}; } | ||
if (hashTag === void 0) { hashTag = ''; } | ||
window.location.href = this.getExternalProjectLink(projectSlug, page, queryParams, hashTag); | ||
}; | ||
LinkUtil.getScriptPath = function (pathToAppJs) { | ||
var scriptUrl = pathToAppJs === '' ? '/' : pathToAppJs.substring(0, pathToAppJs.indexOf('app.js')); | ||
var rootUrl = pathToAppJs.indexOf('/js') !== -1 ? scriptUrl.replace('/js', '') : scriptUrl; | ||
return rootUrl; | ||
}; | ||
LinkUtil.formatQueryParams = function (queryParams) { | ||
var queryString = ''; | ||
if (queryParams !== null && queryParams !== undefined) { | ||
var prop = Object.getOwnPropertyNames(queryParams); | ||
if (prop.length > 0) { | ||
for (var i = 0; i < prop.length; i++) { | ||
if (i === 0) { | ||
queryString += '?'; | ||
} | ||
else { | ||
queryString += '&'; | ||
} | ||
queryString += prop[i] + '=' + queryParams[prop[i]]; | ||
} | ||
} | ||
} | ||
return queryString; | ||
}; | ||
LinkUtil.formatHashTag = function (hashTag) { | ||
var addToLink = ''; | ||
if (hashTag !== '') { | ||
addToLink = '#' + hashTag; | ||
} | ||
return addToLink; | ||
}; | ||
LinkUtil.formatLink = function (projectSlug, page) { | ||
if (projectSlug === void 0) { projectSlug = ''; } | ||
if (page === void 0) { page = 'Home'; } | ||
var projectLinkPart = ''; | ||
if (projectSlug !== '') { | ||
projectLinkPart += 'p/' + projectSlug.toLowerCase() + '/'; | ||
} | ||
var pageLinkPart = ''; | ||
if (page.indexOf('/') === -1) { | ||
pageLinkPart += 'SitePages/'; | ||
} | ||
pageLinkPart += page + '.aspx'; | ||
return 'https://' + this.getHostName() + '/' + projectLinkPart + pageLinkPart; | ||
}; | ||
return LinkUtil; | ||
}()); | ||
export { FileUtil, GuidUtil, LanguageUtil, LinkUtil }; | ||
//# sourceMappingURL=app-util.es5.js.map |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.appUtil = {})); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.appUtil = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
var LanguageUtil = /** @class */ (function () { | ||
function LanguageUtil() { | ||
} | ||
LanguageUtil.getLanguage = function () { | ||
if (!coscine || !coscine.language || !coscine.language.locale) { | ||
return 'en'; | ||
} | ||
switch (coscine.language.locale) { | ||
case 'de': return coscine.language.locale; | ||
default: return 'en'; | ||
} | ||
}; | ||
return LanguageUtil; | ||
}()); | ||
var LanguageUtil = /** @class */ (function () { | ||
function LanguageUtil() { | ||
} | ||
LanguageUtil.getLanguage = function () { | ||
if (!coscine || !coscine.language || !coscine.language.locale) { | ||
return 'en'; | ||
} | ||
switch (coscine.language.locale) { | ||
case 'de': | ||
return coscine.language.locale; | ||
default: | ||
return 'en'; | ||
} | ||
}; | ||
return LanguageUtil; | ||
}()); | ||
var GuidUtil = /** @class */ (function () { | ||
function GuidUtil() { | ||
} | ||
GuidUtil.isValidGuid = function (guid) { | ||
if (guid !== null && | ||
typeof guid === 'string' && | ||
guid.match(/[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}/i)) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
GuidUtil.getResourceId = function () { | ||
var urlParams = new URLSearchParams(window.location.search); | ||
if (urlParams.has('resource_id')) { | ||
var urlResourceId = urlParams.get('resource_id'); | ||
if (this.isValidGuid(urlResourceId)) { | ||
return urlResourceId; | ||
} | ||
} | ||
return ''; | ||
}; | ||
GuidUtil.getProjectId = function () { | ||
var baseUrl = _spPageContextInfo.siteAbsoluteUrl; | ||
var splitUrl = baseUrl.split('/'); | ||
var projectUri = splitUrl[splitUrl.length - 1]; | ||
if (this.isValidGuid(projectUri)) { | ||
return projectUri; | ||
} | ||
return ''; | ||
}; | ||
return GuidUtil; | ||
}()); | ||
var GuidUtil = /** @class */ (function () { | ||
function GuidUtil() { | ||
} | ||
GuidUtil.isValidGuid = function (guid) { | ||
if (guid !== null && | ||
typeof guid === 'string' && | ||
guid.match(/[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}/i)) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
GuidUtil.getResourceId = function () { | ||
var urlParams = new URLSearchParams(window.location.search); | ||
if (urlParams.has('resource_id')) { | ||
var urlResourceId = urlParams.get('resource_id'); | ||
if (this.isValidGuid(urlResourceId)) { | ||
return urlResourceId; | ||
} | ||
} | ||
return ''; | ||
}; | ||
GuidUtil.getProjectId = function () { | ||
return coscine.project.id; | ||
}; | ||
return GuidUtil; | ||
}()); | ||
var FileUtil = /** @class */ (function () { | ||
function FileUtil() { | ||
} | ||
FileUtil.formatBytes = function (bytes, decimals) { | ||
if (decimals === void 0) { decimals = 2; } | ||
if (bytes === 0) { | ||
return '0 Bytes'; | ||
} | ||
var k = 1024; | ||
var dm = decimals < 0 ? 0 : decimals; | ||
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; | ||
var i = Math.floor(Math.log(bytes) / Math.log(k)); | ||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; | ||
}; | ||
return FileUtil; | ||
}()); | ||
var FileUtil = /** @class */ (function () { | ||
function FileUtil() { | ||
} | ||
FileUtil.formatBytes = function (bytes, decimals) { | ||
if (decimals === void 0) { decimals = 2; } | ||
if (bytes === 0) { | ||
return '0 Bytes'; | ||
} | ||
var k = 1024; | ||
var dm = decimals < 0 ? 0 : decimals; | ||
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; | ||
var i = Math.floor(Math.log(bytes) / Math.log(k)); | ||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; | ||
}; | ||
return FileUtil; | ||
}()); | ||
exports.FileUtil = FileUtil; | ||
exports.GuidUtil = GuidUtil; | ||
exports.LanguageUtil = LanguageUtil; | ||
var LinkUtil = /** @class */ (function () { | ||
function LinkUtil() { | ||
} | ||
LinkUtil.getProjectSlug = function () { | ||
var baseUrl = _spPageContextInfo.siteAbsoluteUrl; | ||
var splitUrl = baseUrl.split('/'); | ||
var projectUri = splitUrl[splitUrl.length - 1]; | ||
return projectUri; | ||
}; | ||
LinkUtil.getHostName = function () { | ||
var hostName = window.location.hostname; | ||
if (hostName.indexOf(':') !== -1) { | ||
if (hostName.indexOf('https://') !== -1) { | ||
hostName = hostName.replace('https://', ''); | ||
} | ||
hostName = hostName.substr(0, hostName.indexOf(':')); | ||
} | ||
return hostName; | ||
}; | ||
LinkUtil.getRootLink = function (page, queryParams, hashTag) { | ||
if (page === void 0) { page = 'Home'; } | ||
if (queryParams === void 0) { queryParams = {}; } | ||
if (hashTag === void 0) { hashTag = ''; } | ||
return (this.formatLink('', page) + this.formatQueryParams(queryParams) + this.formatHashTag(hashTag)); | ||
}; | ||
LinkUtil.getProjectLink = function (page, queryParams, hashTag) { | ||
if (page === void 0) { page = 'Home'; } | ||
if (queryParams === void 0) { queryParams = {}; } | ||
if (hashTag === void 0) { hashTag = ''; } | ||
return (this.formatLink(this.getProjectSlug(), page) + | ||
this.formatQueryParams(queryParams) + | ||
this.formatHashTag(hashTag)); | ||
}; | ||
LinkUtil.getExternalProjectLink = function (projectSlug, page, queryParams, hashTag) { | ||
if (projectSlug === void 0) { projectSlug = this.getProjectSlug(); } | ||
if (page === void 0) { page = 'Home'; } | ||
if (queryParams === void 0) { queryParams = {}; } | ||
if (hashTag === void 0) { hashTag = ''; } | ||
return (this.formatLink(projectSlug, page) + | ||
this.formatQueryParams(queryParams) + | ||
this.formatHashTag(hashTag)); | ||
}; | ||
LinkUtil.redirectToRoot = function (page, queryParams, hashTag) { | ||
if (page === void 0) { page = 'Home'; } | ||
if (queryParams === void 0) { queryParams = {}; } | ||
if (hashTag === void 0) { hashTag = ''; } | ||
window.location.href = this.getRootLink(page, queryParams, hashTag); | ||
}; | ||
LinkUtil.redirectToProject = function (page, queryParams, hashTag) { | ||
if (page === void 0) { page = 'Home'; } | ||
if (queryParams === void 0) { queryParams = {}; } | ||
if (hashTag === void 0) { hashTag = ''; } | ||
window.location.href = this.getProjectLink(page, queryParams, hashTag); | ||
}; | ||
LinkUtil.redirectToExternalProject = function (projectSlug, page, queryParams, hashTag) { | ||
if (projectSlug === void 0) { projectSlug = this.getProjectSlug(); } | ||
if (page === void 0) { page = 'Home'; } | ||
if (queryParams === void 0) { queryParams = {}; } | ||
if (hashTag === void 0) { hashTag = ''; } | ||
window.location.href = this.getExternalProjectLink(projectSlug, page, queryParams, hashTag); | ||
}; | ||
LinkUtil.getScriptPath = function (pathToAppJs) { | ||
var scriptUrl = pathToAppJs === '' ? '/' : pathToAppJs.substring(0, pathToAppJs.indexOf('app.js')); | ||
var rootUrl = pathToAppJs.indexOf('/js') !== -1 ? scriptUrl.replace('/js', '') : scriptUrl; | ||
return rootUrl; | ||
}; | ||
LinkUtil.formatQueryParams = function (queryParams) { | ||
var queryString = ''; | ||
if (queryParams !== null && queryParams !== undefined) { | ||
var prop = Object.getOwnPropertyNames(queryParams); | ||
if (prop.length > 0) { | ||
for (var i = 0; i < prop.length; i++) { | ||
if (i === 0) { | ||
queryString += '?'; | ||
} | ||
else { | ||
queryString += '&'; | ||
} | ||
queryString += prop[i] + '=' + queryParams[prop[i]]; | ||
} | ||
} | ||
} | ||
return queryString; | ||
}; | ||
LinkUtil.formatHashTag = function (hashTag) { | ||
var addToLink = ''; | ||
if (hashTag !== '') { | ||
addToLink = '#' + hashTag; | ||
} | ||
return addToLink; | ||
}; | ||
LinkUtil.formatLink = function (projectSlug, page) { | ||
if (projectSlug === void 0) { projectSlug = ''; } | ||
if (page === void 0) { page = 'Home'; } | ||
var projectLinkPart = ''; | ||
if (projectSlug !== '') { | ||
projectLinkPart += 'p/' + projectSlug.toLowerCase() + '/'; | ||
} | ||
var pageLinkPart = ''; | ||
if (page.indexOf('/') === -1) { | ||
pageLinkPart += 'SitePages/'; | ||
} | ||
pageLinkPart += page + '.aspx'; | ||
return 'https://' + this.getHostName() + '/' + projectLinkPart + pageLinkPart; | ||
}; | ||
return LinkUtil; | ||
}()); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.FileUtil = FileUtil; | ||
exports.GuidUtil = GuidUtil; | ||
exports.LanguageUtil = LanguageUtil; | ||
exports.LinkUtil = LinkUtil; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
//# sourceMappingURL=app-util.umd.js.map |
@@ -9,2 +9,4 @@ "use strict"; | ||
exports.FileUtil = file_1.FileUtil; | ||
var link_1 = require("./util/link"); | ||
exports.LinkUtil = link_1.LinkUtil; | ||
//# sourceMappingURL=app-util.js.map |
@@ -25,9 +25,3 @@ "use strict"; | ||
GuidUtil.getProjectId = function () { | ||
var baseUrl = _spPageContextInfo.siteAbsoluteUrl; | ||
var splitUrl = baseUrl.split('/'); | ||
var projectUri = splitUrl[splitUrl.length - 1]; | ||
if (this.isValidGuid(projectUri)) { | ||
return projectUri; | ||
} | ||
return ''; | ||
return coscine.project.id; | ||
}; | ||
@@ -34,0 +28,0 @@ return GuidUtil; |
@@ -11,4 +11,6 @@ "use strict"; | ||
switch (coscine.language.locale) { | ||
case 'de': return coscine.language.locale; | ||
default: return 'en'; | ||
case 'de': | ||
return coscine.language.locale; | ||
default: | ||
return 'en'; | ||
} | ||
@@ -15,0 +17,0 @@ }; |
export { LanguageUtil } from './util/language'; | ||
export { GuidUtil } from './util/guid'; | ||
export { FileUtil } from './util/file'; | ||
export { LinkUtil } from './util/link'; |
export declare class GuidUtil { | ||
static isValidGuid(guid: any): boolean; | ||
static getResourceId(): string | null; | ||
static getProjectId(): any; | ||
static getProjectId(): string; | ||
} |
{ | ||
"name": "@coscine/app-util", | ||
"version": "1.3.2", | ||
"version": "1.4.0", | ||
"description": "This library provides utility methods for the CoScInE Apps with JavaScript.", | ||
@@ -78,3 +78,3 @@ "keywords": [ | ||
"prettier": { | ||
"semi": false, | ||
"semi": true, | ||
"singleQuote": true | ||
@@ -81,0 +81,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
64452
23
560