MCPcopy
hub / github.com/processing/p5.js / storage

Function storage

src/data/local_storage.js:8–431  ·  view source on GitHub ↗

* @module Data * @submodule LocalStorage * * This module defines the p5 methods for working with local storage

(p5, fn)

Source from the content-addressed store, hash-verified

6 */
7
8function storage(p5, fn){
9 /**
10 * Stores a value in the web browser's local storage.
11 *
12 * Web browsers can save small amounts of data using the built-in
13 * <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage" target="_blank">localStorage object</a>.
14 * Data stored in `localStorage` can be retrieved at any point, even after
15 * refreshing a page or restarting the browser. Data are stored as key-value
16 * pairs.
17 *
18 * `storeItem()` makes it easy to store values in `localStorage` and
19 * <a href="#/p5/getItem">getItem()</a> makes it easy to retrieve them.
20 *
21 * The first parameter, `key`, is the name of the value to be stored as a
22 * string.
23 *
24 * The second parameter, `value`, is the value to be stored. Values can have
25 * any type.
26 *
27 * Note: Sensitive data such as passwords or personal information shouldn't be
28 * stored in `localStorage`.
29 *
30 * @method storeItem
31 * @for p5
32 * @param {String} key name of the value.
33 * @param {String|Number|Boolean|Object|Array} value value to be stored.
34 *
35 * @example
36 * function setup() {
37 * createCanvas(100, 100);
38 *
39 * // Store the player's name.
40 * storeItem('name', 'Feist');
41 *
42 * // Store the player's score.
43 * storeItem('score', 1234);
44 *
45 * describe('The text "Feist: 1234" written in black on a gray background.');
46 * }
47 *
48 * function draw() {
49 * background(200);
50 *
51 * // Style the text.
52 * textAlign(CENTER, CENTER);
53 * textSize(14);
54 *
55 * // Retrieve the name.
56 * let name = getItem('name');
57 *
58 * // Retrieve the score.
59 * let score = getItem('score');
60 *
61 * // Display the score.
62 * text(`${name}: ${score}`, 50, 50);
63 * }
64 *
65 * @example

Callers 2

local_storage.jsFile · 0.85
local_storage.jsFile · 0.85

Calls 2

_friendlyErrorMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected