本文整理汇总了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())
};
}