New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

infrontjs

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

infrontjs - npm Package Compare versions

Comparing version

to
0.9.5

CODE-OF-CONDUCT.md

26

jsdoc.json

@@ -17,3 +17,27 @@ {

"theme_opts": {
"default_theme": "light"
"default_theme": "light",
"title" : "InfrontJS API documentation",
"menu": [
{
"title": "WWW",
"link": "https://www.infrontjs.com",
"target": "_blank"
},
{
"title": "EXAMPLES",
"link": "https://examples.infrontjs.com/",
"target": "_blank"
},
{
"title": "GUIDES",
"link": "https://guides.infrontjs.com/",
"target": "_blank"
},
{
"title": "GITHUB",
"link": "https://github.com/infrontjs/infrontjs",
"target": "_blank"
}
],
"footer" : "<small>Maintained by <a href=\"https://www.infrontjs\">InfontJS</a> - <a href=\"https://www.infrontjs.com/imprint.txt\">Imprint</a> - <a href=\"https://www.infrontjs.com/privacy.txt\">Privacy</a></small>"
}

@@ -20,0 +44,0 @@ },

10

package.json
{
"name": "infrontjs",
"version": "0.9.4",
"description": "A frontend framework",
"version": "0.9.5",
"description": "A plain javascript frontend framework",
"main": "src/IF.js",
"type" : "module",
"type": "module",
"scripts": {
"build": "rollup -c",
"generate-docs": "jsdoc --configure jsdoc.json --verbose",
"test": "mocha --recursive ./test/*.test.js"
"test": "mocha --recursive ./test/**/*.test.js"
},

@@ -26,3 +26,3 @@ "repository": {

},
"homepage": "https://github.com/infrontjs/infrontjs#readme",
"homepage": "https://www.infrontjs.com",
"devDependencies": {

@@ -29,0 +29,0 @@ "@babel/plugin-proposal-class-static-block": "^7.18.6",

@@ -0,1 +1,3 @@

<img src="https://www.infrontjs.com/assets/ext/ifjs-colored-bg-logo.png" style="max-width: 100%; margin-left: -4px; margin-bottom: 24px">
# InfrontJS - API documentation

@@ -10,1 +12,18 @@

## Build the docs
To generate the api docs, run the following commands. The generated api docs are in the folder `./apidocs`.
```bash
git clone https://github.com/infrontjs/infrontjs.git
npm init
npm run generate-docs
```
## Other Resources
As you explore the API docs, you may find these resources valuable:
* [InfrontJS Guides](https://guides.infrontjs.com)
* [InfrontJS Github repo](https://github.com/infrontjs/infrontjs)
* [InforntJS Examples](https://examples.infrontjs.com)

@@ -1,37 +0,126 @@

# InfrontJS
![InfrontJS logo](https://www.infrontjs.com/assets/ext/ifjs-colored-bg-logo.png)
The aim of this project is to provide a fast, unobstrusive and lightweight Vanilla Javascript Frontend framework.
# [InfrontJS](https://www.infrontjs.com)
## Stuff included
A simple, smart and pure vanilla javascript framework.
- Lodash _.get / _.set functionality wrapped into PathObject
- UrlPattern
- microtemplate
- observable-slim for watchables
- https://www.shadertoy.com/view/mt23WK forked from: https://www.shadertoy.com/view/wlSSD3
**For developers who...**
## ToDos
* ... like simple and smart solutions
* ... want to have full control of your code and no black boxes
* ... prefer to stay close to the platform and want to use its full power
* ... know vanilla javascript, css3 and html5
* ... want to avoid unnecessary abstractions
* ... do not want to learn additional domain specific languages and concepts (e.g. for templates etc)
* ... prefer a painless and easy-to-configure toolchain
**Version 1.0**
**For managers who...**
- [ ] Remove TemplateManager
- [ ] Rename ViewManager to View
- [ ] Add engine property and by default, set it to "ejs"
- [ ] JSDoc
- [ ] infront-cli
- [ ] Add tests
- [ ] UserGuide
- [ ] 404 State
- [X] Rename Api to Http (Client)
- [x] Move Http to Util
- [x] Rethink PropertyObject -> maybe just a simple set/get method that interacts with [this] instance properties
- [x] Move RouteParams/UrlPattern into Router/Controller
- [x] Work on non-hash-based actions
- [x] Add Front.js observables
- [x] Wrap Functions to static Helper class
- [x] Remove is_default state because it does not make sense, use route array instead
* ... are tired of wasting time on permanent framework version updates
* ... don't want to take the risk that their product is built upon a framework which might become outdated in the future
* ... want their developers spending most of their energy on the product and not about the underlying technology
* ... want to avoid unnecessary third party dependencies
* ... want to stay flexible
**Version 2.0**
### [Homepage](https://www.infrontjs.com) &middot; [ApiDocs](https://apidocs.infrontjs.com) &middot; [Examples](https://examples.infrontjs.com) &middot; [Twitter](https://twitter.com/infrontjs)
- [ ] Add verbose mode and/or logger
- [ ] Investigate on Typescript support
## Installation
### CDN
```html
<script src="https://unpkg.com/infrontjs/dist/IF.js"></script>
```
### npm
```bash
npm install infrontjs
```
## Example
```javascript
class GreetingState extends IF.State
{
async enter()
{
this.app.view.render( this.app.container, '<h1>Hello InfrontJS World</h1>' );
}
}
const myApp = new IF.App();
myApp.states.add( GreetingState );
myApp.run();
```
## Build & Test
Feel free to fork and work with the library. After cloning it, make sure to
```bash
npm install
```
in order to install all dependencies.
### Build library
Run the following command. The library will be generated and saved in the `./dist` folder.
```bash
npm run build
```
### Generate api docs
To generate the api docs, run the following command. The generated api docs are in the folder `./apidocs`.
```bash
npm run generate-docs
```
### Run unit tests
Unit tests can be executed by the following command
```bash
npm run test
```
## Resources
* Find general information and interesting news on our [website](https://www.infrontjs.com).
* Like reading api documentation. Have a look at the [api docs](https://apidocs.infrontjs.com).
* Do you prefer to learn by example? Check out the [official examples](https://examples.infrontjs.com).
* Get the latest development updates on [twitter](https://twitter.com/infrontjs).
## Roadmap to 1.0
We are currently working hard on the release of version 1.0
- [ ] Route Not Found handling
- [ ] Add minification version to rollup build
- [x] L18N add automatic locale resolving
- [x] L18N add NumberFormat logic
- [x] L18N add DateTimeFormat logic
- [x] Complete api docs
## Credits
This framework is build upon some great other open source projects...
* View class encapsulates [EJS](https://ejs.co/)
* DOM diffing enabled rendering is powered by [diffDOM](https://github.com/fiduswriter/diffDOM)
* Observables from the Helper class are supported by [ObservableSlim](https://github.com/elliotnb/observable-slim)
* UrlPattern used by the Router class relies on [UrlPattern](https://github.com/snd/url-pattern)
* PathObject implementation heavily relies on some [Lodash](https://github.com/lodash/lodash) methods
* The background fx of our Shameless plug DefaultScene is based on this [shader](https://www.shadertoy.com/view/wlSSD3])
## Contributing
By contributing or commenting on issues in this repository, whether you've read them or not, you're agreeing to the [Contributor Code of Conduct](CODE-OF-CONDUCT.md). Much like traffic laws, ignorance doesn't grant you immunity.
## License
This content is released under the (http://opensource.org/licenses/MIT) MIT License.

@@ -0,1 +1,3 @@

import { RouteParams } from "../IF.js";
/**

@@ -10,4 +12,2 @@ * State class. Parent state class. Extend this class for your state logic.

* {
* static ID = 'my-state';
*
* asnyc enter()

@@ -31,3 +31,3 @@ * {

*/
static ROUTE = null;
static ROUTE = "/";

@@ -37,3 +37,3 @@ /**

* @param {App} app - App instance
* @param {RouteParams} routeParams - Current route params
* @param {RouteParams=} routeParams - Current route params
*/

@@ -43,3 +43,3 @@ constructor( app, routeParams )

this.app = app;
this.routeParams = routeParams;
this.routeParams = null === routeParams ? new RouteParams() : routeParams;
}

@@ -79,3 +79,3 @@

*/
getRedirectTo()
getRedirectUrl()
{

@@ -100,4 +100,25 @@ return null;

}
getParams()
{
return this.routeParams.getParams();
}
getParam( key, defaultValue = null )
{
return this.routeParams.getParam( key, defaultValue );
}
getQueries()
{
return this.routeParams.getQueries();
}
getQuery( key, defaultValue = null )
{
return this.routeParams.getQuery( key, defaultValue );
}
}
export { State };

@@ -10,3 +10,3 @@ import { Router } from "./Router.js";

const VERSION = '0.9.4';
const VERSION = '0.9.5';

@@ -77,2 +77,7 @@ const DEFAULT_SETTINGS = {

if ( typeof window === 'undefined' )
{
throw new Error( 'InfrontJS works only in browser mode.' );
}
// If container property is a string, check if it is a querySelector

@@ -79,0 +84,0 @@ if ( this.container !== null && false === this.container instanceof HTMLElement )

@@ -0,1 +1,5 @@

/**
* L18n
* Simple internationalization logic
*/
class L18n

@@ -5,2 +9,34 @@ {

// List of valid 2-chared-county-codes
static COUNTRY_CODES = [
"AD", "AE", "AF", "AG", "AI", "AL", "AM", "AN", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ",
"BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ",
"CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ",
"DE", "DJ", "DK", "DM", "DO", "DZ",
"EC", "EE", "EG", "EH", "EN", "ER", "ES", "ET",
"FI", "FJ", "FK", "FM", "FO", "FR",
"GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY",
"HK", "HM", "HN", "HR", "HT", "HU",
"ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT",
"JE", "JM", "JO", "JP",
"KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ",
"LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY",
"MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ",
"NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ",
"OM",
"PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY",
"QA",
"RE", "RO", "RS", "RU", "RW",
"SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ",
"TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ",
"UA", "UG", "UM", "US", "UY", "UZ",
"VA", "VC", "VE", "VG", "VI", "VN", "VU",
"WF", "WS", "YE", "YT",
"ZA","ZM", "ZW" ];
/**
* Constructor
* @param {App} appInstance - InfrontJS App reference
*/
constructor( appInstance )

@@ -10,10 +46,69 @@ {

this.defaultLanguage = L18n.LANG_EN;
this.currentLanguage = this.defaultLanguage;
let cl = this.resolveBrowserLanguage();
if ( null === cl )
{
cl = this.defaultLanguage.toLowerCase();
}
this.dictionary = {};
this.setCurrentLanguage( cl );
}
/**
* Resolve preferred browser language
* @returns {*|null|string}
*/
resolveBrowserLanguage()
{
// See: https://stackoverflow.com/questions/1043339/javascript-for-detecting-browser-language-preference/46514247#46514247
var nav = typeof window !== "undefined" && window.navigator ? window.navigator : null,
browserLanguagePropertyKeys = ['language', 'browserLanguage', 'systemLanguage', 'userLanguage'],
i,
language,
len,
shortLanguage = null;
if ( !nav )
{
return null;
}
// support for HTML 5.1 "navigator.languages"
if (Array.isArray(nav.languages)) {
for (i = 0; i < nav.languages.length; i++) {
language = nav.languages[i];
len = language.length;
if (!shortLanguage && len) {
shortLanguage = language;
}
if (language && len>2) {
return language.slice( 0, 2).toLowerCase();
}
}
}
// support for other well known properties in browsers
for (i = 0; i < browserLanguagePropertyKeys.length; i++) {
language = nav[browserLanguagePropertyKeys[i]];
//skip this loop iteration if property is null/undefined. IE11 fix.
if (language == null) { continue; }
len = language.length;
if (!shortLanguage && len) {
shortLanguage = language;
}
if (language && len > 2) {
return language.slice( 0, 2).toLowerCase();
}
}
return shortLanguage.toLowerCase();
}
/**
* Export localization function to window scope.
* @param {string=} [fnName=_lc] - Name of global localization function
*/
expose( fnName = '_lc' )
{
if ( window )
if ( typeof window !== "undefined" )
{

@@ -24,2 +119,6 @@ window[ fnName ] = this.getLocale.bind( this );

/**
* Sets dictionary
* @param {object=} [dict={}] - Dictionary
*/
setDictionary( dict = {} )

@@ -30,2 +129,30 @@ {

/**
*
* Add given translation object to dictionary
*
* @param {string} langCode - Langugae code (2 chars)
* @param {object} translationObject - The translation object, simple key-value object
*/
addTranslation( langCode, translationObject )
{
if ( langCode && langCode.length > 2 )
{
langCode = langCode.slice( 0, 2);
}
if ( !langCode || false === this._isValidLangCode( langCode ) )
{
throw new Error( 'Invalid langCode: ' + langCode )
}
this.dictionary[ langCode ] = translationObject;
}
/**
* Gets current translation by given key
* @param {string} key - Translation key
* @param {array=} [params=undefined] - Params array
* @returns {string}
*/
getLocale( key, params )

@@ -64,4 +191,85 @@ {

}
/**
* Get formatted number
*
* @param {Date} num - Number to format
* @param {Object=} [opts=null] - NumberFormat options used if set. @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat|NumberFormat}
* @returns {string}
*/
getNumber( num = 0, opts = null )
{
if ( opts )
{
return Intl.NumberFormat( this.currentLanguage, opts ).format( num );
}
else
{
return this._nf.format( num );
}
}
/**
* Get formatted date time
*
* @param {Date} dt - Date object to format
* @param {Object=} [opts=null] - DateTimeFormat options used if set. @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat|DateTimeFormat}
* @returns {string}
*/
getDateTime( dt, opts = null )
{
if ( opts )
{
return Intl.DateTimeFormat( this.currentLanguage, opts ).format( dt );
}
else
{
return this._dtf.format( dt );
}
}
/**
* Set current language
* @param {string} langCode - 2 chared language code
* @throws {Error} - Invalid language code
*/
setCurrentLanguage( langCode )
{
if ( langCode && langCode.length > 2 )
{
langCode = langCode.slice( 0, 2);
}
if ( !langCode || false === this._isValidLangCode( langCode ) )
{
throw new Error( 'Invalid langCode: ' + langCode )
}
this.currentLanguage = langCode.toLowerCase();
this._nf = new Intl.NumberFormat(
this.currentLanguage,
{
minimumFractionDigits : 2,
maximumFractionDigits : 2
}
);
this._dtf = new Intl.DateTimeFormat( this.currentLanguage );
}
/**
* Get current selected language
* @returns {string} - Returns 2 chared language code
*/
getCurrentLanguage()
{
return this.currentLanguage;
}
_isValidLangCode( langCode )
{
return -1 < L18n.COUNTRY_CODES.indexOf( langCode.toUpperCase() );
}
}
export { L18n };

@@ -1,2 +0,2 @@

import { RouteParams } from "./RouteParams.js";
import { RouteParams } from "../base/RouteParams.js";
import { Helper } from "../util/Helper.js";

@@ -187,3 +187,3 @@ import { States } from "./States.js";

{
this.processUrl()
this.processUrl();
}

@@ -266,2 +266,3 @@ else if ( this.mode = 'hash' )

window.history.replaceState( null, null, url );
this.processUrl();
}

@@ -268,0 +269,0 @@ }

@@ -27,42 +27,42 @@ import { Helper } from "../util/Helper.js";

*
* @param {BaseState} stateClass - State class to be added.
* @param {...BaseState} stateClasses - State class to be added.
* @throws {Error} - Throws an error when adding state is not possible
* @returns {boolean} - Returns wheter or not adding was successful
*/
add( stateClass )
add( ...stateClasses )
{
// @todo Fix this, only check for function or class
if ( false === Helper.isClass( stateClass ) )
for( const stateClass of stateClasses )
{
throw new Error( 'States.addState expects a class/subclass of State.' );
}
if ( false === Helper.isClass( stateClass ) )
{
throw new Error( 'States.addState expects a class/subclass of State.' );
}
// Throw an error if ID is null or already taken
if ( false === Helper.isString( stateClass.ID ) )
{
stateClass.ID = Helper.createUid();
// @todo show warning ... throw new Error( 'Given stateClass does not have a valid static ID' );
}
// Throw an error if ID is null or already taken
if ( false === Helper.isString( stateClass.ID ) )
{
stateClass.ID = Helper.createUid();
// @todo show warning ... throw new Error( 'Given stateClass does not have a valid static ID' );
}
if ( true === this._states.hasOwnProperty( stateClass.ID ) )
{
// @todo Show warning ...
return false;
}
if ( true === this._states.hasOwnProperty( stateClass.ID ) )
{
// @todo Show warning ...
return false;
}
this._states[ stateClass.ID ] = stateClass;
this._states[ stateClass.ID ] = stateClass;
if ( Helper.isString( stateClass.ROUTE ) )
{
this.app.router.addRoute( stateClass.ROUTE, stateClass );
}
else if ( Helper.isArray( stateClass.ROUTE ) )
{
for ( let route of stateClass.ROUTE )
if ( Helper.isString( stateClass.ROUTE ) )
{
this.app.router.addRoute( route, stateClass );
this.app.router.addRoute( stateClass.ROUTE, stateClass );
}
else if ( Helper.isArray( stateClass.ROUTE ) )
{
for ( let route of stateClass.ROUTE )
{
this.app.router.addRoute( route, stateClass );
}
}
}
return true;
}

@@ -103,6 +103,6 @@

{
const redirectTo = newState.getRedirectTo();
if ( redirectTo )
const redirectUrl = newState.getRedirectUrl();
if ( redirectUrl )
{
this.app.router.redirect( redirectTo );
this.app.router.redirect( redirectUrl );
return false;

@@ -109,0 +109,0 @@ }

@@ -8,6 +8,9 @@ import { compile, render } from "./../_external/ejs/ejs.js";

* Provides management and rendering of ejs templates including DOM diffing.
* @namespace core
*/
class View
{
/**
* Constructor
* @param {App} appInstance - App reference
*/
constructor( appInstance )

@@ -31,2 +34,6 @@ {

/**
* Sets window title
* @param {string} title - Title to set
*/
setWindowTitle( title )

@@ -40,2 +47,8 @@ {

/**
* Compiles template with given options
* @param {string} template - EJS based template
* @param {object} opts - EJS template options. @see {@link https://ejs.co/#docs}
* @returns {*} - Compiled template function
*/
compile( template, opts )

@@ -47,12 +60,14 @@ {

/**
* Renders template with given data to html container.
*
* @param {HTMLElement|null} container - Container in which template should be rendered
* @param {HTMLElement|null} container - Container in which template should be rendered. If null, the generated HTML is returned
* @param {string} tmpl - EJS template string
* @param {object=} [data={}] - Template data.
* @param {boolean} [forceRepaint=false] - If false, DOM diffing is enabled.
* @param {object=} [tmplOptions=null] - EJS template options. @see {@link https://ejs.co/#docs}
* @returns {undefined|string} - If container is undefined|null, the rendered html is returned.
*/
render( container, tmpl, data = {}, forceRepaint = false )
render( container, tmpl, data = {}, forceRepaint = false, tmplOptions = null )
{
const html = render( tmpl, data );
const html = render( tmpl, data, tmplOptions );
if ( !container || false === ( container instanceof HTMLElement ) )

@@ -91,2 +106,10 @@ {

/**
* Load html templated from given url
*
* @param {string} templateUrl - URL to template to load
* @param {boolean=} [useCache=true] - If true, use cache to avoid unnecessary loading
* @throws {Error}
* @returns {string}
*/
async load( templateUrl, useCache = true )

@@ -93,0 +116,0 @@ {

export { State } from "./base/State.js";
export { RouteParams } from "./base/RouteParams.js";

@@ -3,0 +4,0 @@ export { App } from "./core/App.js";

import { get, set } from "./../_external/lodash/lodash-extract.js";
/**
* PathObject
* Convenient way to work with JSON datastructures.
*
* @example
* const po = new PathObject(
* {
* "a" : "Hello",
* "b" : {
* "c" : "World"
* }
* }
* );
*
* po.get( "b.c" );
* // Returns "World"
* po.set( "b.c", "InfrontJS" );
* po.get( "b.c" );
* // Return "InfrontJS"
* po.get( "b.d", "what?" );
* // Returns "what?"
*/
class PathObject
{
/**
* Constructor
* @param {object=} [properties={}] - Initial literal
*/
constructor( properties = {} )

@@ -6,0 +32,0 @@ {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display