literium-runner
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -1,1 +0,1 @@ | ||
export declare function getLangs({navigator}: Window): ReadonlyArray<string>; | ||
export declare function getLangs({ navigator }: Window): ReadonlyArray<string>; |
import { Nav, SetPath } from '../location'; | ||
export declare function getBase({location: {protocol, host}}: Window): string; | ||
export declare function getBase({ location: { protocol, host } }: Window): string; | ||
export declare function initNav<Event extends SetPath>(win?: Window): Nav<Event>; |
@@ -1,1 +0,1 @@ | ||
export declare function getLangs({navigator}: Window): ReadonlyArray<string>; | ||
export declare function getLangs({ navigator }: Window): ReadonlyArray<string>; |
import { Nav, SetPath } from '../location'; | ||
export declare function getBase({location: {protocol, host}}: Window): string; | ||
export declare function getBase({ location: { protocol, host } }: Window): string; | ||
export declare function initNav<Event extends SetPath>(win?: Window): Nav<Event>; |
@@ -16,2 +16,2 @@ export interface Locale { | ||
} | ||
export declare function setLang<State extends HasLang>(state: State, {lang}: SetLang): State; | ||
export declare function setLang<State extends HasLang>(state: State, { lang }: SetLang): State; |
/// <reference types="node" /> | ||
import { Nav, SetPath } from '../location'; | ||
import { IncomingMessage, ServerResponse } from 'http'; | ||
export declare function getBase({headers: {host}}: IncomingMessage): string; | ||
export declare function getBase({ headers: { host } }: IncomingMessage): string; | ||
export declare function initNav<Event extends SetPath>(req: IncomingMessage, res: ServerResponse): Nav<Event>; |
@@ -0,1 +1,2 @@ | ||
import { JsonType } from 'literium-json'; | ||
export interface StoreData<Type> { | ||
@@ -8,5 +9,6 @@ $?: boolean; | ||
_: Type; | ||
j: JsonType<Type>; | ||
} | ||
export declare function initStore<Type>(name: string, def: Type): StoreCell<Type>; | ||
export declare function initStore<Type, JType extends Type>(name: string, json: JsonType<JType>, def: Type): StoreCell<Type>; | ||
export declare function loadStore<Type>(store: StoreCell<Type>): Type; | ||
export declare function saveStore<Type>(store: StoreCell<Type>, data?: Type, persist?: boolean): void; |
@@ -1,18 +0,19 @@ | ||
import { dummy } from 'literium'; | ||
import { dummy, is_ok, un_ok } from 'literium'; | ||
import { parse, build } from 'literium-json'; | ||
var _a = check() ? [load_, save_] : [dummy, dummy], _load = _a[0], _save = _a[1]; | ||
export function initStore(name, def) { | ||
return { $: name, _: def }; | ||
export function initStore(name, json, def) { | ||
return { $: name, _: def, j: json }; | ||
} | ||
export function loadStore(store) { | ||
var cell = _load(store.$); | ||
var cell = _load(store.$, store.j); | ||
return cell ? cell._ : store._; | ||
} | ||
export function saveStore(store, data, persist) { | ||
var cell = _load(store.$) || { _: store._ }; | ||
var cell = _load(store.$, store.j) || { _: store._ }; | ||
if (persist != undefined) | ||
cell.$ = persist; | ||
cell._ = data; | ||
_save(store.$, cell); | ||
_save(store.$, store.j, cell); | ||
} | ||
function load_(name) { | ||
function load_(name, json) { | ||
var raw1 = sessionStorage.getItem(name); | ||
@@ -24,8 +25,6 @@ var raw2 = localStorage.getItem(name); | ||
var persist = !raw1 && !!raw2; | ||
try { | ||
return { $: persist, _: JSON.parse(raw) }; | ||
} | ||
catch (_) { } | ||
var res = parse(json, raw); | ||
return is_ok(res) ? { $: persist, _: un_ok(res) } : undefined; | ||
} | ||
function save_(name, _a) { | ||
function save_(name, json, _a) { | ||
var persist = _a.$, data = _a._; | ||
@@ -35,4 +34,5 @@ sessionStorage.removeItem(name); | ||
if (persist != undefined && data != undefined) { | ||
var json = JSON.stringify(data); | ||
(persist ? localStorage : sessionStorage).setItem(name, json); | ||
var res = build(json, data); | ||
if (is_ok(res)) | ||
(persist ? localStorage : sessionStorage).setItem(name, un_ok(res)); | ||
} | ||
@@ -39,0 +39,0 @@ } |
@@ -16,2 +16,2 @@ export interface Locale { | ||
} | ||
export declare function setLang<State extends HasLang>(state: State, {lang}: SetLang): State; | ||
export declare function setLang<State extends HasLang>(state: State, { lang }: SetLang): State; |
{ | ||
"name": "literium-runner", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Runner module for Literium web-framework.", | ||
@@ -54,7 +54,8 @@ "main": "index.js", | ||
"tsify": "^4.0.0", | ||
"typescript": "^2.8.3" | ||
"typescript": "^2.9.1" | ||
}, | ||
"peerDependencies": { | ||
"literium": "^0.2.0" | ||
"literium": "^0.2.0", | ||
"literium-json": "^0.2.0" | ||
} | ||
} |
/// <reference types="node" /> | ||
import { Nav, SetPath } from '../location'; | ||
import { IncomingMessage, ServerResponse } from 'http'; | ||
export declare function getBase({headers: {host}}: IncomingMessage): string; | ||
export declare function getBase({ headers: { host } }: IncomingMessage): string; | ||
export declare function initNav<Event extends SetPath>(req: IncomingMessage, res: ServerResponse): Nav<Event>; |
@@ -1,2 +0,3 @@ | ||
import { dummy } from 'literium'; | ||
import { dummy, is_ok, un_ok } from 'literium'; | ||
import { JsonType, parse, build } from 'literium-json'; | ||
@@ -11,15 +12,16 @@ export interface StoreData<Type> { | ||
_: Type; // default value | ||
j: JsonType<Type>; // validator | ||
} | ||
const [_load, _save]: [ | ||
<Type>(name: string) => StoreData<Type> | void, | ||
<Type>(name: string, data: StoreData<Type>) => void | ||
<Type>(name: string, json: JsonType<Type>) => StoreData<Type> | void, | ||
<Type>(name: string, json: JsonType<Type>, data: StoreData<Type>) => void | ||
] = check() ? [load_, save_] : [dummy, dummy]; | ||
export function initStore<Type>(name: string, def: Type): StoreCell<Type> { | ||
return { $: name, _: def }; | ||
export function initStore<Type, JType extends Type>(name: string, json: JsonType<JType>, def: Type): StoreCell<Type> { | ||
return { $: name, _: def, j: json }; | ||
} | ||
export function loadStore<Type>(store: StoreCell<Type>): Type { | ||
const cell = _load<Type>(store.$); | ||
const cell = _load(store.$, store.j); | ||
return cell ? cell._ as Type : store._; | ||
@@ -29,9 +31,9 @@ } | ||
export function saveStore<Type>(store: StoreCell<Type>, data?: Type, persist?: boolean) { | ||
const cell = _load<Type>(store.$) || { _: store._ }; | ||
const cell = _load(store.$, store.j) || { _: store._ }; | ||
if (persist != undefined) cell.$ = persist; | ||
cell._ = data; | ||
_save(store.$, cell); | ||
_save(store.$, store.j, cell); | ||
} | ||
function load_<Type>(name: string): StoreData<Type> | void { | ||
function load_<Type>(name: string, json: JsonType<Type>): StoreData<Type> | void { | ||
const raw1 = sessionStorage.getItem(name); | ||
@@ -42,13 +44,12 @@ const raw2 = localStorage.getItem(name); | ||
const persist = !raw1 && !!raw2; | ||
try { | ||
return { $: persist, _: JSON.parse(raw) as Type }; | ||
} catch (_) { } | ||
const res = parse(json, raw); | ||
return is_ok(res) ? { $: persist, _: un_ok(res) } : undefined; | ||
} | ||
function save_<Type>(name: string, { $: persist, _: data }: StoreData<Type>) { | ||
function save_<Type>(name: string, json: JsonType<Type>, { $: persist, _: data }: StoreData<Type>) { | ||
sessionStorage.removeItem(name); | ||
localStorage.removeItem(name); | ||
if (persist != undefined && data != undefined) { | ||
const json = JSON.stringify(data); | ||
(persist ? localStorage : sessionStorage).setItem(name, json); | ||
const res = build(json, data); | ||
if (is_ok(res)) (persist ? localStorage : sessionStorage).setItem(name, un_ok(res)); | ||
} | ||
@@ -55,0 +56,0 @@ } |
@@ -0,1 +1,2 @@ | ||
import { JsonType } from 'literium-json'; | ||
export interface StoreData<Type> { | ||
@@ -8,5 +9,6 @@ $?: boolean; | ||
_: Type; | ||
j: JsonType<Type>; | ||
} | ||
export declare function initStore<Type>(name: string, def: Type): StoreCell<Type>; | ||
export declare function initStore<Type, JType extends Type>(name: string, json: JsonType<JType>, def: Type): StoreCell<Type>; | ||
export declare function loadStore<Type>(store: StoreCell<Type>): Type; | ||
export declare function saveStore<Type>(store: StoreCell<Type>, data?: Type, persist?: boolean): void; |
26
store.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var literium_1 = require("literium"); | ||
var literium_json_1 = require("literium-json"); | ||
var _a = check() ? [load_, save_] : [literium_1.dummy, literium_1.dummy], _load = _a[0], _save = _a[1]; | ||
function initStore(name, def) { | ||
return { $: name, _: def }; | ||
function initStore(name, json, def) { | ||
return { $: name, _: def, j: json }; | ||
} | ||
exports.initStore = initStore; | ||
function loadStore(store) { | ||
var cell = _load(store.$); | ||
var cell = _load(store.$, store.j); | ||
return cell ? cell._ : store._; | ||
@@ -15,10 +16,10 @@ } | ||
function saveStore(store, data, persist) { | ||
var cell = _load(store.$) || { _: store._ }; | ||
var cell = _load(store.$, store.j) || { _: store._ }; | ||
if (persist != undefined) | ||
cell.$ = persist; | ||
cell._ = data; | ||
_save(store.$, cell); | ||
_save(store.$, store.j, cell); | ||
} | ||
exports.saveStore = saveStore; | ||
function load_(name) { | ||
function load_(name, json) { | ||
var raw1 = sessionStorage.getItem(name); | ||
@@ -30,8 +31,6 @@ var raw2 = localStorage.getItem(name); | ||
var persist = !raw1 && !!raw2; | ||
try { | ||
return { $: persist, _: JSON.parse(raw) }; | ||
} | ||
catch (_) { } | ||
var res = literium_json_1.parse(json, raw); | ||
return literium_1.is_ok(res) ? { $: persist, _: literium_1.un_ok(res) } : undefined; | ||
} | ||
function save_(name, _a) { | ||
function save_(name, json, _a) { | ||
var persist = _a.$, data = _a._; | ||
@@ -41,4 +40,5 @@ sessionStorage.removeItem(name); | ||
if (persist != undefined && data != undefined) { | ||
var json = JSON.stringify(data); | ||
(persist ? localStorage : sessionStorage).setItem(name, json); | ||
var res = literium_json_1.build(json, data); | ||
if (literium_1.is_ok(res)) | ||
(persist ? localStorage : sessionStorage).setItem(name, literium_1.un_ok(res)); | ||
} | ||
@@ -45,0 +45,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73718
1256
2