npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

laravel-config-to-js

v0.0.4

Published

Automatically export laravel config variables to javascript using annotation

Downloads

10

Readme

Laravel Config To Javascript

Introduction

This package provides a clean, easy maintainable and fast way to re-use your Laravel config files on the client side (javascript). It's built to be used in a Laravel project with Gulp, but you're free to find other uses for it.

Important

This a very early version of the project and might have errors. If you report them here, I'll be happy to fix them.

Documentation

Install

Install the package via npm:

npm install laravel-config-to-js

Usage

var buildJsConfig = require('laravel-config-to-js');

buildJSConfig(options);

Options

The following options and its default values are:

{
    configDirPath: './config',
    destFilePath: './resources/assets/js/variables.js',
    namespace: 'Config',
}

How it works

The package will go through all the configuration files in your Laravel project seeking comment that contains the annotation @jsVariable. If found, the contents of the following option will be transformed to javascript. Every option found in the same file will be grouped down in a object with the name of that file and each group in a namespace.

Here's an example:

Laravel config folder:

project
│   ...
└───config
    │   app.php
    │   custom.php

app.php contents:

return [
    /*
    |--------------------------------------------------------------------------
    | Application URL
    |--------------------------------------------------------------------------
    |
    | This URL is used by the console to properly generate URLs when using
    | the Artisan command line tool. You should set this to the root of
    | your application so that it is used when running Artisan tasks.
    |
    | @jsVariable
    */

    'url' => 'http://laravel.com',

    /*
    |--------------------------------------------------------------------------
    | Application Timezone
    |--------------------------------------------------------------------------
    |
    | Here you may specify the default timezone for your application, which
    | will be used by the PHP date and date-time functions. We have gone
    | ahead and set this to a sensible default for you out of the box.
    |
    */

    'timezone' => 'Europe/London',

    /*
    |--------------------------------------------------------------------------
    | Application Locale Configuration
    |--------------------------------------------------------------------------
    |
    | The application locale determines the default locale that will be used
    | by the translation service provider. You are free to set this value
    | to any of the locales which will be supported by the application.
    |
    */

    // @jsVariable
    'locale' => 'en',
];

custom.php contents:

return [
    'my_important_things' => [
        'right_here' => [
            /**
             * @jsVariable
             */
            'this_key' => 'I need this on client side',
            'other_key' => 'This is private, shhhh',
        ],
    ],
];

Output:

var Config = {
    "app": {
        "url": "http://www.laravel.com",
        "locale": "en"
    },
    "event": {
        "my_important_things": {
            "right_here": {
                "this_key": "I need this on client side"
            }
        }
    }
}

Not supported

There are some options that can't be supported, for obvious reasons. If you try to get one of these options you will get a "not supported" as value. This is the list:

  • Any function, example: env('APP_DEBUG', false),
  • Scope operators, example: Illuminate\View\ViewServiceProvider::class,

License

Laravel Config To Javascript is open-sourced software licensed under the MIT license