literium-runner
Advanced tools
Comparing version 0.1.1 to 0.2.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var literium_1 = require("literium"); | ||
var urlRegExp = /^([^:]+:)?(\/\/)?(?:([^@:\/\?#]*)@)?(([^:\/\?#]+)(?:\:(\d+))?)?(([\/]?[^\?#]*)?(\?[^#]*)?)?(#.*)?$/; | ||
@@ -45,3 +46,3 @@ function parse(url) { | ||
set_path = function (path) { | ||
send({ $: 'path', path: path }); | ||
send(literium_1.keyed('path', path)); | ||
}; | ||
@@ -48,0 +49,0 @@ // send initial url |
@@ -0,1 +1,2 @@ | ||
import { keyed } from 'literium'; | ||
var urlRegExp = /^([^:]+:)?(\/\/)?(?:([^@:\/\?#]*)@)?(([^:\/\?#]+)(?:\:(\d+))?)?(([\/]?[^\?#]*)?(\?[^#]*)?)?(#.*)?$/; | ||
@@ -42,3 +43,3 @@ function parse(url) { | ||
set_path = function (path) { | ||
send({ $: 'path', path: path }); | ||
send(keyed('path', path)); | ||
}; | ||
@@ -45,0 +46,0 @@ // send initial url |
@@ -1,2 +0,2 @@ | ||
import { Fork } from 'literium'; | ||
import { Fork, Keyed } from 'literium'; | ||
export interface HasBase { | ||
@@ -8,7 +8,4 @@ base: string; | ||
} | ||
export interface SetPath { | ||
$: 'path'; | ||
path: string; | ||
} | ||
export declare function setPath<State extends HasPath>(state: State, {path}: SetPath): State; | ||
export declare type SetPath = Keyed<'path', string>; | ||
export declare function setPath<State extends HasPath>(state: State, event: SetPath): State; | ||
export interface Nav<AppEvent> { | ||
@@ -15,0 +12,0 @@ on(fork: Fork<AppEvent>): void; |
import * as tslib_1 from "tslib"; | ||
export function setPath(state, _a) { | ||
var path = _a.path; | ||
return tslib_1.__assign({}, state, { path: path }); | ||
export function setPath(state, event) { | ||
return event.$ == 'path' ? tslib_1.__assign({}, state, { path: event._ }) : state; | ||
} | ||
//# sourceMappingURL=location.js.map |
@@ -0,1 +1,2 @@ | ||
import { keyed } from 'literium'; | ||
export function getBase(_a) { | ||
@@ -9,3 +10,3 @@ var host = _a.headers.host; | ||
var _a = fork(), send = _a[0], done = _a[1]; | ||
send({ $: 'path', path: req.url || '' }); | ||
send(keyed('path', req.url || '')); | ||
done(); | ||
@@ -12,0 +13,0 @@ }, |
@@ -1,5 +0,11 @@ | ||
export interface Store<Type> { | ||
load(): Type | void; | ||
save(data: Type): void; | ||
export interface StoreData<Type> { | ||
$?: boolean; | ||
_?: Type; | ||
} | ||
export declare function createStore<Type>(name: string): Store<Type>; | ||
export interface StoreCell<Type> { | ||
$: string; | ||
_: Type; | ||
} | ||
export declare function initStore<Type>(name: string, 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; |
import { dummy } from 'literium'; | ||
var _a = check() ? [load_, save_] : [dummy, dummy], _load = _a[0], _save = _a[1]; | ||
export function initStore(name, def) { | ||
return { $: name, _: def }; | ||
} | ||
export function loadStore(store) { | ||
var cell = _load(store.$); | ||
return cell ? cell._ : store._; | ||
} | ||
export function saveStore(store, data, persist) { | ||
var cell = _load(store.$) || { _: store._ }; | ||
if (persist != undefined) | ||
cell.$ = persist; | ||
cell._ = data; | ||
_save(store.$, cell); | ||
} | ||
function load_(name) { | ||
var raw = localStorage.getItem(name); | ||
if (!raw) { | ||
return undefined; | ||
} | ||
var raw1 = sessionStorage.getItem(name); | ||
var raw2 = localStorage.getItem(name); | ||
var raw = raw1 || raw2; | ||
if (!raw) | ||
return; | ||
var persist = !raw1 && !!raw2; | ||
try { | ||
return JSON.parse(raw); | ||
return { $: persist, _: JSON.parse(raw) }; | ||
} | ||
catch (e) { | ||
return undefined; | ||
catch (_) { } | ||
} | ||
function save_(name, _a) { | ||
var persist = _a.$, data = _a._; | ||
sessionStorage.removeItem(name); | ||
localStorage.removeItem(name); | ||
if (persist != undefined && data != undefined) { | ||
var json = JSON.stringify(data); | ||
(persist ? localStorage : sessionStorage).setItem(name, json); | ||
} | ||
} | ||
function save_(name, data) { | ||
localStorage.setItem(name, JSON.stringify(data)); | ||
} | ||
function check() { | ||
try { | ||
return typeof localStorage != 'undefined'; | ||
return typeof localStorage != 'undefined' && typeof sessionStorage != 'undefined'; | ||
} | ||
catch (e) { | ||
catch (_) { | ||
return false; | ||
} | ||
} | ||
var _a = check() ? [load_, save_] : [dummy, dummy], load = _a[0], save = _a[1]; | ||
export function createStore(name) { | ||
return { | ||
load: function () { return load(name); }, | ||
save: function (data) { return save(name, data); } | ||
}; | ||
} | ||
//# sourceMappingURL=store.js.map |
@@ -1,2 +0,2 @@ | ||
import { Fork } from 'literium'; | ||
import { Fork, Keyed } from 'literium'; | ||
export interface HasBase { | ||
@@ -8,7 +8,4 @@ base: string; | ||
} | ||
export interface SetPath { | ||
$: 'path'; | ||
path: string; | ||
} | ||
export declare function setPath<State extends HasPath>(state: State, {path}: SetPath): State; | ||
export declare type SetPath = Keyed<'path', string>; | ||
export declare function setPath<State extends HasPath>(state: State, event: SetPath): State; | ||
export interface Nav<AppEvent> { | ||
@@ -15,0 +12,0 @@ on(fork: Fork<AppEvent>): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
function setPath(state, _a) { | ||
var path = _a.path; | ||
return tslib_1.__assign({}, state, { path: path }); | ||
function setPath(state, event) { | ||
return event.$ == 'path' ? tslib_1.__assign({}, state, { path: event._ }) : state; | ||
} | ||
exports.setPath = setPath; | ||
//# sourceMappingURL=location.js.map |
{ | ||
"name": "literium-runner", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Runner module for Literium web-framework.", | ||
@@ -37,3 +37,6 @@ "main": "index.js", | ||
"literium", | ||
"framework" | ||
"framework", | ||
"typescript", | ||
"es6", | ||
"es2015" | ||
], | ||
@@ -55,4 +58,4 @@ "author": "K. <kayo@illumium.org>", | ||
"peerDependencies": { | ||
"literium": "^0.1.1" | ||
"literium": "^0.2.0" | ||
} | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var literium_1 = require("literium"); | ||
function getBase(_a) { | ||
@@ -12,3 +13,3 @@ var host = _a.headers.host; | ||
var _a = fork(), send = _a[0], done = _a[1]; | ||
send({ $: 'path', path: req.url || '' }); | ||
send(literium_1.keyed('path', req.url || '')); | ||
done(); | ||
@@ -15,0 +16,0 @@ }, |
@@ -0,1 +1,2 @@ | ||
import { keyed } from 'literium'; | ||
import { Nav, SetPath } from '../location'; | ||
@@ -56,3 +57,3 @@ | ||
set_path = (path: string) => { | ||
send({ $: 'path', path } as Event); | ||
send(keyed('path' as 'path', path) as Event); | ||
}; | ||
@@ -59,0 +60,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { Fork } from 'literium'; | ||
import { Fork, Keyed } from 'literium'; | ||
@@ -11,9 +11,6 @@ export interface HasBase { | ||
export interface SetPath { | ||
$: 'path'; | ||
path: string; | ||
} | ||
export type SetPath = Keyed<'path', string>; | ||
export function setPath<State extends HasPath>(state: State, { path }: SetPath): State { | ||
return { ...(state as {}), path } as State; | ||
export function setPath<State extends HasPath>(state: State, event: SetPath): State { | ||
return event.$ == 'path' ? { ...(state as {}), path: event._ } as State : state; | ||
} | ||
@@ -20,0 +17,0 @@ |
@@ -0,1 +1,2 @@ | ||
import { keyed } from 'literium'; | ||
import { Nav, SetPath } from '../location'; | ||
@@ -12,3 +13,3 @@ import { IncomingMessage, ServerResponse } from 'http'; | ||
const [send, done] = fork(); | ||
send({ $: 'path', path: req.url || '' } as Event); | ||
send(keyed('path' as 'path', req.url || '') as Event); | ||
done(); | ||
@@ -15,0 +16,0 @@ }, |
import { dummy } from 'literium'; | ||
export interface Store<Type> { | ||
load(): Type | void; | ||
save(data: Type): void; | ||
export interface StoreData<Type> { | ||
$?: boolean; // data is persistent | ||
_?: Type; // actual data value | ||
} | ||
function load_<Type>(name: string): Type | void { | ||
let raw = localStorage.getItem(name); | ||
if (!raw) { | ||
return undefined; | ||
} | ||
export interface StoreCell<Type> { | ||
$: string; // data cell name | ||
_: Type; // default value | ||
} | ||
const [_load, _save]: [ | ||
<Type>(name: string) => StoreData<Type> | void, | ||
<Type>(name: string, data: StoreData<Type>) => void | ||
] = check() ? [load_, save_] : [dummy, dummy]; | ||
export function initStore<Type>(name: string, def: Type): StoreCell<Type> { | ||
return { $: name, _: def }; | ||
} | ||
export function loadStore<Type>(store: StoreCell<Type>): Type { | ||
const cell = _load<Type>(store.$); | ||
return cell ? cell._ as Type : store._; | ||
} | ||
export function saveStore<Type>(store: StoreCell<Type>, data?: Type, persist?: boolean) { | ||
const cell = _load<Type>(store.$) || { _: store._ }; | ||
if (persist != undefined) cell.$ = persist; | ||
cell._ = data; | ||
_save(store.$, cell); | ||
} | ||
function load_<Type>(name: string): StoreData<Type> | void { | ||
const raw1 = sessionStorage.getItem(name); | ||
const raw2 = localStorage.getItem(name); | ||
const raw = raw1 || raw2; | ||
if (!raw) return; | ||
const persist = !raw1 && !!raw2; | ||
try { | ||
return JSON.parse(raw) as Type; | ||
} catch (e) { | ||
return undefined; | ||
} | ||
return { $: persist, _: JSON.parse(raw) as Type }; | ||
} catch (_) { } | ||
} | ||
function save_<Type>(name: string, data: Type) { | ||
localStorage.setItem(name, JSON.stringify(data)); | ||
function save_<Type>(name: string, { $: 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); | ||
} | ||
} | ||
@@ -26,18 +56,6 @@ | ||
try { | ||
return typeof localStorage != 'undefined' | ||
} catch (e) { | ||
return typeof localStorage != 'undefined' && typeof sessionStorage != 'undefined' | ||
} catch (_) { | ||
return false; | ||
} | ||
} | ||
const [load, save]: [ | ||
<Type>(name: string) => Type | void, | ||
<Type>(name: string, data: Type) => void | ||
] = check() ? [load_, save_] : [dummy, dummy]; | ||
export function createStore<Type>(name: string): Store<Type> { | ||
return { | ||
load: () => load(name), | ||
save: data => save(name, data) | ||
}; | ||
} |
@@ -1,5 +0,11 @@ | ||
export interface Store<Type> { | ||
load(): Type | void; | ||
save(data: Type): void; | ||
export interface StoreData<Type> { | ||
$?: boolean; | ||
_?: Type; | ||
} | ||
export declare function createStore<Type>(name: string): Store<Type>; | ||
export interface StoreCell<Type> { | ||
$: string; | ||
_: Type; | ||
} | ||
export declare function initStore<Type>(name: string, 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; |
56
store.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var literium_1 = require("literium"); | ||
var _a = check() ? [load_, save_] : [literium_1.dummy, literium_1.dummy], _load = _a[0], _save = _a[1]; | ||
function initStore(name, def) { | ||
return { $: name, _: def }; | ||
} | ||
exports.initStore = initStore; | ||
function loadStore(store) { | ||
var cell = _load(store.$); | ||
return cell ? cell._ : store._; | ||
} | ||
exports.loadStore = loadStore; | ||
function saveStore(store, data, persist) { | ||
var cell = _load(store.$) || { _: store._ }; | ||
if (persist != undefined) | ||
cell.$ = persist; | ||
cell._ = data; | ||
_save(store.$, cell); | ||
} | ||
exports.saveStore = saveStore; | ||
function load_(name) { | ||
var raw = localStorage.getItem(name); | ||
if (!raw) { | ||
return undefined; | ||
} | ||
var raw1 = sessionStorage.getItem(name); | ||
var raw2 = localStorage.getItem(name); | ||
var raw = raw1 || raw2; | ||
if (!raw) | ||
return; | ||
var persist = !raw1 && !!raw2; | ||
try { | ||
return JSON.parse(raw); | ||
return { $: persist, _: JSON.parse(raw) }; | ||
} | ||
catch (e) { | ||
return undefined; | ||
catch (_) { } | ||
} | ||
function save_(name, _a) { | ||
var persist = _a.$, data = _a._; | ||
sessionStorage.removeItem(name); | ||
localStorage.removeItem(name); | ||
if (persist != undefined && data != undefined) { | ||
var json = JSON.stringify(data); | ||
(persist ? localStorage : sessionStorage).setItem(name, json); | ||
} | ||
} | ||
function save_(name, data) { | ||
localStorage.setItem(name, JSON.stringify(data)); | ||
} | ||
function check() { | ||
try { | ||
return typeof localStorage != 'undefined'; | ||
return typeof localStorage != 'undefined' && typeof sessionStorage != 'undefined'; | ||
} | ||
catch (e) { | ||
catch (_) { | ||
return false; | ||
} | ||
} | ||
var _a = check() ? [load_, save_] : [literium_1.dummy, literium_1.dummy], load = _a[0], save = _a[1]; | ||
function createStore(name) { | ||
return { | ||
load: function () { return load(name); }, | ||
save: function (data) { return save(name, data); } | ||
}; | ||
} | ||
exports.createStore = createStore; | ||
//# sourceMappingURL=store.js.map |
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
72220
110
1251
1
144
0