|
1 | 1 | <template> |
2 | 2 | <div> |
3 | | - <p>Use this helper to generate the possible fixtures for your own URL.</p> |
| 3 | + <p>Use this helper to generate the possible fixtures for your own URL. Please note this is a simple JavaScript port and it will not be 100% accurate for special or accented characters.</p> |
4 | 4 | <h4><label for="url">URL</label></h4> |
5 | 5 | <input class="input" type="text" id="url" placeholder="http://example.com/api/comments?query=json&order=id" v-model="url"/> |
6 | 6 | <h4><label for="method">Method</label></h4> |
|
75 | 75 | 'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', |
76 | 76 | 'о', 'و', 'θ', 'ို', 'ǒ', 'ǿ', 'º', 'ო', 'ओ', 'o', |
77 | 77 | 'ö'], |
78 | | - 'p' : ['п', 'π', 'ပ', 'პ', 'پ', 'p'], |
| 78 | + 'p' : ['п', 'π', 'ပ', 'პ', 'پ', 'p', 'ƥ'], |
79 | 79 | 'q' : ['ყ', 'q'], |
80 | 80 | 'r' : ['ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', 'რ', 'r'], |
81 | 81 | 's' : ['ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص', 'စ', |
|
253 | 253 | .map(param => { |
254 | 254 | return param.replace(/[\\/?:*"><|]/g, REPLACEMENT); |
255 | 255 | }) |
256 | | - // toAscii |
| 256 | + // folded + ascii |
257 | 257 | .map(param => { |
258 | 258 | Object.keys(CHARS).forEach(key => { |
259 | 259 | param = param.replace(new RegExp(`[${CHARS[key].join('')}]`, 'g'), key); |
260 | 260 | }); |
261 | | -
|
262 | | - return param.replace(/[^\x20-\x7E]/gu, ''); |
263 | | - }) |
264 | | - // delimit |
265 | | - .map(param => { |
266 | | - return param.replace(/\B([A-Z])/g, '-$1') |
267 | | - .toLowerCase() |
268 | | - .replace(/[-_\s]+/g, REPLACEMENT); |
| 261 | + return param.toLowerCase().replace(/[^\x20-\x7E]/gu, ''); |
269 | 262 | }) |
270 | | - // removeLeft |
| 263 | + // replaceMatches |
271 | 264 | .map(param => { |
272 | | - return param.replace(new RegExp(`^${REPLACEMENT}+`), ''); |
| 265 | + return param.replace(/[-_\s]+/, REPLACEMENT); |
273 | 266 | }) |
274 | | - // removeRight |
| 267 | + // trim |
275 | 268 | .map(param => { |
276 | | - return param.replace(new RegExp(`${REPLACEMENT}+$`), ''); |
| 269 | + return param.replace(new RegExp(`^${REPLACEMENT}+|${REPLACEMENT}+$`), ''); |
277 | 270 | }) |
278 | 271 | .join('&'); |
279 | 272 | } |
|
0 commit comments