added all files to project

This commit is contained in:
2022-03-10 10:36:59 +01:00
parent 09dd957b33
commit 46a936d7de
25351 changed files with 3883356 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
node_modules
test
+78
View File
@@ -0,0 +1,78 @@
# Slugg
Make strings url-safe.
- Comprehensive tests
- No dependencies
- Not in coffee-script (lol)
- Coerces foreign symbols to their english equivalent
- Doesn't try to do anything fancy with symbols (just removes them)
- Works in browser (`window.slugg`) and AMD/CommonJS-flavoured module loaders
```
npm install slugg
```
## Usage:
### slug(string, [separator, toStrip])
```js
var slug = require('slugg')
slug('My fantastic blog post')
//-> 'my-fantastic-blog-post'
slug('Today I found £5')
//-> 'today-i-found-5'
slug('I ♥ you')
//-> 'i-you'
```
If you want a separator other than '-', pass it in as the second argument:
```js
slug('Kevin Spacey', ' ')
//-> 'kevin spacey'
```
By default, slugg will strip (i.e. remove and not replace) any sort of quotemark: `'"’‘”“`.
If you want to control which characters are stripped, pass a regex as the last option
that will match the chars you want to replace, eg:
```js
slug('Mum\'s cooking', /'/g)
//-> 'mums-cooking'
```
Remember to use the `g` flag if you want all the matches stripped (not just the first).
After version 1.1.0, a new syntax has been introduced:
### slug(string, [options])
If you want a separator other than '-', pass it in as the `separator` option:
```js
slug('Kevin Spacey', { separator: ' ' })
//-> 'kevin spacey'
```
If you want to control which characters are stripped, pass a regex as the `toStrip` option
that will match the chars you want to replace, eg:
```js
slug('Mum\'s cooking', { toStrip: /'/g })
//-> 'mums-cooking'
```
Remember to use the `g` flag if you want all the matches stripped (not just the first).
By default, slugg will convert your string to lower case. If you want to disable it just
pass the `toLowerCase` option as `false`, eg:
```js
slug('Slugg rocks!', { toLowerCase: false })
//-> 'Slugg-rocks'
```
+20
View File
@@ -0,0 +1,20 @@
{
"name": "slugg",
"repo": "bengourley/slugg",
"description": "Make strings url safe (with no dependencies)",
"version": "0.1.3",
"repository": "git@github.com:bengourley/slugg.git",
"author": "Ben Gourley",
"license": "BSD",
"keywords": [
"slug",
"url",
"string"
],
"dependencies": {},
"development": {},
"main": "slugg.js",
"scripts": [
"slugg.js"
]
}
+60
View File
@@ -0,0 +1,60 @@
{
"_from": "slugg@^1.2.0",
"_id": "slugg@1.2.1",
"_inBundle": false,
"_integrity": "sha1-51KvIkGvPycURjxd4iXOpHYIdAo=",
"_location": "/slugg",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "slugg@^1.2.0",
"name": "slugg",
"escapedName": "slugg",
"rawSpec": "^1.2.0",
"saveSpec": null,
"fetchSpec": "^1.2.0"
},
"_requiredBy": [
"/hafas-client"
],
"_resolved": "https://registry.npmjs.org/slugg/-/slugg-1.2.1.tgz",
"_shasum": "e752af2241af3f2714463c5de225cea47608740a",
"_spec": "slugg@^1.2.0",
"_where": "/home/pi/MagicMirror/modules/MMM-PublicTransportHafas/node_modules/hafas-client",
"author": {
"name": "Ben Gourley"
},
"bugs": {
"url": "https://github.com/bengourley/slugg/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Make strings url safe (with no dependencies)",
"devDependencies": {
"mocha": "~1.7",
"mocha-srv": "~0.1",
"proclaim": "~1.2"
},
"homepage": "https://github.com/bengourley/slugg#readme",
"keywords": [
"slug",
"url",
"string"
],
"license": "BSD",
"main": "slugg.js",
"name": "slugg",
"publishConfig": {
"registry": "http://registry.npmjs.org/"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/bengourley/slugg.git"
},
"scripts": {
"test": "mocha test -R spec",
"test-browser": "mocha-srv test"
},
"version": "1.2.1"
}
+133
View File
@@ -0,0 +1,133 @@
(function (root) {
var defaultSeparator = '-'
var defaultToStrip = /['"’‘”“]/g
var defaultToLowerCase = true
function slugg(string, separator, toStrip) {
// Coerce the value into a string.
if ([ undefined, null ].indexOf(string) !== -1) string = ''
string = typeof string.toString === 'function' ? string.toString() : ''
var options = {}
if (typeof separator === 'object') {
options = separator
} else {
options.separator = separator
options.toStrip = toStrip
// Separator might be omitted and toStrip in its place
if (options.separator instanceof RegExp) {
options.toStrip = separator
options.separator = defaultSeparator
}
// Only a separator was passed
if (typeof options.toStrip === 'undefined') options.toStrip = /['"’‘”“]/g
}
// Separator is optional
if (typeof options.separator === 'undefined') options.separator = defaultSeparator
// toStrip is optional
if (typeof options.toStrip === 'undefined') options.toStrip = defaultToStrip
// toLowerCase is optional
if (typeof options.toLowerCase === 'undefined') options.toLowerCase = defaultToLowerCase
// Make lower-case
if (options.toLowerCase) string = string.toLowerCase()
// Swap out non-english characters for their english equivalent
for (var i = 0, len = string.length; i < len; i++) {
if (chars[string.charAt(i)]) {
string = string.replace(string.charAt(i), chars[string.charAt(i)])
}
}
string = string
// Strip chars that shouldn't be replaced with separator
.replace(options.toStrip, '')
// Replace non-word characters with separator
.replace(/[\W|_]+/g, options.separator)
// Strip dashes from the beginning
.replace(new RegExp('^' + options.separator + '+'), '')
// Strip dashes from the end
.replace(new RegExp(options.separator + '+$'), '')
return string
}
// Conversion table. Modified version of:
// https://github.com/dodo/node-slug/blob/master/src/slug.coffee
var chars = slugg.chars = {
// Latin
'À': 'A', 'Á': 'A', 'Â': 'A', 'Ã': 'A', 'Ä': 'A', 'Å': 'A', 'Æ': 'AE',
'Ç': 'C', 'È': 'E', 'É': 'E', 'Ê': 'E', 'Ë': 'E', 'Ì': 'I', 'Í': 'I',
'Î': 'I', 'Ï': 'I', 'Ð': 'D', 'Ñ': 'N', 'Ò': 'O', 'Ó': 'O', 'Ô': 'O',
'Õ': 'O', 'Ö': 'O', 'Ő': 'O', 'Ø': 'O', 'Ù': 'U', 'Ú': 'U', 'Û': 'U',
'Ü': 'U', 'Ű': 'U', 'Ý': 'Y', 'Þ': 'TH', 'ß': 'ss', 'à': 'a', 'á': 'a',
'â': 'a', 'ã': 'a', 'ä': 'a', 'å': 'a', 'æ': 'ae', 'ç': 'c', 'è': 'e',
'é': 'e', 'ê': 'e', 'ë': 'e', 'ì': 'i', 'í': 'i', 'î': 'i', 'ï': 'i',
'ð': 'd', 'ñ': 'n', 'ò': 'o', 'ó': 'o', 'ô': 'o', 'õ': 'o', 'ö': 'o',
'ő': 'o', 'ø': 'o', 'ù': 'u', 'ú': 'u', 'û': 'u', 'ü': 'u', 'ű': 'u',
'ý': 'y', 'þ': 'th', 'ÿ': 'y', 'ẞ': 'SS', 'œ': 'oe', 'Œ': 'OE',
// Greek
'α': 'a', 'β': 'b', 'γ': 'g', 'δ': 'd', 'ε': 'e', 'ζ': 'z', 'η': 'h',
'θ': '8', 'ι': 'i', 'κ': 'k', 'λ': 'l', 'μ': 'm', 'ν': 'n', 'ξ': '3',
'ο': 'o', 'π': 'p', 'ρ': 'r', 'σ': 's', 'τ': 't', 'υ': 'y', 'φ': 'f',
'χ': 'x', 'ψ': 'ps', 'ω': 'w', 'ά': 'a', 'έ': 'e', 'ί': 'i', 'ό': 'o',
'ύ': 'y', 'ή': 'h', 'ώ': 'w', 'ς': 's', 'ϊ': 'i', 'ΰ': 'y', 'ϋ': 'y',
'ΐ': 'i', 'Α': 'A', 'Β': 'B', 'Γ': 'G', 'Δ': 'D', 'Ε': 'E', 'Ζ': 'Z',
'Η': 'H', 'Θ': '8', 'Ι': 'I', 'Κ': 'K', 'Λ': 'L', 'Μ': 'M', 'Ν': 'N',
'Ξ': '3', 'Ο': 'O', 'Π': 'P', 'Ρ': 'R', 'Σ': 'S', 'Τ': 'T', 'Υ': 'Y',
'Φ': 'F', 'Χ': 'X', 'Ψ': 'PS', 'Ω': 'W', 'Ά': 'A', 'Έ': 'E', 'Ί': 'I',
'Ό': 'O', 'Ύ': 'Y', 'Ή': 'H', 'Ώ': 'W', 'Ϊ': 'I', 'Ϋ': 'Y',
// Turkish
'ş': 's', 'Ş': 'S', 'ı': 'i', 'İ': 'I', 'ğ': 'g', 'Ğ': 'G',
// Russian
'а': 'a', 'б': 'b', 'в': 'v', 'г': 'g', 'д': 'd', 'е': 'e', 'ё': 'yo',
'ж': 'zh', 'з': 'z', 'и': 'i', 'й': 'j', 'к': 'k', 'л': 'l', 'м': 'm',
'н': 'n', 'о': 'o', 'п': 'p', 'р': 'r', 'с': 's', 'т': 't', 'у': 'u',
'ф': 'f', 'х': 'h', 'ц': 'c', 'ч': 'ch', 'ш': 'sh', 'щ': 'sh', 'ъ': 'u',
'ы': 'y', 'э': 'e', 'ю': 'yu', 'я': 'ya', 'А': 'A', 'Б': 'B',
'В': 'V', 'Г': 'G', 'Д': 'D', 'Е': 'E', 'Ё': 'Yo', 'Ж': 'Zh', 'З': 'Z',
'И': 'I', 'Й': 'J', 'К': 'K', 'Л': 'L', 'М': 'M', 'Н': 'N', 'О': 'O',
'П': 'P', 'Р': 'R', 'С': 'S', 'Т': 'T', 'У': 'U', 'Ф': 'F', 'Х': 'H',
'Ц': 'C', 'Ч': 'Ch', 'Ш': 'Sh', 'Щ': 'Sh', 'Ъ': 'U', 'Ы': 'Y',
'Э': 'E', 'Ю': 'Yu', 'Я': 'Ya',
// Ukranian
'Є': 'Ye', 'І': 'I', 'Ї': 'Yi', 'Ґ': 'G',
'є': 'ye', 'і': 'i', 'ї': 'yi', 'ґ': 'g',
// Czech
'č': 'c', 'ď': 'd', 'ě': 'e', 'ň': 'n', 'ř': 'r', 'š': 's',
'ť': 't', 'ů': 'u', 'ž': 'z', 'Č': 'C', 'Ď': 'D', 'Ě': 'E',
'Ň': 'N', 'Ř': 'R', 'Š': 'S', 'Ť': 'T', 'Ů': 'U', 'Ž': 'Z',
// Polish
'ą': 'a', 'ć': 'c', 'ę': 'e', 'ł': 'l', 'ń': 'n', 'ś': 's',
'ź': 'z', 'ż': 'z', 'Ą': 'A', 'Ć': 'C', 'Ę': 'e', 'Ł': 'L',
'Ń': 'N', 'Ś': 'S', 'Ź': 'Z', 'Ż': 'Z',
// Latvian
'ā': 'a', 'ē': 'e', 'ģ': 'g', 'ī': 'i', 'ķ': 'k', 'ļ': 'l',
'ņ': 'n', 'ū': 'u', 'Ā': 'A', 'Ē': 'E', 'Ģ': 'G', 'Ī': 'i',
'Ķ': 'k', 'Ļ': 'L', 'Ņ': 'N', 'Ū': 'u'
}
// Be compatible with different module systems
if (typeof define !== 'undefined' && define.amd) {
// AMD
define([], function () {
return slugg
})
} else if (typeof module !== 'undefined' && module.exports) {
// CommonJS
module.exports = slugg
} else {
// Script tag
root.slugg = slugg
}
}(this))