slug_generator

Creator: coderz1093

Last updated:

0 purchases

slug_generator Image
slug_generator Images

Languages

Categories

Add to Cart

Description:

slug generator

Slug generator #
A pure dart implementation of a random slug generator.
Do you recall these funny random strings used all over the internet as alternatives to uuids for naming repositories/projects/objects, like: defiant-fluffy-eagle-of-reward or big-augmented-lori-of-cookies? With this package you can generate random strings like these yourself (we refer to them as slugs).

ℹ️ This package has been ported (with some simplifications/changes to implementation) from a Python package coolname. Please bear in mind, however, that I am NOT associated with, nor contributed to coolname.

Features #
Generate random slugs:
final rng = Random(42)

// To generate a slug
final slug = rng.nextSlug();
// slug == 'glistening-inventive-loon-from-atlantis'

// To generate a tokenized slug
final tokens = rng.nextSlugToken();
// tokens == <String>['loutish', 'imaginary', 'anteater', 'of', 'competence']
copied to clipboard
Getting started #
Add slug_generator to your pubspec.yaml:
dependencies:
pubspec: ^x.x.x # replace x.x.x with the latest version
copied to clipboard
Then, inside your project, whenever you want to generate a slug import math (which contains Random), as well as this package (which provides extensions for slug generation):
import 'dart:math' show Random;
import 'package:slug_generator/slug_generator.dart';
copied to clipboard
Usage #
Simply call nextSlug or nextSlugToken on an instance of Random to generate slugs or tokenized slugs respecitvely:
final rng = Random(42)

// To generate a slug
final slug = rng.nextSlug();
// slug == 'glistening-inventive-loon-from-atlantis';

// To generate a tokenized slug
final tokens = rng.nextSlugToken();
// tokens == <String>['loutish', 'imaginary', 'anteater', 'of', 'competence'];
// You can do whatever you want with the tokens, for instance:
final phrase = tokens.map((e)=>"${e[0].toUpperCase()}${e.substring(1)}").join(' ');
// phrase == 'Loutish Imaginary Anteater Of Competence';
copied to clipboard
Optionally, you may pass a specific collection as a parameter to either of nextSlug or nextSlugToken in order to sample only from that collection. For instance:
// Sample slugs of length 2
rng.nextSlug(Collections.two);

// Sample slugs of length 3
rng.nextSlug(Collections.three);

// Sample slugs of length 4
rng.nextSlug(Collections.four);

// Sample slugs from all available collections (default)
rng.nextSlug(Collections.all);
copied to clipboard
The table below shows orders for the number of unique slugs of given length that can be generated using this package:



Words
Combinations
Example




4
$10^{10}$
lumpy-agouti-of-unknown-enthusiasm


3
$10^8$
speedy-thistle-starling


2
$10^5$
whimsical-dodo



For advanced users #
You may want to define your own word collections and pass them to nextSlug. See file data_containers.dart to understand the data structures used for defining word collections and see files words_vault.dart and collections.dart for examples of word collections.
Additional information #
If you would like to contribute, consider expanding upon the package's word collection by adding new terms. Before doing so however, please make sure that

The word really fits to where you want to add it
The term is not already present (in case of two-word terms also make sure that it is not possible to construct the term through composition of already existing words)
The word is not offensive (we try to be neutral or positive, hence the heavy reliance of this package's dictionary on the mother nature's terminology)

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.