New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

js-config-loader

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-config-loader

Loads json data from script of type json.

latest
Source
npmnpm
Version
2.0.4
Version published
Maintainers
1
Created
Source

config-loader

General

The config loader provides a easy and simple way to get configs from HTML (typically from the backend server) into your client application without using global variables.

Install

yarn add js-config-loader --save
npm install js-config-loader --save
bower install config-loader --save

Usage

The ConfigLoader requires 2 arguments.

The first one is the element id, which contains the configuration to load. This element must contains valid JSON. Typically is this element a script tag.

The second argument is an object with options. Currently the only option is "throwError". If "throwError" is TRUE, an error will be thrown, if the config can not be found or parsed. If it is FALSE, an empty object will be returned, if an error occurs. The default value is TRUE.

The property "config" of the instance returns the config from given element.

Example

<html>
    <head>
        <script src="loader.js"></script>
        <script id="application" type="application/json">
            {
                "baseUrl": "/",
                "environment": "prod",
                "locale": {
                    "area": "de_DE",
                    "available": [
                        "de_DE",
                        "nl_NL",
                        "fr_FR",
                        "de_AT"
                    ],
                    "current": "de_DE",
                    "default": "de_DE"
                },
                "logger": {
                    "level": 400
                }
            }
        </script>
        <script>
            let configLoader = new ConfigLoader('#application');
            console.log(configLoader.config);
        </script>
    </head>
    <body>
    </body>
</html>

This will dump then JSON as JS Object to the console from the element #application.

FAQs

Package last updated on 20 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts