CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-store

A localStorage wrapper for all browsers without using cookies or flash, providing persistent client-side storage with automatic fallback and plugin architecture

75

0.96x
Overview
Eval results
Files

task.mdevals/scenario-5/

Legacy Data Migration Tool

A utility that safely reads and normalizes data stored by various systems in localStorage. The tool must handle data that may have been stored using different serialization approaches, including raw strings, pre-stringified JSON, and improperly formatted values.

Capabilities

Reads values with different serialization formats

  • It retrieves a value that was stored as a raw string (not JSON-stringified) @test
  • It retrieves a value that was stored as JSON-stringified data @test
  • It retrieves a value that was stored as a double-stringified JSON (accidentally stringified twice) @test

Handles malformed or corrupted data gracefully

  • It handles values with invalid JSON syntax without throwing errors @test
  • It handles values with partial JSON fragments @test

Stores values consistently

  • It stores string values in a way that they can be retrieved correctly @test
  • It stores object values with proper serialization @test

Implementation

@generates

API

/**
 * Safely retrieves a value from localStorage with automatic deserialization.
 * Handles raw strings, JSON-stringified values, and malformed data.
 *
 * @param {string} key - The key to retrieve
 * @param {*} defaultValue - Optional default value if key doesn't exist
 * @returns {*} The retrieved and deserialized value, or defaultValue if not found
 */
function safeGet(key, defaultValue) {
  // IMPLEMENTATION HERE
}

/**
 * Stores a value in localStorage with automatic serialization.
 *
 * @param {string} key - The key to store under
 * @param {*} value - The value to store
 * @returns {*} The stored value
 */
function safeSet(key, value) {
  // IMPLEMENTATION HERE
}

/**
 * Removes a value from localStorage.
 *
 * @param {string} key - The key to remove
 */
function safeRemove(key) {
  // IMPLEMENTATION HERE
}

module.exports = {
  safeGet,
  safeSet,
  safeRemove
};

Dependencies { .dependencies }

store { .dependency }

Provides cross-browser local storage support with automatic serialization and deserialization.

Install with Tessl CLI

npx tessl i tessl/npm-store

tile.json