Socket
Socket
Sign inDemoInstall

@coffeekraken/s-sugar-config

Package Overview
Dependencies
632
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @coffeekraken/s-sugar-config

Powerful config management class that let you access the .config.(j|t)s files stored either at (mono)repo, package (.sugar/*) or user (.local/.sugar/*) level.


Version published
Weekly downloads
221
increased by67.42%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

@coffeekraken/s-sugar-config

MIT 2.0.0-alpha.20 - Git repository

size downloads license discord

Powerful config management class that let you access the .config.(j|t)s files stored either at (mono)repo, package (.sugar/) or user (.local/.sugar/) level.

Install

npm i @coffeekraken/s-sugar-config

SSugarConfig

This package expose a simple SSugarConfig class that let you access the configurations from the sugar packages, as well as your own configs defined in your .sugar folder.

Features

  • Work on node and in the browser
  • Based on the @coffeekraken/s-config class
  • And more...

Node usage

Using it in node is as simple as importing the class, loading the configs and access them:

import __SSugarConfig from '@coffeekraken/s-sugar-config';
// loading the configs (has to be done only once per process)
await __SSugarConfig.load();
// access them
const jsDir = __SSugarConfig.get('storage.package.src.jsDir');

Note that in a sugar CLI based process, the configuration loading is made for your in the CLI itself.

Browser usage

To use the sugar configs in your browser, you MUST either use the @coffeekraken/s-vite build, or inject the configs by yourself in your bundle see more.

The sugar config class admit that your configurations are stored under the window.env.SUGAR.config object.

import __SSugarConfig from '@coffeekraken/s-sugar-config';
const fontawesomeConfig = __SSugarConfig.get('icons.fontawesome');

Note that you can obviously choose which configurations are exposed in your frontend code. Here's a simple example:

myConfig.config.ts

export default function (env, config) {
  if (env.platform !== 'node') return;
  return {
    myConfig: 'hello',
  };
}

Inject config

If you do not use the @coffeekraken/s-vite build, you can inject them like so:

Using vite

Make use of the @coffeekraken/s-vite-sugar-plugin vite plugin.

Injecting the configuration by yourself

The configurations MUST be stored in the window.env.SUGAR.config object.

Here's a simple code that you can inject:

if (!window.env) window.env = {};
if (!window.env.SUGAR) window.env.SUGAR = {};
window.env.SUGAR.config = JSON.parse('your configs...');

API

Node

For more information about the Node API, please check out the API documentation

JS

For more information about the JS API, please check out the API documentation

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Here's all the ways you can contact us listed:

discord email

FAQs

Last updated on 15 Sep 2023

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc