Skip to content

Commit

Permalink
add description & usecases
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Nov 7, 2022
1 parent 8dd819d commit 6781691
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/scriptlets/trusted-set-local-storage-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
* @scriptlet trusted-set-local-storage-item
*
* @description
* Adds specified key and its value to localStorage object, or updates the value of the key if it already exists.
* Adds item with arbitrary key and value to localStorage object, or updates the value of the key if it already exists.
*
* **Syntax**
* ```
Expand All @@ -17,23 +17,34 @@ import {
*
* - `key` — required, key name to be set.
* - `value` - required, key value; possible values:
* - positive decimal integer `<= 32767`
* - one of the predefined constants:
* - `undefined`
* - `false`
* - `true`
* - `null`
* - `emptyObj` - empty object
* - `emptyArr` - empty array
* - `''` - empty string
* - `yes`
* - `no`
* - arbitrary value
* - `$now$` keyword for setting current time in ms, corresponds to `Date.now()` and `(new Date).getTime()` calls
* - `$thisDate$` keyword for setting string representation of the current date and time, corresponds to `Date()` and `(new Date).toString()` calls
*
* **Examples**
* 1. Set local storage item
* ```
* example.org#%#//scriptlet('trusted-set-local-storage-item', 'player.live.current.mute', 'false')
*
* example.org#%#//scriptlet('trusted-set-local-storage-item', 'exit-intent-marketing', '1')
* example.org#%#//scriptlet('trusted-set-local-storage-item', 'COOKIE_CONSENTS', '{"preferences":3,"marketing":false'})
*
* example.org#%#//scriptlet('trusted-set-local-storage-item', 'providers', '[16364,88364]')
*
* example.org#%#//scriptlet('trusted-set-local-storage-item', 'providers', '{"providers":[16364,88364],"consent":"all"}')
* ```
*
* 2. Set item with a special value
* ```
* example.org#%#//scriptlet('trusted-set-local-storage-item', 'player.live.current.play', '$now$')
*
* example.org#%#//scriptlet('trusted-set-local-storage-item', 'WPPwlbcapp9yj24', '$thisDate$')
* ```
*
* 3. Set item without key or value
* ```
* example.org#%#//scriptlet('trusted-set-local-storage-item', '', '2644')
*
* example.org#%#//scriptlet('trusted-set-local-storage-item', 'ppu_main_none', '')
* ```
*/
/* eslint-enable max-len */
Expand Down

0 comments on commit 6781691

Please sign in to comment.