2.1.0 • Published 4 years ago

slugx v2.1.0

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

slugx 🐌

A lightweight Slug generator/validator.

How to use

npm install slugx --save-dev or yarn add -D slugx.

Generate Slug

const slugx = require('slugx');
const newSlug = slugx.create('Hello world');
// slugx = 'hello-world'

Remove accents

Removes the accents from a string, converting them to their corresponding non-accented ASCII characters.

const slugx = require('slugx');
const newSlug = slugx.removeAccents('àéîõü');
// slugx = 'aeiou'

console.log(slugx.removeAccents('ÀÁÂÃÄÅ')); // AAAAAA

Validate Slug

const slugx = require('slugx');
const isValid = slugx.validate('hello-world');
// isValid = true

Options

For Create Slug

separator (optional): Change separator between words:

const slugx = require('slugx');
const newSlug = slugx.create('Hello world, Slugx', { separator: '.' });
// slugx = 'hello.world.slugx'

lowercase (optional): By default, lowercase is enable. This means that will uppercase letters will be changed to lowercase.

const slugx = require('slugx');
const newSlug = slugx.create('Hello world, SlugX', { lowercase: 'false' });
// slugx = 'Hello-world-SlugX'

strict (optional): The strict only accepts letters and numbers in the generated slug

const slugx = require('slugx');
const newSlug = slugx.create('Hello world, SlugX $1', { strict: 'true' });
// slugx = 'hello-world-Slugx-1'

For Validate Slug

min (optional): The minimum acceptable characters for validating slug

const slugx = require('slugx');

const isValidCase1 = slugx.validate('Hello world, Slugx', { min: 3 });
// isValidCase1 = true

const isValidCase2 = slugx.validate('Hi', { min: 3 });
// isValidCase2 = false

max (optional): The maximum acceptable characters for validating slug

const slugx = require('slugx');

const isValidCase1 = slugx.validate('Hello world, Slugx', { min: 32 });
// isValidCase1 = true

const isValidCase2 = slugx.validate('Hello world, Slugx', { min: 3 });
// isValidCase2 = false

allowOnlyNumbers (optional): By default, the allowOnlyNumbers is disabled, but you can change to false to invalidate slug with without letters.

const slugx = require('slugx');

const isValidCase1 = slugx.validate('12312312', { allowOnlyNumbers: true });
// isValidCase1 = true

const isValidCase2 = slugx.validate('12312312', { allowOnlyNumbers: false });
// isValidCase2 = false

slugConfig (optional): The slugConfig will set options of slugx.create to compare and validate

const slugx = require('slugx');

const isValidCase1 = slugx.validate('isValid-Hello-World', { slugOptions: { lowercase: false } });
// isValidCase1 = true

const isValidCase2 = slugx.validate('isValid-Hello-World', { slugOptions: { lowercase: true } });
// isValidCase2 = false
2.1.0

4 years ago

2.0.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.2

4 years ago

1.0.0

4 years ago

0.1.0

4 years ago

0.0.1

5 years ago