本文整理匯總了TypeScript中@ephox/dom-globals.localStorage類的典型用法代碼示例。如果您正苦於以下問題:TypeScript localStorage類的具體用法?TypeScript localStorage怎麽用?TypeScript localStorage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了localStorage類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
const getAllHistory = function (): Record<string, string[]> {
const unparsedHistory = localStorage.getItem(STORAGE_KEY);
if (unparsedHistory === null) {
return {};
}
// parse history
let history;
try {
history = JSON.parse(unparsedHistory);
} catch (e) {
if (e instanceof SyntaxError) {
console.log('Local storage ' + STORAGE_KEY + ' was not valid JSON', e);
return {};
}
throw e;
}
// validate the parsed value
if (!isRecordOfUrlArray(history)) {
console.log('Local storage ' + STORAGE_KEY + ' was not valid format', history);
return {};
}
return history;
};
示例2:
const sClearHistory = Step.sync(() => {
localStorage.removeItem('tinymce-url-history');
});