StellifyJS is a Laravel-inspired front-end only framework complete with a service container and various other helper utilities such as collections, form validation, a HTTP request wrapper and so on.
StellifyJS was created to provide the users of Stellify the convenience they experience working with Laravel on the server, client-side. The various classes and helper functions provided are automatically exposed via the Window object in the Stellify editor (found at stellisoft.com). This means they can be accessed directly without installation. Alternatively, you can pull down the package and bundle it up with various library extensions of your choosing before requesting it from a server or CDN.
View on npm here.
npm install stellifyjsimport Application from "stellifyjs";
// Fetch config from browser (or fallback to default)
const config = window.APP_CONFIG || {
environment: 'development',
debug: true,
providers: [
'AppServiceProvider',
'ValidationServiceProvider',
// Add more providers as needed
],
expose: {
validation: 'class' // Expose only these methods from ValidationService
}
};
// Create and boot the application
const stellifyJsApp = new Application(config);
await stellifyJsApp.boot();
// Expose globally for debugging
window.stellifyJsApp = stellifyJsApp;The service container is a powerful tool for managing class dependencies and performing dependency injection. You bind classes to the container as shown below:
const container = new Container();
container.bind("str", Str);Now, from anywhere in the framework, you can access string helpers dynamically:
const strHelper = container.resolve("str");
console.log(strHelper.slug("Hello World!")); // "hello-world"Helper methods are exposed on the window object under the namespace "Stellify".
Converts a word to its plural form.
Str.plural('child'); // Returns: 'children'
Str.plural('book'); // Returns: 'books'
Str.plural('box'); // Returns: 'boxes'
Str.plural('baby'); // Returns: 'babies'
Str.plural('person', 1); // Returns: 'person'Converts a word to its singular form.
Str.singular('children'); // Returns: 'child'
Str.singular('books'); // Returns: 'book'
Str.singular('boxes'); // Returns: 'box'
Str.singular('babies'); // Returns: 'baby'Converts a string to camelCase.
Str.camelCase('foo_bar'); // Returns: 'fooBar'
Str.camelCase('foo-bar'); // Returns: 'fooBar'
Str.camelCase('Foo Bar'); // Returns: 'fooBar'Converts a string to snake_case.
Str.snakeCase('fooBar'); // Returns: 'foo_bar'
Str.snakeCase('foo bar'); // Returns: 'foo_bar'
Str.snakeCase('Foo-Bar'); // Returns: 'foo_bar'Converts a string to kebab-case.
Str.kebabCase('fooBar'); // Returns: 'foo-bar'
Str.kebabCase('foo_bar'); // Returns: 'foo-bar'
Str.kebabCase('Foo Bar'); // Returns: 'foo-bar'Converts a string to StudlyCase (PascalCase).
Str.studlyCase('foo_bar'); // Returns: 'FooBar'
Str.studlyCase('foo-bar'); // Returns: 'FooBar'
Str.studlyCase('foo bar'); // Returns: 'FooBar'Generates a URL-friendly slug from a string.
Str.slug('Hello World!'); // Returns: 'hello-world'
Str.slug('Héllö Wörld'); // Returns: 'hello-world'
Str.slug('This & That'); // Returns: 'this-and-that'Generates a random string of specified length.
Str.random(); // Returns: random 16 character string
Str.random(8); // Returns: random 8 character stringChecks if a string starts with a given substring.
Str.startsWith('Hello World', 'Hello'); // Returns: true
Str.startsWith('Hello World', 'World'); // Returns: falseChecks if a string ends with a given substring.
Str.endsWith('Hello World', 'World'); // Returns: true
Str.endsWith('Hello World', 'Hello'); // Returns: falseTruncates a string and adds "..." if it exceeds a certain length.
Str.truncate('This is a long text', 7); // Returns: 'This is...'
Str.truncate('Short text', 20); // Returns: 'Short text'Gets a value from a nested object using dot notation.
const obj = { user: { profile: { name: 'John' } } };
Arr.get(obj, 'user.profile.name'); // Returns: 'John'
Arr.get(obj, 'user.profile.age', 25); // Returns: 25 (default value)Sets a value in a nested object using dot notation.
const obj = {};
Arr.set(obj, 'user.profile.name', 'John');
// Result: { user: { profile: { name: 'John' } } }Checks if a key exists in a nested object.
const obj = { user: { profile: { name: 'John' } } };
Arr.has(obj, 'user.profile.name'); // Returns: true
Arr.has(obj, 'user.profile.age'); // Returns: falseFlattens a multi-dimensional array into a single-level array.
const arr = [1, [2, 3], [4, [5, 6]]];
Arr.flatten(arr); // Returns: [1, 2, 3, 4, 5, 6]Extracts a specific key from an array of objects.
const users = [
{ id: 1, name: 'John' },
{ id: 2, name: 'Jane' }
];
Arr.pluck(users, 'name'); // Returns: ['John', 'Jane']Removes duplicate values from an array.
const arr = [1, 2, 2, 3, 3, 4];
Arr.unique(arr); // Returns: [1, 2, 3, 4]Randomly shuffles the elements of an array.
const arr = [1, 2, 3, 4, 5];
Arr.shuffle(arr); // Returns: [3, 1, 5, 2, 4] (random order)Gets the first element of an array.
const arr = [1, 2, 3];
Arr.first(arr); // Returns: 1Gets the last element of an array.
const arr = [1, 2, 3];
Arr.last(arr); // Returns: 3StellifyJS is open-sourced software licensed under the MIT license.