@spare/phrasing
Advanced tools
Comparing version 0.3.7 to 0.3.9
@@ -85,2 +85,28 @@ 'use strict'; | ||
/** | ||
* Camel/pascal case phrase -> split vector | ||
* Snake: fox_jumps_over_dog | ||
* Kebab: fox-jumps-over-dog | ||
* @param {string} phrase camel/pascal-case phrase | ||
* @returns {string[]} | ||
*/ | ||
function camelToVector(phrase) { | ||
let ms, | ||
wd, | ||
ve = []; | ||
if ((ms = INILOW.exec(phrase)) && ([wd] = ms)) ve.push(wd); | ||
while ((ms = CAPWORD.exec(phrase)) && ([wd] = ms)) ve.push(wd); | ||
return ve; | ||
} | ||
/** | ||
* snake or kebab phrase -> split vector | ||
* @param {string} phrase - dashed phrase | ||
* @returns {string[]} | ||
*/ | ||
const snakeToVector = phrase => phrase.split(/\W/g); | ||
exports.CAMEL = CAMEL; | ||
@@ -94,6 +120,8 @@ exports.CAPREST = CAPREST; | ||
exports.camelToSnake = camelToSnake; | ||
exports.camelToVector = camelToVector; | ||
exports.snakeToCamel = snakeToCamel; | ||
exports.snakeToPascal = snakeToPascal; | ||
exports.snakeToVector = snakeToVector; | ||
exports.wordToCap = wordToCap; | ||
exports.wordsToCamel = wordsToCamel; | ||
exports.wordsToPascal = wordsToPascal; |
@@ -81,2 +81,28 @@ import { mutate } from '@vect/vector-mapper'; | ||
export { CAMEL, CAPREST, CAPWORD, DASH_CAPREST, INILOW, INIWORD, WORD, camelToSnake, snakeToCamel, snakeToPascal, wordToCap, wordsToCamel, wordsToPascal }; | ||
/** | ||
* Camel/pascal case phrase -> split vector | ||
* Snake: fox_jumps_over_dog | ||
* Kebab: fox-jumps-over-dog | ||
* @param {string} phrase camel/pascal-case phrase | ||
* @returns {string[]} | ||
*/ | ||
function camelToVector(phrase) { | ||
let ms, | ||
wd, | ||
ve = []; | ||
if ((ms = INILOW.exec(phrase)) && ([wd] = ms)) ve.push(wd); | ||
while ((ms = CAPWORD.exec(phrase)) && ([wd] = ms)) ve.push(wd); | ||
return ve; | ||
} | ||
/** | ||
* snake or kebab phrase -> split vector | ||
* @param {string} phrase - dashed phrase | ||
* @returns {string[]} | ||
*/ | ||
const snakeToVector = phrase => phrase.split(/\W/g); | ||
export { CAMEL, CAPREST, CAPWORD, DASH_CAPREST, INILOW, INIWORD, WORD, camelToSnake, camelToVector, snakeToCamel, snakeToPascal, snakeToVector, wordToCap, wordsToCamel, wordsToPascal }; |
{ | ||
"name": "@spare/phrasing", | ||
"version": "0.3.7", | ||
"description": "A debugging tool", | ||
"version": "0.3.9", | ||
"description": "Convert among snake/kebab/camel/pascal phrasings", | ||
"main": "dist/index.cjs.js", | ||
@@ -25,6 +25,8 @@ "module": "dist/index.esm.js", | ||
"keywords": [ | ||
"test", | ||
"console", | ||
"debug", | ||
"print" | ||
"phrasing", | ||
"split", | ||
"camel", | ||
"kebab", | ||
"pascal", | ||
"snake" | ||
], | ||
@@ -37,3 +39,3 @@ "author": "Hoyeung Wong", | ||
"homepage": "https://github.com/hoyeungw/spare#readme", | ||
"gitHead": "24f9b918bfc02607aca1c23933c6409c7097ded8" | ||
"gitHead": "028ebcbe8435520c001ae45a558c5682333f77e6" | ||
} |
9758
188