本文整理匯總了TypeScript中json-hammerhead.stringify函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript stringify函數的具體用法?TypeScript stringify怎麽用?TypeScript stringify使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了stringify函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: setFormInfo
export function setFormInfo (input, info) {
if (input.form) {
const hiddenInput = getInput(input.form);
nativeMethods.inputValueSetter.call(hiddenInput, JSON.stringify(info));
}
}
示例2: function
const sendMsg = (forced?: boolean) => {
this.activeServiceMessagesCounter++;
const isAsyncRequest = !forced;
const transport = this;
let request = XhrSandbox.createNativeXHR();
const msgCallback = function () {
// NOTE: The 500 status code is returned by server when an error occurred into service message handler
if (nativeMethods.xhrStatusGetter.call(this) === 500 && this.responseText) {
msg.disableResending = true;
errorHandler.call(this); // eslint-disable-line no-use-before-define
return;
}
transport.activeServiceMessagesCounter--;
const response = this.responseText && parseJSON(this.responseText);
request = null;
callback(null, response);
};
const errorHandler = function () {
if (msg.disableResending) {
transport.activeServiceMessagesCounter--;
let errorMsg = `XHR request failed with ${request.status} status code.`;
if (this.responseText)
errorMsg += `\nError message: ${this.responseText}`;
callback(new Error(errorMsg));
return;
}
if (isWebKit || isFirefox) {
Transport._storeMessage(msg);
msgCallback.call(this);
}
else
sendMsg(true);
};
XhrSandbox.openNativeXhr(request, settings.get().serviceMsgUrl, isAsyncRequest);
if (forced) {
request.addEventListener('readystatechange', function () {
if (this.readyState !== 4)
return;
msgCallback.call(this);
});
}
else {
request.addEventListener('load', msgCallback);
request.addEventListener('abort', errorHandler);
request.addEventListener('error', errorHandler);
request.addEventListener('timeout', errorHandler);
}
request.send(stringifyJSON(msg));
};
示例3: _removeMessageFromStore
static _removeMessageFromStore (cmd): void {
const messages = Transport._getStoredMessages();
for (let i = 0; i < messages.length; i++) {
if (messages[i].cmd === cmd) {
messages.splice(i, 1);
break;
}
}
nativeMethods.winLocalStorageGetter.call(window).setItem(settings.get().sessionId, stringifyJSON(messages));
}
示例4: _storeMessage
static _storeMessage (msg): void {
const storedMessages = Transport._getStoredMessages();
storedMessages.push(msg);
nativeMethods.winLocalStorageGetter.call(window).setItem(settings.get().sessionId, stringifyJSON(storedMessages));
}
示例5: backup
backup () {
return {
localStorage: JSON.stringify(this.localStorageWrapper.getCurrentState()),
sessionStorage: JSON.stringify(this.sessionStorageWrapper.getCurrentState())
};
}