Comparing version 0.0.1 to 1.0.0
/** | ||
* Return a formatted string and accepts a variable number of arguments. | ||
* Return a formatted string and accepts a variable number of arguments | ||
* whose first argument correspond to string format | ||
* | ||
@@ -7,2 +8,9 @@ * @returns a formatted string | ||
export declare function sprintf(...args: any[]): string; | ||
export default sprintf; | ||
/** | ||
* Operates as `sprintf()` but accepts an array of arguments | ||
* | ||
* @param format string format | ||
* @param argsv an array of arguments | ||
* @returns a formatted string | ||
*/ | ||
export declare function vsprintf(format?: any, argsv?: any[]): string; |
66
index.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var chars = 's'; | ||
/** | ||
* Return a formatted string and accepts a variable number of arguments. | ||
* Return a formatted string using an array of arguments | ||
* | ||
* @param args array of arguments | ||
* @returns a formatted string | ||
*/ | ||
function sprintf() { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
function sprintfv(args) { | ||
var argsLen = args.length; | ||
var formatv = (args[0] || '').toString(); | ||
var argv = []; | ||
var argvLen = argsLen > 0 ? argsLen - 1 : 0; | ||
// Notice: type specifier '%s' is only supported | ||
var formats = formatv.split('%s'); | ||
var formatsLen = formats.length; | ||
if (formatsLen <= 0) { | ||
return formatv; | ||
} | ||
var len = args.length; | ||
var format = (args[0] || '').toString(); | ||
var argv = len > 0 ? new Array(len - 1) : []; | ||
// TODO: type specifier '%s' supported only | ||
var formats = format.split("%" + chars); | ||
if (formats.length <= 0) { | ||
return format; | ||
} | ||
var times = formats.length - 1; | ||
if (times > argv.length) | ||
var formatLen = formatsLen - 1; | ||
if (formatLen > argvLen) { | ||
throw new Error('Too few arguments supplied.'); | ||
for (var i = 0; i < len - 1; ++i) { | ||
argv[i] = (args[i + 1] || '').toString(); | ||
} | ||
for (var i = 0; i < argsLen - 1; ++i) { | ||
argv.push((args[i + 1] || '').toString()); | ||
} | ||
var str = ''; | ||
for (var i = 0; i < formats.length; i++) { | ||
for (var i = 0; i < formatsLen; i++) { | ||
str += formats[i] || ''; | ||
if (i < times) { | ||
if (i < formatLen) { | ||
str += argv[i] || ''; | ||
@@ -37,3 +36,28 @@ } | ||
} | ||
/** | ||
* Return a formatted string and accepts a variable number of arguments | ||
* whose first argument correspond to string format | ||
* | ||
* @returns a formatted string | ||
*/ | ||
function sprintf() { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return sprintfv(args); | ||
} | ||
exports.sprintf = sprintf; | ||
exports.default = sprintf; | ||
/** | ||
* Operates as `sprintf()` but accepts an array of arguments | ||
* | ||
* @param format string format | ||
* @param argsv an array of arguments | ||
* @returns a formatted string | ||
*/ | ||
function vsprintf(format, argsv) { | ||
if (format === void 0) { format = ''; } | ||
if (argsv === void 0) { argsv = []; } | ||
return sprintfv([format].concat(argsv)); | ||
} | ||
exports.vsprintf = vsprintf; |
@@ -5,3 +5,3 @@ { | ||
"repository": "joseluisq/sprintfit", | ||
"version": "0.0.1", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
@@ -34,3 +34,3 @@ "author": { | ||
"jasmine-spec-reporter": "^4.2.1", | ||
"karma": "^2.0.4", | ||
"karma": "^2.0.5", | ||
"karma-chrome-launcher": "^2.2.0", | ||
@@ -37,0 +37,0 @@ "karma-jasmine": "^1.1.2", |
@@ -44,3 +44,3 @@ # Sprintfit [![Build Status](https://travis-ci.org/joseluisq/sprintfit.svg?branch=master)](https://travis-ci.org/joseluisq/sprintfit) [![npm](https://img.shields.io/npm/v/sprintfit.svg)](https://www.npmjs.com/package/sprintfit) [![npm](https://img.shields.io/npm/dt/sprintfit.svg)](https://www.npmjs.com/package/sprintfit) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) | ||
Operates as `vsprintf()` but accepts an array of arguments. | ||
Operates as `sprintf()` but accepts an array of arguments. | ||
@@ -47,0 +47,0 @@ ```js |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.sprintfit={})}(this,function(e){"use strict";var t="s";function r(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var n=e.length,o=(e[0]||"").toString(),f=n>0?new Array(n-1):[],i=o.split("%"+t);if(i.length<=0)return o;var u=i.length-1;if(u>f.length)throw new Error("Too few arguments supplied.");for(var s=0;s<n-1;++s)f[s]=(e[s+1]||"").toString();var l="";for(s=0;s<i.length;s++)l+=i[s]||"",s<u&&(l+=f[s]||"");return l}e.sprintf=r,e.default=r,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.sprintfit={})}(this,function(t){"use strict";function e(t){var e=t.length,n=(t[0]||"").toString(),r=[],o=e>0?e-1:0,i=n.split("%s"),f=i.length;if(f<=0)return n;var u=f-1;if(u>o)throw new Error("Too few arguments supplied.");for(var s=0;s<e-1;++s)r.push((t[s+1]||"").toString());var p="";for(s=0;s<f;s++)p+=i[s]||"",s<u&&(p+=r[s]||"");return p}t.sprintf=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return e(t)},t.vsprintf=function(t,n){return void 0===t&&(t=""),void 0===n&&(n=[]),e([t].concat(n))},Object.defineProperty(t,"__esModule",{value:!0})}); |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
7451
80
1