JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 105
  • Score
    100M100P100Q99228F
  • License MIT

Core SDK for Togglely - Framework agnostic

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@togglely/sdk-core) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    @togglely/sdk-core

    Core SDK for Togglely - Framework agnostic feature toggles.

    Installation

    npm install @togglely/sdk-core

    Usage

    import { TogglelyClient } from '@togglely/sdk-core';
    
    const client = new TogglelyClient({
      apiKey: 'your-api-key',
      environment: 'production',
      baseUrl: 'https://your-togglely-instance.com'
    });
    
    // Check if feature is enabled
    const isEnabled = await client.isEnabled('new-feature', false);
    
    // Get string value
    const message = await client.getString('welcome-message', 'Hello');
    
    // Get number value
    const limit = await client.getNumber('max-items', 10);
    
    // Get JSON value
    const config = await client.getJSON('app-config', {});
    
    // Listen to events
    client.on('ready', () => console.log('Toggles loaded!'));
    client.on('offline', () => console.log('Using offline toggles'));

    Offline Mode

    The SDK automatically falls back to environment variables when the service is unavailable.

    Environment Variables

    TOGGLELY_NEW_FEATURE=true
    TOGGLELY_MAX_ITEMS=100

    Browser Global

    <script>
      window.__TOGGLELY_TOGGLES = {
        'new-feature': true,
        'max-items': 100
      };
    </script>

    API

    TogglelyClient(config)

    Creates a new Togglely client.

    Config options:

    • apiKey (string, required): Your API key
    • environment (string, required): Environment name
    • baseUrl (string, required): Togglely instance URL
    • refreshInterval (number, default: 60000): Polling interval in ms
    • timeout (number, default: 5000): Request timeout in ms
    • offlineFallback (boolean, default: true): Enable offline mode
    • envPrefix (string, default: 'TOGGLELY_'): Environment variable prefix

    Methods

    • isEnabled(key, defaultValue): Check if a boolean toggle is enabled
    • getString(key, defaultValue): Get a string toggle value
    • getNumber(key, defaultValue): Get a number toggle value
    • getJSON(key, defaultValue): Get a JSON toggle value
    • getAllToggles(): Get all toggles
    • setContext(context): Set evaluation context (userId, email, etc.)
    • refresh(): Manually refresh toggles
    • destroy(): Cleanup and stop polling
    • on(event, handler): Listen to events ('ready', 'update', 'error', 'offline', 'online')