https://github.com/mattchewone/feathers-slugify
https://github.com/mattchewone/feathers-slugify
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/mattchewone/feathers-slugify
- Owner: Mattchewone
- License: mit
- Created: 2017-10-04T11:18:56.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-04-19T06:16:15.000Z (about 2 years ago)
- Last Synced: 2025-03-29T05:41:37.022Z (about 2 months ago)
- Language: JavaScript
- Size: 87.9 KB
- Stars: 3
- Watchers: 1
- Forks: 3
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/contributing.md
- License: LICENSE
Awesome Lists containing this project
README
# feathers-slugify
[](https://www.npmjs.com/package/feathers-slugify)
> Feathers hook to slugify properties
**Only tested with FeathersJS V3**
## Installation
```
npm install feathers-slugify --save
```## Single Rule w/single property
```js
const slugify = require('feathers-slugify')module.exports = {
before: {
all: [],
find: [],
get: [],
create: [
slugify({ slug: 'name' })
]
}
}// With data for create
const data = {
name: 'Dave Smith'
}
// Will become
const data = {
name: 'Dave Smith',
slug: 'dave-smith'
}
```## Single Rule w/multiple properties
```js
const slugify = require('feathers-slugify')module.exports = {
before: {
all: [],
find: [],
get: [],
create: [
slugify({ slug: ['meta.firstname', 'meta.surname'] })
]
}
}// With data for create
const data = {
meta: {
firstname: 'Dave',
surname: 'Smith'
}
}
// Will become
const data = {
meta: {
firstname: 'Dave',
surname: 'Smith'
},
slug: 'dave-smith'
}
```## Multiple Rules
```js
const slugify = require('feathers-slugify')module.exports = {
before: {
all: [],
find: [],
get: [],
create: [
slugify([
{
source: ['name.first', 'name.last'],
dest: 'fullname',
overwrite: true // defaults to false
},
{
source: 'title',
dest: 'titleSlug'
}
])
]
}
}// With data for create
const data = {
name: {
first: 'John',
last: 'Smith'
},
title: 'My Awesome Title'
}
// Will become
const data = {
name: {
first: 'John',
last: 'Smith'
},
fullname: 'john-smith',
title: 'My Awesome Title',
titleSlug: 'my-awesome-title'
}
```## Notes
This package uses the [url-slug](https://www.npmjs.com/package/url-slug) package to **_slugify_**.
```
RFC 3986 compliant slug generator with support for multiple languages. It creates safe slugs for use in urls—and can revert them.
```## License
Copyright (c) 2017
Licensed under the [MIT license](LICENSE).