@workfront/cookie
Version:
Extracts values from workfront cookies
95 lines (88 loc) • 3.78 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.WorkfrontCookie = {}));
})(this, (function (exports) { 'use strict';
/**
* Copyright 2016 Workfront
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var COOKIE_NAME = 'attask';
/**
* Copyright 2016 Workfront
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function readCookie(name, cookieString) {
cookieString = cookieString || document.cookie;
var match = cookieString.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
if (match) {
return decodeURIComponent(match[3]);
}
}
/**
* Copyright 2016 Workfront
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function getSessionID(cookieString) {
var cookie = readCookie(COOKIE_NAME, cookieString);
if (cookie) {
return cookie.split('#')[0];
}
}
/**
* Copyright 2016 Workfront
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function getXSRFToken(cookieString) {
return readCookie('XSRF-TOKEN', cookieString) || undefined;
}
exports.COOKIE_NAME = COOKIE_NAME;
exports.getSessionID = getSessionID;
exports.getXSRFToken = getXSRFToken;
exports.readCookie = readCookie;
}));
//# sourceMappingURL=workfront-cookie.js.map