API Docs for: 1.2
Show:

hoon.WebStorage Class

Defined in: src/hoon.js:436

The Base Class of hoon.localStorage and hoon.sessionStorage. You cannot access this class.

This class extends the Storage Interface. In the Storage interface, you must typically use the JSON object for parsing and serializing. On the other hand, in this class you don't have to use the JSON object. This class internally parses and serializes data using the hoon.json object.

Additionally, this class provides get, set and remove methods for operating multiple keys.

Constructor

hoon.WebStorage

(
  • webstorage
)

Defined in src/hoon.js:436

Parameters:

  • webstorage LocalStorage | SessionStorage

Methods

clear

()

Defined in src/hoon.js:535

This method is equivalent to webstorage.clear() .

Example:

hoon.localStorage.setItem("name", "John");
hoon.localStorage.clear();

get

(
  • keys
)

Defined in src/hoon.js:598

Warning: The following methods must be used together.

  • WebStorage.set()
  • WebStorage.get()
  • WebStorage.setItem()
  • WebStorage.getItem()

For example, the following code doesn't work as expected.

localStorage.setItem("name", "John");
var name = hoon.localStorage.getItem("name", "John");

Otherwise, the following code works as expected.

hoon.localStorage.setItem("name", "John");
var name = hoon.localStorage.getItem("name", "John");

Parameters:

  • keys Null | Array of String | String

Example:

hoon.localStorage.set({ name: "John", id: -1 });
// equivalent to hoon.localStorage.getItem("name");
hoon.localStorage.get("name"); // "John"
hoon.localStorage.get(["name", "id"]); // { name: "John", id: -1 }
hoon.localStorage.get(); // { name: "John", id: -1 }
// equivalent to hoon.localStorage.get();
hoon.localStorage.get(null); // { name: "John", id: -1 }

getItem

(
  • key
)

Defined in src/hoon.js:452

return the current value associated with the given key. If the given key does not exist in the list associated with the object then this method must return null.

Warning: The following methods must be used together.

  • WebStorage.set()
  • WebStorage.get()
  • WebStorage.setItem()
  • WebStorage.getItem()

For example, the following code doesn't work as expected.

localStorage.setItem("name", "John");
var name = hoon.localStorage.getItem("name", "John");

Otherwise, the following code works as expected.

hoon.localStorage.setItem("name", "John");
var name = hoon.localStorage.getItem("name", "John");

Parameters:

  • key String

Returns:

the current value associated with the given key.

Example:

hoon.localStorage.setItem("obj", {
    name: "John",
    number: 1,
});
var obj = hoon.localStorage.getItem("obj");
console.log();

key

(
  • n
)

Defined in src/hoon.js:546

This method is equivalent to webstorage.key(n) .

Parameters:

  • n Integer

Example:

hoon.clear();
hoon.localStorage.setItem("name", "John");
console.log(hoon.localStorage.key(0)); // "name"

remove

(
  • keys
)

Defined in src/hoon.js:648

Parameters:

  • keys Null | Array of String | String

Example:

 hoon.localStorage.remove("name"); // equivalent to localStorage.removeItem("name");
 hoon.localStorage.remove(["name", "id"]);
 hoon.localStorage.remove(); // equivalent to localStorage.clear();
 hoon.localStorage.remove(null); // equivalent to localStorage.clear();

removeItem

(
  • key
)

Defined in src/hoon.js:523

This method is equivalent to webstorage.removeItem(key) .

Parameters:

  • key String

Example:

hoon.localStorage.setItem("name", "John");
hoon.localStorage.removeItem("name");

set

()

Defined in src/hoon.js:559

Warning: The following methods must be used together.

  • WebStorage.set()
  • WebStorage.get()
  • WebStorage.setItem()
  • WebStorage.getItem()

For example, the following code doesn't work as expected.

localStorage.setItem("name", "John");
var name = hoon.localStorage.getItem("name", "John");

Otherwise, the following code works as expected.

hoon.localStorage.setItem("name", "John");
var name = hoon.localStorage.getItem("name", "John");

Example:

// equivalent to hoon.localStorage.setItem("name", "John");
hoon.localStorage.set("name", "John");

hoon.localStorage.set({
    name: "John",
    number: 1,
});

setItem

(
  • key
  • val
)

Defined in src/hoon.js:489

Warning: The following methods must be used together.

  • WebStorage.set()
  • WebStorage.get()
  • WebStorage.setItem()
  • WebStorage.getItem()

For example, the following code doesn't work as expected.

localStorage.setItem("name", "John");
var name = hoon.localStorage.getItem("name", "John");

Otherwise, the following code works as expected.

hoon.localStorage.setItem("name", "John");
var name = hoon.localStorage.getItem("name", "John");

Parameters:

  • key String
  • val Object

Returns:

undefined

Example:

hoon.localStorage.setItem("obj", {
    name: "John",
    number: 1,
});
var obj = hoon.localStorage.getItem("obj");
console.log();