bowhead-js
Advanced tools
Comparing version 2.0.0 to 2.1.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var regex = /{([0-9]+)(\:[a-z]+)?}/g; | ||
var regex = /{([0-9]+)(\:[a-z\:]+)?}/g; | ||
var isMuted = true; | ||
@@ -18,3 +18,3 @@ function muteExceptions(val) { | ||
return str.replace(regex, function (_, g1, g2) { | ||
var funcName = g2 ? g2.substr(1) : ''; | ||
var payload = g2 ? g2.substr(1) : ''; | ||
var idx = parseInt(g1, 10); | ||
@@ -37,24 +37,39 @@ if (isNaN(idx)) { | ||
} | ||
var val = args[idx] ? args[idx].toString() : ''; | ||
var input = args[idx] ? args[idx].toString() : ''; | ||
var payloadStrings = payload.split(':'); | ||
var funcName = payloadStrings[0]; | ||
var extraParams = payloadStrings.slice(1); | ||
if (funcName) { | ||
switch (funcName) { | ||
case 'lowercase': | ||
val = val.toLowerCase(); | ||
input = input.toLowerCase(); | ||
break; | ||
case 'uppercase': { | ||
val = val.toUpperCase(); | ||
input = input.toUpperCase(); | ||
break; | ||
} | ||
case 'capitalized': { | ||
if (val) { | ||
val = val.charAt(0).toUpperCase() + val.substr(1); | ||
if (input) { | ||
input = input.charAt(0).toUpperCase() + input.substr(1); | ||
} | ||
break; | ||
} | ||
case 'countable': { | ||
var inputNum = parseInt(input, 10); | ||
if (!isNaN(inputNum)) { | ||
if (inputNum === 1) { | ||
input = extraParams[0] || ''; | ||
} | ||
else { | ||
input = extraParams[1] || extraParams[0] || ''; | ||
} | ||
} | ||
break; | ||
} | ||
default: | ||
val = val + ":" + funcName; | ||
input = input + ":" + funcName; | ||
break; | ||
} | ||
} | ||
return val; | ||
return input; | ||
}); | ||
@@ -61,0 +76,0 @@ } |
{ | ||
"name": "bowhead-js", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Tiny string interpolation library", | ||
@@ -37,13 +37,13 @@ "main": "dist/main.js", | ||
"devDependencies": { | ||
"@types/mocha": "^5.2.7", | ||
"@types/node": "^12.12.7", | ||
"@typescript-eslint/eslint-plugin": "^2.7.0", | ||
"@typescript-eslint/parser": "^2.7.0", | ||
"cross-env": "^6.0.3", | ||
"@types/mocha": "^7.0.1", | ||
"@types/node": "^13.7.7", | ||
"@typescript-eslint/eslint-plugin": "^2.21.0", | ||
"@typescript-eslint/parser": "^2.21.0", | ||
"cross-env": "^7.0.0", | ||
"del-cli": "^3.0.0", | ||
"eslint": "^6.6.0", | ||
"mocha": "^6.2.2", | ||
"typescript": "^3.7.2" | ||
"eslint": "^6.8.0", | ||
"mocha": "^7.1.0", | ||
"typescript": "^3.8.3" | ||
}, | ||
"dependencies": {} | ||
} |
@@ -21,7 +21,15 @@ # bowhead-js | ||
// Index-based arguments | ||
format('{1} {0} {1}', 1, 'haha'); // "haha 1 haha" | ||
// Index-based arguments. | ||
format('{1} {0} {1}', 1, 'haha'); // 'haha 1 haha' | ||
// Custom functions | ||
format('{0:uppercase}', 'haha'); // "HAHA" | ||
// Custom functions. | ||
format('{0:uppercase}', 'haha'); // 'HAHA' | ||
// Plurals. | ||
format('{0:countable:fish:fishes}', '1'); // 'fish'; | ||
format('{0:countable:fish:fishes}', '2'); // 'fishes' | ||
format('{0:countable:fish:fishes}', '0'); // 'fishes' | ||
// "deer" is both singular and plural. | ||
format('{0:countable:deer}', '1'); // 'deer' | ||
format('{0:countable:deer}', '2'); // 'deer' | ||
``` | ||
@@ -34,2 +42,3 @@ | ||
- `capitalized` capitalizes first letter | ||
- `countable` handles plurals | ||
@@ -36,0 +45,0 @@ ### Error handling |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8753
77
57