mirror of
https://github.com/FranzDiebold/github-env-vars-action.git
synced 2025-04-21 15:57:32 -05:00
Truncate slug values to 63 characters.
This commit is contained in:
parent
960f2f11d8
commit
9d7426b893
3 changed files with 25 additions and 12 deletions
9
index.js
9
index.js
|
@ -4,17 +4,20 @@ const core = require('@actions/core');
|
|||
const github = require('@actions/github');
|
||||
|
||||
/**
|
||||
* Slugify a given string.
|
||||
* Slugify a given string to a maximum length.
|
||||
* @param {string} inputString
|
||||
* @param {int} maxLength
|
||||
* @return {string} The slugified string.
|
||||
*/
|
||||
function slugify(inputString) {
|
||||
function slugify(inputString, maxLength = 63) {
|
||||
return inputString
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9 -]/g, ' ') // remove invalid chars
|
||||
.replace(/^\s+|\s+$/g, '') // trim
|
||||
.replace(/\s+/g, '-') // collapse whitespace and replace by -
|
||||
.replace(/-+/g, '-'); // collapse dashes
|
||||
.replace(/-+/g, '-') // collapse dashes
|
||||
.slice(0, maxLength) // truncate to maximum length
|
||||
.replace(/[-]+$/g, ''); // trim trailing -
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue