21 changed files with 542 additions and 18 deletions
@ -0,0 +1,2 @@ |
|||
YEAR: 2020 |
|||
COPYRIGHT HOLDER: Bob Rudis |
@ -0,0 +1,21 @@ |
|||
# MIT License |
|||
|
|||
Copyright (c) 2020 Bob Rudis |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all |
|||
copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|||
SOFTWARE. |
@ -1,4 +1,4 @@ |
|||
# Generated by roxygen2: do not edit by hand |
|||
|
|||
import(httr) |
|||
importFrom(jsonlite,fromJSON) |
|||
export(slugify) |
|||
import(V8) |
|||
|
@ -1,9 +1,11 @@ |
|||
#' ... |
|||
#' |
|||
#' Create slug strings for SEO |
|||
#' |
|||
#' Most blogging platforms turn title phrases into slugs |
|||
#' for better SEO. Tools are provided to turn phrases into slugs. |
|||
#' |
|||
#' @md |
|||
#' @name slugify |
|||
#' @keywords internal |
|||
#' @author Bob Rudis (bob@@rud.is) |
|||
#' @import httr |
|||
#' @importFrom jsonlite fromJSON |
|||
#' @import V8 |
|||
"_PACKAGE" |
|||
|
@ -0,0 +1,38 @@ |
|||
#' Slugif a string |
|||
#' |
|||
#' @param x string |
|||
#' @param replacement replace spaces with replacement character, defaults to `-` |
|||
#' @param remove remove characters that match this regex, defaults to `NULL` (no deleting) |
|||
#' @param lower convert to lower case, defaults to `TRUE` |
|||
#' @param strict strip special characters except replacement, defaults to `TRUE` |
|||
#' @export |
|||
#' @examples |
|||
#' slugify("R is great!") |
|||
slugify <- function(x, replacement = "-", remove = NULL, lower = TRUE, strict = TRUE) { |
|||
|
|||
if (!is.null(remove)) { |
|||
|
|||
.pkgenv$ctx$call( |
|||
"slugify", x[1], |
|||
list( |
|||
replacement = "-", |
|||
remove = remove[1], |
|||
lower = lower[1], |
|||
strict = strict[1] |
|||
) |
|||
) |
|||
|
|||
} else { |
|||
|
|||
.pkgenv$ctx$call( |
|||
"slugify", x[1], |
|||
list( |
|||
replacement = "-", |
|||
lower = lower[1], |
|||
strict = strict[1] |
|||
) |
|||
) |
|||
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,12 @@ |
|||
.pkgenv <- new.env(parent=emptyenv()) |
|||
|
|||
.onLoad <- function(...) { |
|||
|
|||
ctx <- V8::v8() |
|||
ctx$source(system.file("js/bundle.js", package="slugify")) |
|||
|
|||
assign("ctx", ctx, envir=.pkgenv) |
|||
|
|||
cache <- list() |
|||
|
|||
} |
@ -0,0 +1,71 @@ |
|||
|
|||
[](https://www.repostatus.org/#active) |
|||
[](https://keybase.io/hrbrmstr) |
|||
 |
|||
[](https://travis-ci.org/hrbrmstr/slugify) |
|||
 |
|||
 |
|||
|
|||
# slugify |
|||
|
|||
Create slug strings for SEO |
|||
|
|||
## Description |
|||
|
|||
Most blogging platforms turn title phrases into slugs for better SEO. |
|||
Tools are provided to turn phrases into slugs. |
|||
|
|||
## What’s Inside The Tin |
|||
|
|||
The following functions are implemented: |
|||
|
|||
## Installation |
|||
|
|||
``` r |
|||
remotes::install_git("https://git.rud.is/hrbrmstr/slugify.git") |
|||
# or |
|||
remotes::install_git("https://git.sr.ht/~hrbrmstr/slugify") |
|||
# or |
|||
remotes::install_gitlab("hrbrmstr/slugify") |
|||
# or |
|||
remotes::install_bitbucket("hrbrmstr/slugify") |
|||
# or |
|||
remotes::install_github("hrbrmstr/slugify") |
|||
``` |
|||
|
|||
NOTE: To use the ‘remotes’ install options you will need to have the |
|||
[{remotes} package](https://github.com/r-lib/remotes) installed. |
|||
|
|||
## Usage |
|||
|
|||
``` r |
|||
library(slugify) |
|||
|
|||
# current version |
|||
packageVersion("slugify") |
|||
## [1] '0.1.0' |
|||
``` |
|||
|
|||
``` r |
|||
slugify("R is great!") |
|||
## [1] "r-is-great" |
|||
``` |
|||
|
|||
## slugify Metrics |
|||
|
|||
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) | |
|||
| :--- | -------: | --: | --: | ---: | ----------: | ---: | -------: | --: | |
|||
| R | 4 | 0.8 | 33 | 0.79 | 13 | 0.45 | 20 | 0.4 | |
|||
| Rmd | 1 | 0.2 | 9 | 0.21 | 16 | 0.55 | 30 | 0.6 | |
|||
|
|||
## Code of Conduct |
|||
|
|||
Please note that this project is released with a Contributor Code of |
|||
Conduct. By participating in this project you agree to abide by its |
|||
terms. |
@ -0,0 +1,4 @@ |
|||
npm install slugify |
|||
echo "global.slugify = require('slugify');" > in.js |
|||
browserify in.js -o bundle.js |
|||
#webpack --mode="production" in.js -o bundle.js |
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@ |
|||
global.slugify = require('slugify'); |
@ -0,0 +1,21 @@ |
|||
The MIT License (MIT) |
|||
|
|||
Copyright (c) Simeon Velichkov <simeonvelichkov@gmail.com> |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all |
|||
copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|||
SOFTWARE. |
@ -0,0 +1,81 @@ |
|||
|
|||
# slugify |
|||
|
|||
[![npm-version]][npm] [![travis-ci]][travis] [![coveralls-status]][coveralls] |
|||
|
|||
```js |
|||
var slugify = require('slugify') |
|||
|
|||
slugify('some string') // some-string |
|||
|
|||
// if you prefer something other than '-' as separator |
|||
slugify('some string', '_') // some_string |
|||
``` |
|||
|
|||
- Vanilla ES5 JavaScript |
|||
- No dependencies |
|||
- Coerces foreign symbols to their English equivalent (check out the [charMap][charmap] for more details) |
|||
- Works in the browser (window.slugify) and AMD/CommonJS-flavored module loaders |
|||
|
|||
## Options |
|||
|
|||
```js |
|||
slugify('some string', { |
|||
replacement: '-', // replace spaces with replacement character, defaults to `-` |
|||
remove: undefined, // remove characters that match regex, defaults to `undefined` |
|||
lower: false, // convert to lower case, defaults to `false` |
|||
strict: false, // strip special characters except replacement, defaults to `false` |
|||
}) |
|||
``` |
|||
|
|||
For example, to remove `*+~.()'"!:@` from the result slug, you can use `slugify('..', {remove: /[*+~.()'"!:@]/g})`. |
|||
|
|||
## Extend |
|||
|
|||
Out of the box `slugify` comes with support for a handful of Unicode symbols. For example the `☢` (radioactive) symbol is not defined in the [`charMap`][charmap] and therefore it will be stripped by default: |
|||
|
|||
```js |
|||
slugify('unicode ♥ is ☢') // unicode-love-is |
|||
``` |
|||
|
|||
However you can extend the supported symbols, or override the existing ones with your own: |
|||
|
|||
```js |
|||
slugify.extend({'☢': 'radioactive'}) |
|||
slugify('unicode ♥ is ☢') // unicode-love-is-radioactive |
|||
``` |
|||
|
|||
Keep in mind that the `extend` method extends/overrides the default `charMap` for the entire process. In case you need a fresh instance of the slugify's `charMap` object you have to clean up the module cache first: |
|||
|
|||
```js |
|||
delete require.cache[require.resolve('slugify')] |
|||
var slugify = require('slugify') |
|||
``` |
|||
|
|||
## Contribute |
|||
|
|||
1. Add chars to `charmap.json` |
|||
2. Run tests `npm test` |
|||
3. The tests will build the charmap in `index.js` and will sort the `charmap.json` |
|||
4. Commit **all** modified files |
|||
|
|||
--- |
|||
|
|||
> This module was originally a vanilla javascript port of [node-slug][node-slug].<br> |
|||
> Note that the original [slug][slug] module has been ported to vanilla javascript too.<br> |
|||
> One major difference between the two modules is that `slugify` does not depend on the external [unicode][unicode] module. |
|||
|
|||
|
|||
[npm-version]: https://img.shields.io/npm/v/slugify.svg?style=flat-square (NPM Package Version) |
|||
[travis-ci]: https://img.shields.io/travis/simov/slugify/master.svg?style=flat-square (Build Status - Travis CI) |
|||
[coveralls-status]: https://img.shields.io/coveralls/simov/slugify.svg?style=flat-square (Test Coverage - Coveralls) |
|||
|
|||
[npm]: https://www.npmjs.com/package/slugify |
|||
[travis]: https://travis-ci.org/simov/slugify |
|||
[coveralls]: https://coveralls.io/r/simov/slugify?branch=master |
|||
|
|||
[node-slug]: https://github.com/dodo/node-slug |
|||
[slug]: https://www.npmjs.com/package/slug |
|||
[unicode]: https://www.npmjs.com/package/unicode |
|||
[index]: https://github.com/simov/slugify/blob/master/index.js |
|||
[charmap]: https://github.com/simov/slugify/blob/master/config/charmap.json |
@ -0,0 +1,73 @@ |
|||
{ |
|||
"_from": "slugify", |
|||
"_id": "slugify@1.4.2", |
|||
"_inBundle": false, |
|||
"_integrity": "sha512-7UfMG5rtkxfOI5jg/+f4DMQS3ikUqfWnfMvitrhwdTV4pibWXq9mN4RNLHSV3M1lR++x7z+AG7znsiozdBP+aA==", |
|||
"_location": "/slugify", |
|||
"_phantomChildren": {}, |
|||
"_requested": { |
|||
"type": "tag", |
|||
"registry": true, |
|||
"raw": "slugify", |
|||
"name": "slugify", |
|||
"escapedName": "slugify", |
|||
"rawSpec": "", |
|||
"saveSpec": null, |
|||
"fetchSpec": "latest" |
|||
}, |
|||
"_requiredBy": [ |
|||
"#USER", |
|||
"/" |
|||
], |
|||
"_resolved": "https://registry.npmjs.org/slugify/-/slugify-1.4.2.tgz", |
|||
"_shasum": "2c9b2b3321c43110a0058982eea7102b998d5068", |
|||
"_spec": "slugify", |
|||
"_where": "/Users/hrbrmstr/packages/slugify/inst/js", |
|||
"author": { |
|||
"name": "Simeon Velichkov", |
|||
"email": "simeonvelichkov@gmail.com", |
|||
"url": "https://simov.github.io" |
|||
}, |
|||
"bugs": { |
|||
"url": "https://github.com/simov/slugify/issues" |
|||
}, |
|||
"bundleDependencies": false, |
|||
"deprecated": false, |
|||
"description": "Slugifies a String", |
|||
"devDependencies": { |
|||
"coveralls": "^3.1.0", |
|||
"mocha": "^7.2.0", |
|||
"nyc": "^15.1.0" |
|||
}, |
|||
"engines": { |
|||
"node": ">=8.0.0" |
|||
}, |
|||
"files": [ |
|||
"LICENSE", |
|||
"README.md", |
|||
"slugify.d.ts", |
|||
"slugify.js" |
|||
], |
|||
"homepage": "https://github.com/simov/slugify", |
|||
"keywords": [ |
|||
"slugify", |
|||
"slug", |
|||
"url", |
|||
"urlify" |
|||
], |
|||
"license": "MIT", |
|||
"main": "./slugify.js", |
|||
"name": "slugify", |
|||
"repository": { |
|||
"type": "git", |
|||
"url": "git+https://github.com/simov/slugify.git" |
|||
}, |
|||
"scripts": { |
|||
"build": "node bin/build", |
|||
"test": "npm run build && npm run test:ci", |
|||
"test:ci": "npx mocha --recursive", |
|||
"test:cov": "npx nyc --reporter=lcov --reporter=text-summary mocha -- --recursive" |
|||
}, |
|||
"types": "slugify.d.ts", |
|||
"version": "1.4.2" |
|||
} |
@ -0,0 +1,22 @@ |
|||
declare module slugify { |
|||
type ExtendArgs = { |
|||
[key: string]: any; |
|||
} |
|||
|
|||
export function extend (args: ExtendArgs): void; |
|||
} |
|||
|
|||
declare function slugify( |
|||
string: string, |
|||
options?: |
|||
| { |
|||
replacement?: string; |
|||
remove?: RegExp; |
|||
lower?: boolean; |
|||
strict?: boolean; |
|||
} |
|||
| string, |
|||
|
|||
): string; |
|||
|
|||
export default slugify; |
File diff suppressed because one or more lines are too long
@ -0,0 +1,11 @@ |
|||
{ |
|||
"requires": true, |
|||
"lockfileVersion": 1, |
|||
"dependencies": { |
|||
"slugify": { |
|||
"version": "1.4.2", |
|||
"resolved": "https://registry.npmjs.org/slugify/-/slugify-1.4.2.tgz", |
|||
"integrity": "sha512-7UfMG5rtkxfOI5jg/+f4DMQS3ikUqfWnfMvitrhwdTV4pibWXq9mN4RNLHSV3M1lR++x7z+AG7znsiozdBP+aA==" |
|||
} |
|||
} |
|||
} |
@ -1,4 +1,3 @@ |
|||
library(slugify) |
|||
|
|||
# Placeholder with simple test |
|||
expect_equal(1 + 1, 2) |
|||
|
|||
expect_true(slugify("R is great!") == "r-is-great") |
Loading…
Reference in new issue