From 7c1394619a480fd4a5e290c4b9b9db6d64462e82 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 07:09:22 +0000 Subject: [PATCH 001/150] Auto-generated commit 877f1a1493ceb7a0f42b2866d7eb54626fc84d65 --- index.d.ts | 42 + index.mjs | 4 + index.mjs.map | 1 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 2736 insertions(+) create mode 100644 index.d.ts create mode 100644 index.mjs create mode 100644 index.mjs.map create mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..7ae7765 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,42 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2022 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 2.0 + +/** +* Inserts supplied variable values into a format string. +* +* @param str - input string +* @param ...args - variable values +* @throws invalid flags +* @returns formatted string +* +* @example +* var str = format( 'Hello %s!', 'world' ); +* // returns 'Hello world!' +* +* @example +* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); +* // returns 'Pi: ~3.14' +*/ +declare function format( str: string, ...args: Array ): string; + + +// EXPORTS // + +export = format; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f5d68cf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +var e=function(e){return"number"==typeof e};function r(e){var r,a="";for(r=0;r0&&(r-=1),a=i.toExponential(r)):a=i.toPrecision(e.precision),e.alternate||(a=d.call(a,m,"$1e"),a=d.call(a,v,"e"),a=d.call(a,b,""));break;default:throw new Error("invalid double notation. Value: "+e.specifier)}return a=d.call(a,h,"e+0$1"),a=d.call(a,f,"e-0$1"),e.alternate&&(a=d.call(a,u,"$1."),a=d.call(a,w,"$1.e")),i>=0&&e.sign&&(a=e.sign+a),a=e.specifier===g.call(e.specifier)?g.call(a):l.call(a)},S=function(e){var r,a,i,t;for(a=[],t=0,i=x.exec(e);i;)(r=e.slice(t,x.lastIndex-i[0].length)).length&&a.push(r),a.push(k(i)),t=x.lastIndex,i=x.exec(e);return(r=e.slice(t)).length&&a.push(r),a},F=function(e,r,a){var i=r-e.length;return i<0?e:e=a?e+E(i):E(i)+e},I=a,P=function(e){return"string"==typeof e},V=String.fromCharCode,C=isNaN;var R=function e(r){var a,i,t,n,s,o,c,p,l;if(!P(r))throw new TypeError(e("invalid argument. First argument must be a string. Value: `%s`.",r));for(a=S(r),o="",c=1,p=0;p127)throw new Error("invalid character code. Value: "+t.arg);t.arg=C(s)?String(t.arg):V(s)}break;case"e":case"E":case"f":case"F":case"g":case"G":t.hasPeriod||(t.precision=6),t.arg=$(t);break;default:throw new Error("invalid specifier: "+t.specifier)}t.maxWidth>=0&&t.arg.length>t.maxWidth&&(t.arg=t.arg.substring(0,t.maxWidth)),t.padZeros?t.arg=I(t.arg,t.width||t.precision,t.padRight):t.width&&(t.arg=F(t.arg,t.width,t.padRight)),o+=t.arg||"",c+=1}return o},Z=R;export{Z as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..ece543a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/is_number.js","../lib/zero_pad.js","../lib/format_integer.js","../lib/format_double.js","../lib/tokenize.js","../lib/space_pad.js","../lib/is_string.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' ); // NOTE: we inline the `isNumber.isPrimitive` function from `@stdlib/assert/is-number` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Tests if a string starts with a minus sign (`-`).\n*\n* @private\n* @param {string} str - input string\n* @returns {boolean} boolean indicating if a string starts with a minus sign (`-`)\n*/\nfunction startsWithMinus( str ) {\n\treturn str[ 0 ] === '-';\n}\n\n/**\n* Returns a string of `n` zeros.\n*\n* @private\n* @param {number} n - number of zeros\n* @returns {string} string of zeros\n*/\nfunction zeros( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += '0';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with zeros to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction zeroPad( str, width, right ) {\n\tvar negative = false;\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tif ( startsWithMinus( str ) ) {\n\t\tnegative = true;\n\t\tstr = str.substr( 1 );\n\t}\n\tstr = ( right ) ?\n\t\tstr + zeros( pad ) :\n\t\tzeros( pad ) + str;\n\tif ( negative ) {\n\t\tstr = '-' + str;\n\t}\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = zeroPad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isNumber = require( './is_number.js' );\nvar zeroPad = require( './zero_pad.js' );\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as an integer.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid integer\n* @returns {string} formatted token argument\n*/\nfunction formatInteger( token ) {\n\tvar base;\n\tvar out;\n\tvar i;\n\n\tswitch ( token.specifier ) {\n\tcase 'b':\n\t\t// Case: %b (binary)\n\t\tbase = 2;\n\t\tbreak;\n\tcase 'o':\n\t\t// Case: %o (octal)\n\t\tbase = 8;\n\t\tbreak;\n\tcase 'x':\n\tcase 'X':\n\t\t// Case: %x, %X (hexadecimal)\n\t\tbase = 16;\n\t\tbreak;\n\tcase 'd':\n\tcase 'i':\n\tcase 'u':\n\tdefault:\n\t\t// Case: %d, %i, %u (decimal)\n\t\tbase = 10;\n\t\tbreak;\n\t}\n\tout = token.arg;\n\ti = parseInt( out, 10 );\n\tif ( !isFinite( i ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( out ) ) {\n\t\t\tthrow new Error( 'invalid integer. Value: ' + out );\n\t\t}\n\t\ti = 0;\n\t}\n\tif ( i < 0 && ( token.specifier === 'u' || base !== 10 ) ) {\n\t\ti = 0xffffffff + i + 1;\n\t}\n\tif ( i < 0 ) {\n\t\tout = ( -i ).toString( base );\n\t\tif ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tout = '-' + out;\n\t} else {\n\t\tout = i.toString( base );\n\t\tif ( !i && !token.precision ) {\n\t\t\tout = '';\n\t\t} else if ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tif ( token.sign ) {\n\t\t\tout = token.sign + out;\n\t\t}\n\t}\n\tif ( base === 16 ) {\n\t\tif ( token.alternate ) {\n\t\t\tout = '0x' + out;\n\t\t}\n\t\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\t\tuppercase.call( out ) :\n\t\t\tlowercase.call( out );\n\t}\n\tif ( base === 8 ) {\n\t\tif ( token.alternate && out.charAt( 0 ) !== '0' ) {\n\t\t\tout = '0' + out;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = formatInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isNumber = require( './is_number.js' );\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar abs = Math.abs; // eslint-disable-line stdlib/no-builtin-math\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\nvar replace = String.prototype.replace;\n\n\n// VARIABLES //\n\nvar RE_EXP_POS_DIGITS = /e\\+(\\d)$/;\nvar RE_EXP_NEG_DIGITS = /e-(\\d)$/;\nvar RE_ONLY_DIGITS = /^(\\d+)$/;\nvar RE_DIGITS_BEFORE_EXP = /^(\\d+)e/;\nvar RE_TRAILING_PERIOD_ZERO = /\\.0$/;\nvar RE_PERIOD_ZERO_EXP = /\\.0*e/;\nvar RE_ZERO_BEFORE_EXP = /(\\..*[^0])0*e/;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as a floating-point number.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid floating-point number\n* @returns {string} formatted token argument\n*/\nfunction formatDouble( token ) {\n\tvar digits;\n\tvar out;\n\tvar f = parseFloat( token.arg );\n\tif ( !isFinite( f ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( token.arg ) ) {\n\t\t\tthrow new Error( 'invalid floating-point number. Value: ' + out );\n\t\t}\n\t\t// Case: NaN, Infinity, or -Infinity\n\t\tf = token.arg;\n\t}\n\tswitch ( token.specifier ) {\n\tcase 'e':\n\tcase 'E':\n\t\tout = f.toExponential( token.precision );\n\t\tbreak;\n\tcase 'f':\n\tcase 'F':\n\t\tout = f.toFixed( token.precision );\n\t\tbreak;\n\tcase 'g':\n\tcase 'G':\n\t\tif ( abs( f ) < 0.0001 ) {\n\t\t\tdigits = token.precision;\n\t\t\tif ( digits > 0 ) {\n\t\t\t\tdigits -= 1;\n\t\t\t}\n\t\t\tout = f.toExponential( digits );\n\t\t} else {\n\t\t\tout = f.toPrecision( token.precision );\n\t\t}\n\t\tif ( !token.alternate ) {\n\t\t\tout = replace.call( out, RE_ZERO_BEFORE_EXP, '$1e' );\n\t\t\tout = replace.call( out, RE_PERIOD_ZERO_EXP, 'e');\n\t\t\tout = replace.call( out, RE_TRAILING_PERIOD_ZERO, '' );\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tthrow new Error( 'invalid double notation. Value: ' + token.specifier );\n\t}\n\tout = replace.call( out, RE_EXP_POS_DIGITS, 'e+0$1' );\n\tout = replace.call( out, RE_EXP_NEG_DIGITS, 'e-0$1' );\n\tif ( token.alternate ) {\n\t\tout = replace.call( out, RE_ONLY_DIGITS, '$1.' );\n\t\tout = replace.call( out, RE_DIGITS_BEFORE_EXP, '$1.e' );\n\t}\n\tif ( f >= 0 && token.sign ) {\n\t\tout = token.sign + out;\n\t}\n\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\tuppercase.call( out ) :\n\t\tlowercase.call( out );\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = formatDouble;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar RE = /%(?:([1-9]\\d*)\\$)?([0 +\\-#]*)(\\*|\\d+)?(?:(\\.)(\\*|\\d+)?)?[hlL]?([%A-Za-z])/g;\n\n\n// FUNCTIONS //\n\n/**\n* Parses a delimiter.\n*\n* @private\n* @param {Array} match - regular expression match\n* @returns {Object} delimiter token object\n*/\nfunction parse( match ) {\n\treturn {\n\t\t'mapping': ( match[ 1 ] ) ? parseInt( match[ 1 ], 10 ) : void 0,\n\t\t'flags': match[ 2 ],\n\t\t'width': match[ 3 ],\n\t\t'hasPeriod': match[ 4 ] === '.',\n\t\t'precision': match[ 5 ],\n\t\t'specifier': match[ 6 ]\n\t};\n}\n\n\n// MAIN //\n\n/**\n* Tokenizes a string.\n*\n* @private\n* @param {string} str - input string\n* @returns {Array} tokens\n*/\nfunction tokenize( str ) {\n\tvar content;\n\tvar tokens;\n\tvar match;\n\tvar prev;\n\n\ttokens = [];\n\tprev = 0;\n\tmatch = RE.exec( str );\n\twhile ( match ) {\n\t\tcontent = str.slice( prev, RE.lastIndex - match[ 0 ].length );\n\t\tif ( content.length ) {\n\t\t\ttokens.push( content );\n\t\t}\n\t\ttokens.push( parse( match ) );\n\t\tprev = RE.lastIndex;\n\t\tmatch = RE.exec( str );\n\t}\n\tcontent = str.slice( prev );\n\tif ( content.length ) {\n\t\ttokens.push( content );\n\t}\n\treturn tokens;\n}\n\n\n// EXPORTS //\n\nmodule.exports = tokenize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Returns `n` spaces.\n*\n* @private\n* @param {number} n - number of spaces\n* @returns {string} string of spaces\n*/\nfunction spaces( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += ' ';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with spaces to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction spacePad( str, width, right ) {\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tstr = ( right ) ?\n\t\tstr + spaces( pad ) :\n\t\tspaces( pad ) + str;\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = spacePad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar formatInteger = require( './format_integer.js' );\nvar formatDouble = require( './format_double.js' );\nvar tokenize = require( './tokenize.js' );\nvar spacePad = require( './space_pad.js' );\nvar zeroPad = require( './zero_pad.js' );\nvar isString = require( './is_string.js' );\n\n\n// VARIABLES //\n\nvar fromCharCode = String.fromCharCode;\nvar isnan = isNaN; // NOTE: We use the global `isNaN` function here instead of `@stdlib/math/base/assert/is-nan` to avoid circular dependencies.\n\n\n// MAIN //\n\n/**\n* Inserts supplied variable values into a format string.\n*\n* @param {string} str - input string\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be a string\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var str = format( 'Hello %s!', 'world' );\n* // returns 'Hello world!'\n*\n* @example\n* var str = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\nfunction format( str ) {\n\tvar tokens;\n\tvar flags;\n\tvar token;\n\tvar flag;\n\tvar num;\n\tvar out;\n\tvar pos;\n\tvar i;\n\tvar j;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\ttokens = tokenize( str );\n\tout = '';\n\tpos = 1;\n\tfor ( i = 0; i < tokens.length; i++ ) {\n\t\ttoken = tokens[ i ];\n\t\tif ( isString( token ) ) {\n\t\t\tout += token;\n\t\t} else {\n\t\t\tif ( token.mapping ) {\n\t\t\t\tpos = token.mapping;\n\t\t\t}\n\t\t\tflags = token.flags;\n\t\t\tfor ( j = 0; j < flags.length; j++ ) {\n\t\t\t\tflag = flags.charAt( j );\n\t\t\t\tswitch ( flag ) {\n\t\t\t\tcase ' ':\n\t\t\t\t\ttoken.sign = ' ';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '+':\n\t\t\t\t\ttoken.sign = '+';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '-':\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '0':\n\t\t\t\t\ttoken.padZeros = flags.indexOf( '-' ) < 0; // NOTE: We use built-in `Array.prototype.indexOf` here instead of `@stdlib/assert/contains` in order to avoid circular dependencies.\n\t\t\t\t\tbreak;\n\t\t\t\tcase '#':\n\t\t\t\t\ttoken.alternate = true;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error( 'invalid flag: ' + flag );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( token.width === '*' ) {\n\t\t\t\ttoken.width = parseInt( arguments[ pos ], 10 );\n\t\t\t\tpos += 1;\n\t\t\t\tif ( isnan( token.width ) ) {\n\t\t\t\t\tthrow new TypeError( 'the argument for * width at position ' + pos + ' is not a number. Value: `' + token.width + '`.' );\n\t\t\t\t}\n\t\t\t\tif ( token.width < 0 ) {\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.width = -token.width;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( token.precision === '*' && token.hasPeriod ) {\n\t\t\t\ttoken.precision = parseInt( arguments[ pos ], 10 );\n\t\t\t\tpos += 1;\n\t\t\t\tif ( isnan( token.precision ) ) {\n\t\t\t\t\tthrow new TypeError( 'the argument for * precision at position ' + pos + ' is not a number. Value: `' + token.precision + '`.' );\n\t\t\t\t}\n\t\t\t\tif ( token.precision < 0 ) {\n\t\t\t\t\ttoken.precision = 1;\n\t\t\t\t\ttoken.hasPeriod = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\ttoken.arg = arguments[ pos ];\n\t\t\tswitch ( token.specifier ) {\n\t\t\tcase 'b':\n\t\t\tcase 'o':\n\t\t\tcase 'x':\n\t\t\tcase 'X':\n\t\t\tcase 'd':\n\t\t\tcase 'i':\n\t\t\tcase 'u':\n\t\t\t\t// Case: %b (binary), %o (octal), %x, %X (hexadecimal), %d, %i (decimal), %u (unsigned decimal)\n\t\t\t\tif ( token.hasPeriod ) {\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatInteger( token );\n\t\t\t\tbreak;\n\t\t\tcase 's':\n\t\t\t\t// Case: %s (string)\n\t\t\t\ttoken.maxWidth = ( token.hasPeriod ) ? token.precision : -1;\n\t\t\t\tbreak;\n\t\t\tcase 'c':\n\t\t\t\t// Case: %c (character)\n\t\t\t\tif ( !isnan( token.arg ) ) {\n\t\t\t\t\tnum = parseInt( token.arg, 10 );\n\t\t\t\t\tif ( num < 0 || num > 127 ) {\n\t\t\t\t\t\tthrow new Error( 'invalid character code. Value: ' + token.arg );\n\t\t\t\t\t}\n\t\t\t\t\ttoken.arg = ( isnan( num ) ) ?\n\t\t\t\t\t\tString( token.arg ) :\n\t\t\t\t\t\tfromCharCode( num );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'e':\n\t\t\tcase 'E':\n\t\t\tcase 'f':\n\t\t\tcase 'F':\n\t\t\tcase 'g':\n\t\t\tcase 'G':\n\t\t\t\t// Case: %e, %E (scientific notation), %f, %F (decimal floating point), %g, %G (uses the shorter of %e/E or %f/F)\n\t\t\t\tif ( !token.hasPeriod ) {\n\t\t\t\t\ttoken.precision = 6;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatDouble( token );\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error( 'invalid specifier: ' + token.specifier );\n\t\t\t}\n\t\t\t// Fit argument into field width...\n\t\t\tif ( token.maxWidth >= 0 && token.arg.length > token.maxWidth ) {\n\t\t\t\ttoken.arg = token.arg.substring( 0, token.maxWidth );\n\t\t\t}\n\t\t\tif ( token.padZeros ) {\n\t\t\t\ttoken.arg = zeroPad( token.arg, token.width || token.precision, token.padRight ); // eslint-disable-line max-len\n\t\t\t} else if ( token.width ) {\n\t\t\t\ttoken.arg = spacePad( token.arg, token.width, token.padRight );\n\t\t\t}\n\t\t\tout += token.arg || '';\n\t\t\tpos += 1;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = format;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Insert supplied variable values into a format string.\n*\n* @module @stdlib/string-format\n*\n* @example\n* var format = require( '@stdlib/string-format' );\n*\n* var out = format( '%s %s!', 'Hello', 'World' );\n* // returns 'Hello World!'\n*\n* out = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\n\n// MODULES //\n\nvar format = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = format;\n"],"names":["is_number","value","zeros","n","i","out","zero_pad","str","width","right","negative","pad","length","startsWithMinus","substr","isNumber","require$$0","zeroPad","require$$1","lowercase","String","prototype","toLowerCase","uppercase","toUpperCase","format_integer","token","base","specifier","arg","parseInt","isFinite","Error","toString","precision","padRight","sign","alternate","call","charAt","abs","Math","replace","RE_EXP_POS_DIGITS","RE_EXP_NEG_DIGITS","RE_ONLY_DIGITS","RE_DIGITS_BEFORE_EXP","RE_TRAILING_PERIOD_ZERO","RE_PERIOD_ZERO_EXP","RE_ZERO_BEFORE_EXP","RE","parse","match","mapping","flags","hasPeriod","spaces","formatInteger","formatDouble","digits","f","parseFloat","toExponential","toFixed","toPrecision","tokenize","content","tokens","prev","exec","slice","lastIndex","push","spacePad","require$$4","isString","fromCharCode","isnan","isNaN","main","format","flag","num","pos","j","TypeError","padZeros","indexOf","arguments","maxWidth","substring","lib"],"mappings":";;AA6CA,IAAAA,EAPA,SAAmBC,GAClB,MAA0B,iBAAVA,GCCjB,SAASC,EAAOC,GACf,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,EAqCR,IAAAC,EAtBA,SAAkBC,EAAKC,EAAOC,GAC7B,IAAIC,GAAW,EACXC,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,IAnCZ,SAA0BJ,GACzB,MAAoB,MAAbA,EAAK,GAqCPM,CAAiBN,KACrBG,GAAW,EACXH,EAAMA,EAAIO,OAAQ,IAEnBP,EAAM,EACLA,EAAML,EAAOS,GACbT,EAAOS,GAAQJ,EACXG,IACJH,EAAM,IAAMA,IAVLA,GC3CLQ,EAAWC,EACXC,EAAUC,EAGVC,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAuFjC,IAAAC,EA1EA,SAAwBC,GACvB,IAAIC,EACAtB,EACAD,EAEJ,OAASsB,EAAME,WACf,IAAK,IAEJD,EAAO,EACP,MACD,IAAK,IAEJA,EAAO,EACP,MACD,IAAK,IACL,IAAK,IAEJA,EAAO,GACP,MAID,QAECA,EAAO,GAKR,GAFAtB,EAAMqB,EAAMG,IACZzB,EAAI0B,SAAUzB,EAAK,KACb0B,SAAU3B,GAAM,CACrB,IAAMW,EAAUV,GACf,MAAM,IAAI2B,MAAO,2BAA6B3B,GAE/CD,EAAI,EAmCL,OAjCKA,EAAI,IAA2B,MAApBsB,EAAME,WAA8B,KAATD,KAC1CvB,EAAI,WAAaA,EAAI,GAEjBA,EAAI,GACRC,IAASD,GAAI6B,SAAUN,GAClBD,EAAMQ,YACV7B,EAAMY,EAASZ,EAAKqB,EAAMQ,UAAWR,EAAMS,WAE5C9B,EAAM,IAAMA,IAEZA,EAAMD,EAAE6B,SAAUN,GACZvB,GAAMsB,EAAMQ,UAENR,EAAMQ,YACjB7B,EAAMY,EAASZ,EAAKqB,EAAMQ,UAAWR,EAAMS,WAF3C9B,EAAM,GAIFqB,EAAMU,OACV/B,EAAMqB,EAAMU,KAAO/B,IAGP,KAATsB,IACCD,EAAMW,YACVhC,EAAM,KAAOA,GAEdA,EAAQqB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAMjC,GAChBc,EAAUmB,KAAMjC,IAEJ,IAATsB,GACCD,EAAMW,WAAiC,MAApBhC,EAAIkC,OAAQ,KACnClC,EAAM,IAAMA,GAGPA,GCtFJU,EAAWC,EAGXwB,EAAMC,KAAKD,IACXrB,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAC7BkB,EAAUtB,OAAOC,UAAUqB,QAK3BC,EAAoB,WACpBC,EAAoB,UACpBC,EAAiB,UACjBC,EAAuB,UACvBC,EAA0B,OAC1BC,EAAqB,QACrBC,EAAqB,gBAuEzB,ICxFIC,EAAK,6EAYT,SAASC,EAAOC,GACf,MAAO,CACNC,QAAaD,EAAO,GAAQtB,SAAUsB,EAAO,GAAK,SAAO,EACzDE,MAASF,EAAO,GAChB5C,MAAS4C,EAAO,GAChBG,UAA4B,MAAfH,EAAO,GACpBlB,UAAakB,EAAO,GACpBxB,UAAawB,EAAO,ICZtB,SAASI,EAAQrD,GAChB,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,ECMR,ICnBIoD,EAAgBzC,EAChB0C,EJ6BJ,SAAuBhC,GACtB,IAAIiC,EACAtD,EACAuD,EAAIC,WAAYnC,EAAMG,KAC1B,IAAME,SAAU6B,GAAM,CACrB,IAAM7C,EAAUW,EAAMG,KACrB,MAAM,IAAIG,MAAO,yCAA2C3B,GAG7DuD,EAAIlC,EAAMG,IAEX,OAASH,EAAME,WACf,IAAK,IACL,IAAK,IACJvB,EAAMuD,EAAEE,cAAepC,EAAMQ,WAC7B,MACD,IAAK,IACL,IAAK,IACJ7B,EAAMuD,EAAEG,QAASrC,EAAMQ,WACvB,MACD,IAAK,IACL,IAAK,IACCM,EAAKoB,GAAM,OACfD,EAASjC,EAAMQ,WACD,IACbyB,GAAU,GAEXtD,EAAMuD,EAAEE,cAAeH,IAEvBtD,EAAMuD,EAAEI,YAAatC,EAAMQ,WAEtBR,EAAMW,YACXhC,EAAMqC,EAAQJ,KAAMjC,EAAK4C,EAAoB,OAC7C5C,EAAMqC,EAAQJ,KAAMjC,EAAK2C,EAAoB,KAC7C3C,EAAMqC,EAAQJ,KAAMjC,EAAK0C,EAAyB,KAEnD,MACD,QACC,MAAM,IAAIf,MAAO,mCAAqCN,EAAME,WAc7D,OAZAvB,EAAMqC,EAAQJ,KAAMjC,EAAKsC,EAAmB,SAC5CtC,EAAMqC,EAAQJ,KAAMjC,EAAKuC,EAAmB,SACvClB,EAAMW,YACVhC,EAAMqC,EAAQJ,KAAMjC,EAAKwC,EAAgB,OACzCxC,EAAMqC,EAAQJ,KAAMjC,EAAKyC,EAAsB,SAE3Cc,GAAK,GAAKlC,EAAMU,OACpB/B,EAAMqB,EAAMU,KAAO/B,GAEpBA,EAAQqB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAMjC,GAChBc,EAAUmB,KAAMjC,II/Ed4D,EH+BJ,SAAmB1D,GAClB,IAAI2D,EACAC,EACAf,EACAgB,EAKJ,IAHAD,EAAS,GACTC,EAAO,EACPhB,EAAQF,EAAGmB,KAAM9D,GACT6C,IACPc,EAAU3D,EAAI+D,MAAOF,EAAMlB,EAAGqB,UAAYnB,EAAO,GAAIxC,SACxCA,QACZuD,EAAOK,KAAMN,GAEdC,EAAOK,KAAMrB,EAAOC,IACpBgB,EAAOlB,EAAGqB,UACVnB,EAAQF,EAAGmB,KAAM9D,GAMlB,OAJA2D,EAAU3D,EAAI+D,MAAOF,IACRxD,QACZuD,EAAOK,KAAMN,GAEPC,GGpDJM,EFyBJ,SAAmBlE,EAAKC,EAAOC,GAC9B,IAAIE,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,EACHJ,EAERA,EAAM,EACLA,EAAMiD,EAAQ7C,GACd6C,EAAQ7C,GAAQJ,GE/BdU,EAAUyD,EACVC,EDOJ,SAAmB1E,GAClB,MAA0B,iBAAVA,GCHb2E,EAAexD,OAAOwD,aACtBC,EAAQC,MA8JZ,IAAAC,EAxIA,SAASC,EAAQzE,GAChB,IAAI4D,EACAb,EACA5B,EACAuD,EACAC,EACA7E,EACA8E,EACA/E,EACAgF,EAEJ,IAAMT,EAAUpE,GACf,MAAM,IAAI8E,UAAWL,EAAQ,kEAAmEzE,IAKjG,IAHA4D,EAASF,EAAU1D,GACnBF,EAAM,GACN8E,EAAM,EACA/E,EAAI,EAAGA,EAAI+D,EAAOvD,OAAQR,IAE/B,GADAsB,EAAQyC,EAAQ/D,GACXuE,EAAUjD,GACdrB,GAAOqB,MACD,CAKN,IAJKA,EAAM2B,UACV8B,EAAMzD,EAAM2B,SAEbC,EAAQ5B,EAAM4B,MACR8B,EAAI,EAAGA,EAAI9B,EAAM1C,OAAQwE,IAE9B,OADAH,EAAO3B,EAAMf,OAAQ6C,IAErB,IAAK,IACJ1D,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMS,UAAW,EACjBT,EAAM4D,UAAW,EACjB,MACD,IAAK,IACJ5D,EAAM4D,SAAWhC,EAAMiC,QAAS,KAAQ,EACxC,MACD,IAAK,IACJ7D,EAAMW,WAAY,EAClB,MACD,QACC,MAAM,IAAIL,MAAO,iBAAmBiD,GAGtC,GAAqB,MAAhBvD,EAAMlB,MAAgB,CAG1B,GAFAkB,EAAMlB,MAAQsB,SAAU0D,UAAWL,GAAO,IAC1CA,GAAO,EACFN,EAAOnD,EAAMlB,OACjB,MAAM,IAAI6E,UAAW,wCAA0CF,EAAM,6BAA+BzD,EAAMlB,MAAQ,MAE9GkB,EAAMlB,MAAQ,IAClBkB,EAAMS,UAAW,EACjBT,EAAMlB,OAASkB,EAAMlB,OAGvB,GAAyB,MAApBkB,EAAMQ,WAAqBR,EAAM6B,UAAY,CAGjD,GAFA7B,EAAMQ,UAAYJ,SAAU0D,UAAWL,GAAO,IAC9CA,GAAO,EACFN,EAAOnD,EAAMQ,WACjB,MAAM,IAAImD,UAAW,4CAA8CF,EAAM,6BAA+BzD,EAAMQ,UAAY,MAEtHR,EAAMQ,UAAY,IACtBR,EAAMQ,UAAY,EAClBR,EAAM6B,WAAY,GAIpB,OADA7B,EAAMG,IAAM2D,UAAWL,GACdzD,EAAME,WACf,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAECF,EAAM6B,YACV7B,EAAM4D,UAAW,GAElB5D,EAAMG,IAAM4B,EAAe/B,GAC3B,MACD,IAAK,IAEJA,EAAM+D,SAAa/D,EAAe,UAAKA,EAAMQ,WAAa,EAC1D,MACD,IAAK,IAEJ,IAAM2C,EAAOnD,EAAMG,KAAQ,CAE1B,IADAqD,EAAMpD,SAAUJ,EAAMG,IAAK,KAChB,GAAKqD,EAAM,IACrB,MAAM,IAAIlD,MAAO,kCAAoCN,EAAMG,KAE5DH,EAAMG,IAAQgD,EAAOK,GACpB9D,OAAQM,EAAMG,KACd+C,EAAcM,GAEhB,MACD,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEExD,EAAM6B,YACX7B,EAAMQ,UAAY,GAEnBR,EAAMG,IAAM6B,EAAchC,GAC1B,MACD,QACC,MAAM,IAAIM,MAAO,sBAAwBN,EAAME,WAG3CF,EAAM+D,UAAY,GAAK/D,EAAMG,IAAIjB,OAASc,EAAM+D,WACpD/D,EAAMG,IAAMH,EAAMG,IAAI6D,UAAW,EAAGhE,EAAM+D,WAEtC/D,EAAM4D,SACV5D,EAAMG,IAAMZ,EAASS,EAAMG,IAAKH,EAAMlB,OAASkB,EAAMQ,UAAWR,EAAMS,UAC3DT,EAAMlB,QACjBkB,EAAMG,IAAM4C,EAAU/C,EAAMG,IAAKH,EAAMlB,MAAOkB,EAAMS,WAErD9B,GAAOqB,EAAMG,KAAO,GACpBsD,GAAO,EAGT,OAAO9E,GC/IRsF,EALa3E"} \ No newline at end of file diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3948783 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From 77fc9fdefb3a5030ed38534789ee41f6147818d2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Jun 2022 00:55:19 +0000 Subject: [PATCH 002/150] Auto-generated commit --- .editorconfig | 181 ---- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 -- .github/workflows/bundle.yml | 504 ---------- .github/workflows/cancel.yml | 56 -- .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 -- .github/workflows/npm_downloads.yml | 108 -- .github/workflows/productionize.yml | 160 --- .github/workflows/publish.yml | 157 --- .github/workflows/test.yml | 92 -- .github/workflows/test_bundles.yml | 180 ---- .github/workflows/test_coverage.yml | 123 --- .github/workflows/test_install.yml | 83 -- .gitignore | 178 ---- .npmignore | 227 ----- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---------- README.md | 33 +- benchmark/benchmark.js | 73 -- branches.md | 53 - docs/repl.txt | 31 - docs/types/index.d.ts | 42 - docs/types/test.ts | 45 - examples/index.js | 41 - index.mjs | 2 +- index.mjs.map | 2 +- lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 -- package.json | 58 +- stats.html | 2 +- test/test.js | 1092 --------------------- 39 files changed, 19 insertions(+), 4439 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/bundle.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 5e5b58a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-01T00:31:58.583Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/bundle.yml b/.github/workflows/bundle.yml deleted file mode 100644 index 10f472a..0000000 --- a/.github/workflows/bundle.yml +++ /dev/null @@ -1,504 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: bundle - -# Workflow triggers: -on: - # Allow workflow to be manually run: - workflow_dispatch: - - # Run workflow upon completion of `productionize` workflow: - workflow_run: - workflows: ["productionize"] - types: [completed] - -# Workflow jobs: -jobs: - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Checkout production branch: - - name: 'Checkout production branch' - run: | - git fetch --all - git checkout -b production origin/production - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, checkout branch and rebase on `main`: - - name: 'If `deno` exists, checkout branch and rebase on `main`' - if: steps.deno-branch-exists.outputs.remote-exists - continue-on-error: true - run: | - git checkout -b deno origin/deno - git rebase main -s recursive -X ours - while [ $? -ne 0 ]; do - git rebase --skip - done - - # If `deno` does not exist, checkout `main` and create `deno` branch: - - name: 'If `deno` does not exist, checkout `main` and create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout main - git checkout -b deno - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno --force - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Checkout production branch: - - name: 'Checkout production branch' - run: | - git fetch --all - git checkout -b production origin/production - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9823e92..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a117f0b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -click B href "https://github.com/stdlib-js/string-format/tree/main" -click C href "https://github.com/stdlib-js/string-format/tree/production" -click D href "https://github.com/stdlib-js/string-format/tree/esm" -click E href "https://github.com/stdlib-js/string-format/tree/deno" -click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 7ae7765..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b2ceb17..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The function does not compile if provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/index.mjs b/index.mjs index f5d68cf..5ba61be 100644 --- a/index.mjs +++ b/index.mjs @@ -1,4 +1,4 @@ // Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 /// -var e=function(e){return"number"==typeof e};function r(e){var r,a="";for(r=0;r0&&(r-=1),a=i.toExponential(r)):a=i.toPrecision(e.precision),e.alternate||(a=d.call(a,m,"$1e"),a=d.call(a,v,"e"),a=d.call(a,b,""));break;default:throw new Error("invalid double notation. Value: "+e.specifier)}return a=d.call(a,h,"e+0$1"),a=d.call(a,f,"e-0$1"),e.alternate&&(a=d.call(a,u,"$1."),a=d.call(a,w,"$1.e")),i>=0&&e.sign&&(a=e.sign+a),a=e.specifier===g.call(e.specifier)?g.call(a):l.call(a)},S=function(e){var r,a,i,t;for(a=[],t=0,i=x.exec(e);i;)(r=e.slice(t,x.lastIndex-i[0].length)).length&&a.push(r),a.push(k(i)),t=x.lastIndex,i=x.exec(e);return(r=e.slice(t)).length&&a.push(r),a},F=function(e,r,a){var i=r-e.length;return i<0?e:e=a?e+E(i):E(i)+e},I=a,P=function(e){return"string"==typeof e},V=String.fromCharCode,C=isNaN;var R=function e(r){var a,i,t,n,s,o,c,p,l;if(!P(r))throw new TypeError(e("invalid argument. First argument must be a string. Value: `%s`.",r));for(a=S(r),o="",c=1,p=0;p127)throw new Error("invalid character code. Value: "+t.arg);t.arg=C(s)?String(t.arg):V(s)}break;case"e":case"E":case"f":case"F":case"g":case"G":t.hasPeriod||(t.precision=6),t.arg=$(t);break;default:throw new Error("invalid specifier: "+t.specifier)}t.maxWidth>=0&&t.arg.length>t.maxWidth&&(t.arg=t.arg.substring(0,t.maxWidth)),t.padZeros?t.arg=I(t.arg,t.width||t.precision,t.padRight):t.width&&(t.arg=F(t.arg,t.width,t.padRight)),o+=t.arg||"",c+=1}return o},Z=R;export{Z as default}; +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@esm/index.mjs";var e=t,n=r,s=function(t){return"string"==typeof t};var i=function t(r){var i,o,a;if(!s(r))throw new TypeError(t("0hB3R",r));for(i=n(r),(o=new Array(arguments.length))[0]=i,a=1;a 0 ) {\n\t\t\t\tdigits -= 1;\n\t\t\t}\n\t\t\tout = f.toExponential( digits );\n\t\t} else {\n\t\t\tout = f.toPrecision( token.precision );\n\t\t}\n\t\tif ( !token.alternate ) {\n\t\t\tout = replace.call( out, RE_ZERO_BEFORE_EXP, '$1e' );\n\t\t\tout = replace.call( out, RE_PERIOD_ZERO_EXP, 'e');\n\t\t\tout = replace.call( out, RE_TRAILING_PERIOD_ZERO, '' );\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tthrow new Error( 'invalid double notation. Value: ' + token.specifier );\n\t}\n\tout = replace.call( out, RE_EXP_POS_DIGITS, 'e+0$1' );\n\tout = replace.call( out, RE_EXP_NEG_DIGITS, 'e-0$1' );\n\tif ( token.alternate ) {\n\t\tout = replace.call( out, RE_ONLY_DIGITS, '$1.' );\n\t\tout = replace.call( out, RE_DIGITS_BEFORE_EXP, '$1.e' );\n\t}\n\tif ( f >= 0 && token.sign ) {\n\t\tout = token.sign + out;\n\t}\n\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\tuppercase.call( out ) :\n\t\tlowercase.call( out );\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = formatDouble;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar RE = /%(?:([1-9]\\d*)\\$)?([0 +\\-#]*)(\\*|\\d+)?(?:(\\.)(\\*|\\d+)?)?[hlL]?([%A-Za-z])/g;\n\n\n// FUNCTIONS //\n\n/**\n* Parses a delimiter.\n*\n* @private\n* @param {Array} match - regular expression match\n* @returns {Object} delimiter token object\n*/\nfunction parse( match ) {\n\treturn {\n\t\t'mapping': ( match[ 1 ] ) ? parseInt( match[ 1 ], 10 ) : void 0,\n\t\t'flags': match[ 2 ],\n\t\t'width': match[ 3 ],\n\t\t'hasPeriod': match[ 4 ] === '.',\n\t\t'precision': match[ 5 ],\n\t\t'specifier': match[ 6 ]\n\t};\n}\n\n\n// MAIN //\n\n/**\n* Tokenizes a string.\n*\n* @private\n* @param {string} str - input string\n* @returns {Array} tokens\n*/\nfunction tokenize( str ) {\n\tvar content;\n\tvar tokens;\n\tvar match;\n\tvar prev;\n\n\ttokens = [];\n\tprev = 0;\n\tmatch = RE.exec( str );\n\twhile ( match ) {\n\t\tcontent = str.slice( prev, RE.lastIndex - match[ 0 ].length );\n\t\tif ( content.length ) {\n\t\t\ttokens.push( content );\n\t\t}\n\t\ttokens.push( parse( match ) );\n\t\tprev = RE.lastIndex;\n\t\tmatch = RE.exec( str );\n\t}\n\tcontent = str.slice( prev );\n\tif ( content.length ) {\n\t\ttokens.push( content );\n\t}\n\treturn tokens;\n}\n\n\n// EXPORTS //\n\nmodule.exports = tokenize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Returns `n` spaces.\n*\n* @private\n* @param {number} n - number of spaces\n* @returns {string} string of spaces\n*/\nfunction spaces( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += ' ';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with spaces to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction spacePad( str, width, right ) {\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tstr = ( right ) ?\n\t\tstr + spaces( pad ) :\n\t\tspaces( pad ) + str;\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = spacePad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar formatInteger = require( './format_integer.js' );\nvar formatDouble = require( './format_double.js' );\nvar tokenize = require( './tokenize.js' );\nvar spacePad = require( './space_pad.js' );\nvar zeroPad = require( './zero_pad.js' );\nvar isString = require( './is_string.js' );\n\n\n// VARIABLES //\n\nvar fromCharCode = String.fromCharCode;\nvar isnan = isNaN; // NOTE: We use the global `isNaN` function here instead of `@stdlib/math/base/assert/is-nan` to avoid circular dependencies.\n\n\n// MAIN //\n\n/**\n* Inserts supplied variable values into a format string.\n*\n* @param {string} str - input string\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be a string\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var str = format( 'Hello %s!', 'world' );\n* // returns 'Hello world!'\n*\n* @example\n* var str = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\nfunction format( str ) {\n\tvar tokens;\n\tvar flags;\n\tvar token;\n\tvar flag;\n\tvar num;\n\tvar out;\n\tvar pos;\n\tvar i;\n\tvar j;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\ttokens = tokenize( str );\n\tout = '';\n\tpos = 1;\n\tfor ( i = 0; i < tokens.length; i++ ) {\n\t\ttoken = tokens[ i ];\n\t\tif ( isString( token ) ) {\n\t\t\tout += token;\n\t\t} else {\n\t\t\tif ( token.mapping ) {\n\t\t\t\tpos = token.mapping;\n\t\t\t}\n\t\t\tflags = token.flags;\n\t\t\tfor ( j = 0; j < flags.length; j++ ) {\n\t\t\t\tflag = flags.charAt( j );\n\t\t\t\tswitch ( flag ) {\n\t\t\t\tcase ' ':\n\t\t\t\t\ttoken.sign = ' ';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '+':\n\t\t\t\t\ttoken.sign = '+';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '-':\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '0':\n\t\t\t\t\ttoken.padZeros = flags.indexOf( '-' ) < 0; // NOTE: We use built-in `Array.prototype.indexOf` here instead of `@stdlib/assert/contains` in order to avoid circular dependencies.\n\t\t\t\t\tbreak;\n\t\t\t\tcase '#':\n\t\t\t\t\ttoken.alternate = true;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error( 'invalid flag: ' + flag );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( token.width === '*' ) {\n\t\t\t\ttoken.width = parseInt( arguments[ pos ], 10 );\n\t\t\t\tpos += 1;\n\t\t\t\tif ( isnan( token.width ) ) {\n\t\t\t\t\tthrow new TypeError( 'the argument for * width at position ' + pos + ' is not a number. Value: `' + token.width + '`.' );\n\t\t\t\t}\n\t\t\t\tif ( token.width < 0 ) {\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.width = -token.width;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( token.precision === '*' && token.hasPeriod ) {\n\t\t\t\ttoken.precision = parseInt( arguments[ pos ], 10 );\n\t\t\t\tpos += 1;\n\t\t\t\tif ( isnan( token.precision ) ) {\n\t\t\t\t\tthrow new TypeError( 'the argument for * precision at position ' + pos + ' is not a number. Value: `' + token.precision + '`.' );\n\t\t\t\t}\n\t\t\t\tif ( token.precision < 0 ) {\n\t\t\t\t\ttoken.precision = 1;\n\t\t\t\t\ttoken.hasPeriod = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\ttoken.arg = arguments[ pos ];\n\t\t\tswitch ( token.specifier ) {\n\t\t\tcase 'b':\n\t\t\tcase 'o':\n\t\t\tcase 'x':\n\t\t\tcase 'X':\n\t\t\tcase 'd':\n\t\t\tcase 'i':\n\t\t\tcase 'u':\n\t\t\t\t// Case: %b (binary), %o (octal), %x, %X (hexadecimal), %d, %i (decimal), %u (unsigned decimal)\n\t\t\t\tif ( token.hasPeriod ) {\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatInteger( token );\n\t\t\t\tbreak;\n\t\t\tcase 's':\n\t\t\t\t// Case: %s (string)\n\t\t\t\ttoken.maxWidth = ( token.hasPeriod ) ? token.precision : -1;\n\t\t\t\tbreak;\n\t\t\tcase 'c':\n\t\t\t\t// Case: %c (character)\n\t\t\t\tif ( !isnan( token.arg ) ) {\n\t\t\t\t\tnum = parseInt( token.arg, 10 );\n\t\t\t\t\tif ( num < 0 || num > 127 ) {\n\t\t\t\t\t\tthrow new Error( 'invalid character code. Value: ' + token.arg );\n\t\t\t\t\t}\n\t\t\t\t\ttoken.arg = ( isnan( num ) ) ?\n\t\t\t\t\t\tString( token.arg ) :\n\t\t\t\t\t\tfromCharCode( num );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'e':\n\t\t\tcase 'E':\n\t\t\tcase 'f':\n\t\t\tcase 'F':\n\t\t\tcase 'g':\n\t\t\tcase 'G':\n\t\t\t\t// Case: %e, %E (scientific notation), %f, %F (decimal floating point), %g, %G (uses the shorter of %e/E or %f/F)\n\t\t\t\tif ( !token.hasPeriod ) {\n\t\t\t\t\ttoken.precision = 6;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatDouble( token );\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error( 'invalid specifier: ' + token.specifier );\n\t\t\t}\n\t\t\t// Fit argument into field width...\n\t\t\tif ( token.maxWidth >= 0 && token.arg.length > token.maxWidth ) {\n\t\t\t\ttoken.arg = token.arg.substring( 0, token.maxWidth );\n\t\t\t}\n\t\t\tif ( token.padZeros ) {\n\t\t\t\ttoken.arg = zeroPad( token.arg, token.width || token.precision, token.padRight ); // eslint-disable-line max-len\n\t\t\t} else if ( token.width ) {\n\t\t\t\ttoken.arg = spacePad( token.arg, token.width, token.padRight );\n\t\t\t}\n\t\t\tout += token.arg || '';\n\t\t\tpos += 1;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = format;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Insert supplied variable values into a format string.\n*\n* @module @stdlib/string-format\n*\n* @example\n* var format = require( '@stdlib/string-format' );\n*\n* var out = format( '%s %s!', 'Hello', 'World' );\n* // returns 'Hello World!'\n*\n* out = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\n\n// MODULES //\n\nvar format = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = format;\n"],"names":["is_number","value","zeros","n","i","out","zero_pad","str","width","right","negative","pad","length","startsWithMinus","substr","isNumber","require$$0","zeroPad","require$$1","lowercase","String","prototype","toLowerCase","uppercase","toUpperCase","format_integer","token","base","specifier","arg","parseInt","isFinite","Error","toString","precision","padRight","sign","alternate","call","charAt","abs","Math","replace","RE_EXP_POS_DIGITS","RE_EXP_NEG_DIGITS","RE_ONLY_DIGITS","RE_DIGITS_BEFORE_EXP","RE_TRAILING_PERIOD_ZERO","RE_PERIOD_ZERO_EXP","RE_ZERO_BEFORE_EXP","RE","parse","match","mapping","flags","hasPeriod","spaces","formatInteger","formatDouble","digits","f","parseFloat","toExponential","toFixed","toPrecision","tokenize","content","tokens","prev","exec","slice","lastIndex","push","spacePad","require$$4","isString","fromCharCode","isnan","isNaN","main","format","flag","num","pos","j","TypeError","padZeros","indexOf","arguments","maxWidth","substring","lib"],"mappings":";;AA6CA,IAAAA,EAPA,SAAmBC,GAClB,MAA0B,iBAAVA,GCCjB,SAASC,EAAOC,GACf,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,EAqCR,IAAAC,EAtBA,SAAkBC,EAAKC,EAAOC,GAC7B,IAAIC,GAAW,EACXC,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,IAnCZ,SAA0BJ,GACzB,MAAoB,MAAbA,EAAK,GAqCPM,CAAiBN,KACrBG,GAAW,EACXH,EAAMA,EAAIO,OAAQ,IAEnBP,EAAM,EACLA,EAAML,EAAOS,GACbT,EAAOS,GAAQJ,EACXG,IACJH,EAAM,IAAMA,IAVLA,GC3CLQ,EAAWC,EACXC,EAAUC,EAGVC,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAuFjC,IAAAC,EA1EA,SAAwBC,GACvB,IAAIC,EACAtB,EACAD,EAEJ,OAASsB,EAAME,WACf,IAAK,IAEJD,EAAO,EACP,MACD,IAAK,IAEJA,EAAO,EACP,MACD,IAAK,IACL,IAAK,IAEJA,EAAO,GACP,MAID,QAECA,EAAO,GAKR,GAFAtB,EAAMqB,EAAMG,IACZzB,EAAI0B,SAAUzB,EAAK,KACb0B,SAAU3B,GAAM,CACrB,IAAMW,EAAUV,GACf,MAAM,IAAI2B,MAAO,2BAA6B3B,GAE/CD,EAAI,EAmCL,OAjCKA,EAAI,IAA2B,MAApBsB,EAAME,WAA8B,KAATD,KAC1CvB,EAAI,WAAaA,EAAI,GAEjBA,EAAI,GACRC,IAASD,GAAI6B,SAAUN,GAClBD,EAAMQ,YACV7B,EAAMY,EAASZ,EAAKqB,EAAMQ,UAAWR,EAAMS,WAE5C9B,EAAM,IAAMA,IAEZA,EAAMD,EAAE6B,SAAUN,GACZvB,GAAMsB,EAAMQ,UAENR,EAAMQ,YACjB7B,EAAMY,EAASZ,EAAKqB,EAAMQ,UAAWR,EAAMS,WAF3C9B,EAAM,GAIFqB,EAAMU,OACV/B,EAAMqB,EAAMU,KAAO/B,IAGP,KAATsB,IACCD,EAAMW,YACVhC,EAAM,KAAOA,GAEdA,EAAQqB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAMjC,GAChBc,EAAUmB,KAAMjC,IAEJ,IAATsB,GACCD,EAAMW,WAAiC,MAApBhC,EAAIkC,OAAQ,KACnClC,EAAM,IAAMA,GAGPA,GCtFJU,EAAWC,EAGXwB,EAAMC,KAAKD,IACXrB,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAC7BkB,EAAUtB,OAAOC,UAAUqB,QAK3BC,EAAoB,WACpBC,EAAoB,UACpBC,EAAiB,UACjBC,EAAuB,UACvBC,EAA0B,OAC1BC,EAAqB,QACrBC,EAAqB,gBAuEzB,ICxFIC,EAAK,6EAYT,SAASC,EAAOC,GACf,MAAO,CACNC,QAAaD,EAAO,GAAQtB,SAAUsB,EAAO,GAAK,SAAO,EACzDE,MAASF,EAAO,GAChB5C,MAAS4C,EAAO,GAChBG,UAA4B,MAAfH,EAAO,GACpBlB,UAAakB,EAAO,GACpBxB,UAAawB,EAAO,ICZtB,SAASI,EAAQrD,GAChB,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,ECMR,ICnBIoD,EAAgBzC,EAChB0C,EJ6BJ,SAAuBhC,GACtB,IAAIiC,EACAtD,EACAuD,EAAIC,WAAYnC,EAAMG,KAC1B,IAAME,SAAU6B,GAAM,CACrB,IAAM7C,EAAUW,EAAMG,KACrB,MAAM,IAAIG,MAAO,yCAA2C3B,GAG7DuD,EAAIlC,EAAMG,IAEX,OAASH,EAAME,WACf,IAAK,IACL,IAAK,IACJvB,EAAMuD,EAAEE,cAAepC,EAAMQ,WAC7B,MACD,IAAK,IACL,IAAK,IACJ7B,EAAMuD,EAAEG,QAASrC,EAAMQ,WACvB,MACD,IAAK,IACL,IAAK,IACCM,EAAKoB,GAAM,OACfD,EAASjC,EAAMQ,WACD,IACbyB,GAAU,GAEXtD,EAAMuD,EAAEE,cAAeH,IAEvBtD,EAAMuD,EAAEI,YAAatC,EAAMQ,WAEtBR,EAAMW,YACXhC,EAAMqC,EAAQJ,KAAMjC,EAAK4C,EAAoB,OAC7C5C,EAAMqC,EAAQJ,KAAMjC,EAAK2C,EAAoB,KAC7C3C,EAAMqC,EAAQJ,KAAMjC,EAAK0C,EAAyB,KAEnD,MACD,QACC,MAAM,IAAIf,MAAO,mCAAqCN,EAAME,WAc7D,OAZAvB,EAAMqC,EAAQJ,KAAMjC,EAAKsC,EAAmB,SAC5CtC,EAAMqC,EAAQJ,KAAMjC,EAAKuC,EAAmB,SACvClB,EAAMW,YACVhC,EAAMqC,EAAQJ,KAAMjC,EAAKwC,EAAgB,OACzCxC,EAAMqC,EAAQJ,KAAMjC,EAAKyC,EAAsB,SAE3Cc,GAAK,GAAKlC,EAAMU,OACpB/B,EAAMqB,EAAMU,KAAO/B,GAEpBA,EAAQqB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAMjC,GAChBc,EAAUmB,KAAMjC,II/Ed4D,EH+BJ,SAAmB1D,GAClB,IAAI2D,EACAC,EACAf,EACAgB,EAKJ,IAHAD,EAAS,GACTC,EAAO,EACPhB,EAAQF,EAAGmB,KAAM9D,GACT6C,IACPc,EAAU3D,EAAI+D,MAAOF,EAAMlB,EAAGqB,UAAYnB,EAAO,GAAIxC,SACxCA,QACZuD,EAAOK,KAAMN,GAEdC,EAAOK,KAAMrB,EAAOC,IACpBgB,EAAOlB,EAAGqB,UACVnB,EAAQF,EAAGmB,KAAM9D,GAMlB,OAJA2D,EAAU3D,EAAI+D,MAAOF,IACRxD,QACZuD,EAAOK,KAAMN,GAEPC,GGpDJM,EFyBJ,SAAmBlE,EAAKC,EAAOC,GAC9B,IAAIE,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,EACHJ,EAERA,EAAM,EACLA,EAAMiD,EAAQ7C,GACd6C,EAAQ7C,GAAQJ,GE/BdU,EAAUyD,EACVC,EDOJ,SAAmB1E,GAClB,MAA0B,iBAAVA,GCHb2E,EAAexD,OAAOwD,aACtBC,EAAQC,MA8JZ,IAAAC,EAxIA,SAASC,EAAQzE,GAChB,IAAI4D,EACAb,EACA5B,EACAuD,EACAC,EACA7E,EACA8E,EACA/E,EACAgF,EAEJ,IAAMT,EAAUpE,GACf,MAAM,IAAI8E,UAAWL,EAAQ,kEAAmEzE,IAKjG,IAHA4D,EAASF,EAAU1D,GACnBF,EAAM,GACN8E,EAAM,EACA/E,EAAI,EAAGA,EAAI+D,EAAOvD,OAAQR,IAE/B,GADAsB,EAAQyC,EAAQ/D,GACXuE,EAAUjD,GACdrB,GAAOqB,MACD,CAKN,IAJKA,EAAM2B,UACV8B,EAAMzD,EAAM2B,SAEbC,EAAQ5B,EAAM4B,MACR8B,EAAI,EAAGA,EAAI9B,EAAM1C,OAAQwE,IAE9B,OADAH,EAAO3B,EAAMf,OAAQ6C,IAErB,IAAK,IACJ1D,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMS,UAAW,EACjBT,EAAM4D,UAAW,EACjB,MACD,IAAK,IACJ5D,EAAM4D,SAAWhC,EAAMiC,QAAS,KAAQ,EACxC,MACD,IAAK,IACJ7D,EAAMW,WAAY,EAClB,MACD,QACC,MAAM,IAAIL,MAAO,iBAAmBiD,GAGtC,GAAqB,MAAhBvD,EAAMlB,MAAgB,CAG1B,GAFAkB,EAAMlB,MAAQsB,SAAU0D,UAAWL,GAAO,IAC1CA,GAAO,EACFN,EAAOnD,EAAMlB,OACjB,MAAM,IAAI6E,UAAW,wCAA0CF,EAAM,6BAA+BzD,EAAMlB,MAAQ,MAE9GkB,EAAMlB,MAAQ,IAClBkB,EAAMS,UAAW,EACjBT,EAAMlB,OAASkB,EAAMlB,OAGvB,GAAyB,MAApBkB,EAAMQ,WAAqBR,EAAM6B,UAAY,CAGjD,GAFA7B,EAAMQ,UAAYJ,SAAU0D,UAAWL,GAAO,IAC9CA,GAAO,EACFN,EAAOnD,EAAMQ,WACjB,MAAM,IAAImD,UAAW,4CAA8CF,EAAM,6BAA+BzD,EAAMQ,UAAY,MAEtHR,EAAMQ,UAAY,IACtBR,EAAMQ,UAAY,EAClBR,EAAM6B,WAAY,GAIpB,OADA7B,EAAMG,IAAM2D,UAAWL,GACdzD,EAAME,WACf,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAECF,EAAM6B,YACV7B,EAAM4D,UAAW,GAElB5D,EAAMG,IAAM4B,EAAe/B,GAC3B,MACD,IAAK,IAEJA,EAAM+D,SAAa/D,EAAe,UAAKA,EAAMQ,WAAa,EAC1D,MACD,IAAK,IAEJ,IAAM2C,EAAOnD,EAAMG,KAAQ,CAE1B,IADAqD,EAAMpD,SAAUJ,EAAMG,IAAK,KAChB,GAAKqD,EAAM,IACrB,MAAM,IAAIlD,MAAO,kCAAoCN,EAAMG,KAE5DH,EAAMG,IAAQgD,EAAOK,GACpB9D,OAAQM,EAAMG,KACd+C,EAAcM,GAEhB,MACD,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEExD,EAAM6B,YACX7B,EAAMQ,UAAY,GAEnBR,EAAMG,IAAM6B,EAAchC,GAC1B,MACD,QACC,MAAM,IAAIM,MAAO,sBAAwBN,EAAME,WAG3CF,EAAM+D,UAAY,GAAK/D,EAAMG,IAAIjB,OAASc,EAAM+D,WACpD/D,EAAMG,IAAMH,EAAMG,IAAI6D,UAAW,EAAGhE,EAAM+D,WAEtC/D,EAAM4D,SACV5D,EAAMG,IAAMZ,EAASS,EAAMG,IAAKH,EAAMlB,OAASkB,EAAMQ,UAAWR,EAAMS,UAC3DT,EAAMlB,QACjBkB,EAAMG,IAAM4C,EAAU/C,EAAMG,IAAKH,EAAMlB,MAAOkB,EAAMS,WAErD9B,GAAOqB,EAAMG,KAAO,GACpBsD,GAAO,EAGT,OAAO9E,GC/IRsF,EALa3E"} \ No newline at end of file +{"version":3,"file":"index.mjs","sources":["../lib/is_string.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar interpolate = require( '@stdlib/string-base-format-interpolate' );\nvar tokenize = require( '@stdlib/string-base-format-tokenize' );\nvar isString = require( './is_string.js' );\n\n\n// MAIN //\n\n/**\n* Inserts supplied variable values into a format string.\n*\n* @param {string} str - input string\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be a string\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var str = format( 'Hello %s!', 'world' );\n* // returns 'Hello world!'\n*\n* @example\n* var str = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\nfunction format( str ) {\n\tvar tokens;\n\tvar args;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hB3R', str ) );\n\t}\n\ttokens = tokenize( str );\n\targs = new Array( arguments.length );\n\targs[ 0 ] = tokens;\n\tfor ( i = 1; i < args.length; i++ ) {\n\t\targs[ i ] = arguments[ i ];\n\t}\n\treturn interpolate.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = format;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Insert supplied variable values into a format string.\n*\n* @module @stdlib/string-format\n*\n* @example\n* var format = require( '@stdlib/string-format' );\n*\n* var out = format( '%s %s!', 'Hello', 'World' );\n* // returns 'Hello World!'\n*\n* out = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\n\n// MODULES //\n\nvar format = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = format;\n"],"names":["interpolate","require$$0","tokenize","require$$1","isString","value","main","format","str","tokens","args","i","TypeError","Array","arguments","length","apply","lib"],"mappings":";;iMAyCA,ICnBIA,EAAcC,EACdC,EAAWC,EACXC,EDUJ,SAAmBC,GAClB,MAA0B,iBAAVA,GC+BjB,IAAAC,EApBA,SAASC,EAAQC,GAChB,IAAIC,EACAC,EACAC,EAEJ,IAAMP,EAAUI,GACf,MAAM,IAAII,UAAWL,EAAQ,QAASC,IAKvC,IAHAC,EAASP,EAAUM,IACnBE,EAAO,IAAIG,MAAOC,UAAUC,SACtB,GAAMN,EACNE,EAAI,EAAGA,EAAID,EAAKK,OAAQJ,IAC7BD,EAAMC,GAAMG,UAAWH,GAExB,OAAOX,EAAYgB,MAAO,KAAMN,IClBjCO,EALahB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 3229c04..0000000 --- a/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Insert supplied variable values into a format string. -* -* @module @stdlib/string-format -* -* @example -* var format = require( '@stdlib/string-format' ); -* -* var out = format( '%s %s!', 'Hello', 'World' ); -* // returns 'Hello World!' -* -* out = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ - -// MODULES // - -var format = require( './main.js' ); - - -// EXPORTS // - -module.exports = format; diff --git a/lib/is_string.js b/lib/is_string.js deleted file mode 100644 index 8f1fd29..0000000 --- a/lib/is_string.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Tests if a value is a string primitive. -* -* @param {*} value - value to test -* @returns {boolean} boolean indicating if a value is a string primitive -* -* @example -* var bool = isString( 'beep' ); -* // returns true -* -* @example -* var bool = isString( new String( 'beep' ) ); -* // returns false -*/ -function isString( value ) { - return ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies. -} - - -// EXPORTS // - -module.exports = isString; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c08c83c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var interpolate = require( '@stdlib/string-base-format-interpolate' ); -var tokenize = require( '@stdlib/string-base-format-tokenize' ); -var isString = require( './is_string.js' ); - - -// MAIN // - -/** -* Inserts supplied variable values into a format string. -* -* @param {string} str - input string -* @param {Array} ...args - variable values -* @throws {TypeError} first argument must be a string -* @throws {Error} invalid flags -* @returns {string} formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -function format( str ) { - var tokens; - var args; - var i; - - if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); - } - tokens = tokenize( str ); - args = new Array( arguments.length ); - args[ 0 ] = tokens; - for ( i = 1; i < args.length; i++ ) { - args[ i ] = arguments[ i ]; - } - return interpolate.apply( null, args ); -} - - -// EXPORTS // - -module.exports = format; diff --git a/package.json b/package.json index 4e14c75..68ef433 100644 --- a/package.json +++ b/package.json @@ -1,33 +1,10 @@ { - "name": "@stdlib/string-format", + "name": "@stdlib/error-tools-fmtprodmsg", "version": "0.0.1", "description": "Insert supplied variable values into a format string.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,35 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string-base-format-interpolate": "^0.0.x", - "@stdlib/string-base-format-tokenize": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-float64-ninf": "^0.0.x", - "@stdlib/constants-float64-pi": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html index 3948783..76934e8 100644 --- a/stats.html +++ b/stats.html @@ -2669,7 +2669,7 @@ - - - - From 81d8624857783c352855f190ac80ce5ff211cd28 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 05:13:32 +0000 Subject: [PATCH 005/150] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 681 ------ .github/workflows/publish.yml | 157 -- .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 1092 --------- 38 files changed, 2709 insertions(+), 4410 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 90d7edd..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-30T21:03:28.671Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 128c22e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,681 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9823e92..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a117f0b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -click B href "https://github.com/stdlib-js/string-format/tree/main" -click C href "https://github.com/stdlib-js/string-format/tree/production" -click D href "https://github.com/stdlib-js/string-format/tree/esm" -click E href "https://github.com/stdlib-js/string-format/tree/deno" -click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b2ceb17..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The function does not compile if provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..42f692a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..125d0ab --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From d125fcc1d77ce99d17f268148aabd5adde734de8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 17:09:29 +0000 Subject: [PATCH 006/150] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..abe26f3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hB3R', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); diff --git a/package.json b/package.json index 4e14c75..f984d98 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/string-format", + "name": "@stdlib/error-tools-fmtprodmsg", "version": "0.0.1", "description": "Insert supplied variable values into a format string.", "license": "Apache-2.0", From 59f836e0ab429c7ee4d90565e249dcc81d97a40c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 01:46:32 +0000 Subject: [PATCH 007/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2736 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7ae7765..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 42f692a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l - - - - - - RollUp Visualizer - - - -
- - - - - From f1dc3fd375c8a0e94913fd529c8bc28eaa54bd86 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 01:47:03 +0000 Subject: [PATCH 008/150] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 681 ------ .github/workflows/publish.yml | 157 -- .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 1092 --------- 38 files changed, 2709 insertions(+), 4410 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index b92b99e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T00:32:40.853Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 128c22e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,681 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9823e92..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a117f0b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -click B href "https://github.com/stdlib-js/string-format/tree/main" -click C href "https://github.com/stdlib-js/string-format/tree/production" -click D href "https://github.com/stdlib-js/string-format/tree/esm" -click E href "https://github.com/stdlib-js/string-format/tree/deno" -click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b2ceb17..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The function does not compile if provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..42f692a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4b9e3ba --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From ed814ad7b6a87ed673d5ebe8b4a690cfd0c5cc2f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 3 Jul 2022 00:25:51 +0000 Subject: [PATCH 009/150] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..abe26f3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hB3R', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); diff --git a/package.json b/package.json index 87fba20..aab78a5 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/string-format", + "name": "@stdlib/error-tools-fmtprodmsg", "version": "0.0.2", "description": "Insert supplied variable values into a format string.", "license": "Apache-2.0", From 65436eccd2c84cf00f15cf0394da72f4b214f5df Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 3 Jul 2022 00:27:04 +0000 Subject: [PATCH 010/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2736 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7ae7765..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 42f692a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l - - - - - - RollUp Visualizer - - - -
- - - - - From 55e28b67dd43387e6b53dbea1837e283d968bb65 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 3 Jul 2022 00:27:43 +0000 Subject: [PATCH 011/150] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 681 ------ .github/workflows/publish.yml | 157 -- .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 1092 --------- 37 files changed, 2709 insertions(+), 4409 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 128c22e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,681 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9823e92..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a117f0b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -click B href "https://github.com/stdlib-js/string-format/tree/main" -click C href "https://github.com/stdlib-js/string-format/tree/production" -click D href "https://github.com/stdlib-js/string-format/tree/esm" -click E href "https://github.com/stdlib-js/string-format/tree/deno" -click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b2ceb17..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The function does not compile if provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..42f692a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6df2ea8 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 632774b1f63ccbe72232a4cc852c145696558de2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 3 Jul 2022 13:30:49 +0000 Subject: [PATCH 012/150] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..abe26f3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hB3R', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); diff --git a/package.json b/package.json index 87fba20..aab78a5 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/string-format", + "name": "@stdlib/error-tools-fmtprodmsg", "version": "0.0.2", "description": "Insert supplied variable values into a format string.", "license": "Apache-2.0", From de1675002d29c00ee40ed08cb8fd7e0630f00295 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 3 Jul 2022 13:33:58 +0000 Subject: [PATCH 013/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2736 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7ae7765..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 42f692a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l - - - - - - RollUp Visualizer - - - -
- - - - - From 17bdbcf653168d7a6c6aa0de58ccca4ee9dfd78e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 3 Jul 2022 13:34:34 +0000 Subject: [PATCH 014/150] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 687 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 1092 --------- 37 files changed, 2709 insertions(+), 4375 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 6726965..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,687 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9823e92..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a117f0b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -click B href "https://github.com/stdlib-js/string-format/tree/main" -click C href "https://github.com/stdlib-js/string-format/tree/production" -click D href "https://github.com/stdlib-js/string-format/tree/esm" -click E href "https://github.com/stdlib-js/string-format/tree/deno" -click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b2ceb17..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The function does not compile if provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..42f692a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b638dc7 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From df565a15bc1456afdaf3c32485477a0c722eb0e6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 12 Jul 2022 14:15:42 +0000 Subject: [PATCH 015/150] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..abe26f3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hB3R', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); diff --git a/package.json b/package.json index e8860dc..4875ff8 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/string-format", + "name": "@stdlib/error-tools-fmtprodmsg", "version": "0.0.3", "description": "Insert supplied variable values into a format string.", "license": "Apache-2.0", From e51de3166b6489870237a9c168c6650e9bebf9e7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 12 Jul 2022 14:33:24 +0000 Subject: [PATCH 016/150] Update README.md for ESM bundle v0.0.3 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8febd53..20e18f5 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ limitations under the License. ## Usage ```javascript -import format from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs'; +import format from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs'; ``` #### format( str, ...args ) @@ -220,7 +220,7 @@ out = format( str, 7 ); - - - - From 5ad65996dde44ecc13ced38ff79591052018179b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 12 Jul 2022 14:37:13 +0000 Subject: [PATCH 019/150] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/bundle_tags.yml | 125 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 691 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 1092 --------- 38 files changed, 2709 insertions(+), 4504 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/bundle_tags.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/bundle_tags.yml b/.github/workflows/bundle_tags.yml deleted file mode 100644 index 46a96ae..0000000 --- a/.github/workflows/bundle_tags.yml +++ /dev/null @@ -1,125 +0,0 @@ - -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: bundle_tags - -# Workflow triggers: -on: - # Run workflow when a new tag is pushed to the repository: - push: - tags: - - '*' - -# Workflow jobs: -jobs: - - # Define job to wait a minute before running the workflow... - waiting: - - # Define display name: - name: 'Waiting Period' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the steps to run: - steps: - - # Wait three minutes: - - name: 'Wait three minutes' - run: | - sleep 3m - - # Define job to publish bundle tags to GitHub... - create-tags: - - # Define display name: - name: 'Create bundle tags' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: waiting - - # Define the steps to run: - steps: - - # Wait for the productionize workflow to succeed: - - name: 'Wait for productionize workflow to succeed' - uses: lewagon/wait-on-check-action@v1.0.0 - timeout-minutes: 5 - with: - ref: main - check-regexp: 'Productionize' - repo-token: ${{ secrets.GITHUB_TOKEN }} - wait-interval: 60 - allowed-conclusions: success - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - git fetch --all - - # Create bundle tags: - - name: 'Create bundle tags' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - ESCAPED=$(echo $SLUG | sed -E 's/\//\\\//g') - - git checkout -b deno origin/deno - sed -i -E "s/$ESCAPED@deno/$ESCAPED@$VERSION-deno/g" README.md - git add README.md - git commit -m "Update README.md for Deno bundle $VERSION" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - sed -i -E "s/$ESCAPED@$VERSION-deno/$ESCAPED@deno/g" README.md - git add README.md - git commit -m "Revert changes to README.md for Deno bundle $VERSION" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - git checkout -b umd origin/umd - sed -i -E "s/$ESCAPED@umd/$ESCAPED@$VERSION-umd/g" README.md - git add README.md - git commit -m "Update README.md for UMD bundle $VERSION" - git tag -a $VERSION-umd -m "$VERSION-umd" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-umd - sed -i -E "s/$ESCAPED@$VERSION-umd/$ESCAPED@umd/g" README.md - git add README.md - git commit -m "Revert changes to README.md for UMD bundle $VERSION" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" umd - - git checkout -b esm origin/esm - sed -i -E "s/$ESCAPED@esm/$ESCAPED@$VERSION-esm/g" README.md - git add README.md - git commit -m "Update README.md for ESM bundle $VERSION" - git tag -a $VERSION-esm -m "$VERSION-esm" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-esm - sed -i -E "s/$ESCAPED@$VERSION-esm/$ESCAPED@esm/g" README.md - git add README.md - git commit -m "Revert changes to README.md for ESM bundle $VERSION" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" esm diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 0a144b2..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,691 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9823e92..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a117f0b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -click B href "https://github.com/stdlib-js/string-format/tree/main" -click C href "https://github.com/stdlib-js/string-format/tree/production" -click D href "https://github.com/stdlib-js/string-format/tree/esm" -click E href "https://github.com/stdlib-js/string-format/tree/deno" -click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b2ceb17..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The function does not compile if provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..42f692a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c3e0691 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 82df96ea386b092b54422dfba449d85fa59dcf65 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 04:41:24 +0000 Subject: [PATCH 020/150] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..abe26f3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hB3R', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); diff --git a/package.json b/package.json index e8860dc..4875ff8 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/string-format", + "name": "@stdlib/error-tools-fmtprodmsg", "version": "0.0.3", "description": "Insert supplied variable values into a format string.", "license": "Apache-2.0", From d45c0712fd10fd439309ab48b44748f7943e1754 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 13:05:28 +0000 Subject: [PATCH 021/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2736 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7ae7765..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 42f692a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l - - - - - - RollUp Visualizer - - - -
- - - - - From 6ade7378711774c1beb3a6d3c019ccb5ebdcf12a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 13:05:58 +0000 Subject: [PATCH 022/150] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 1092 --------- 38 files changed, 2709 insertions(+), 4449 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 3c15eb7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T00:36:11.351Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9823e92..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a117f0b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -click B href "https://github.com/stdlib-js/string-format/tree/main" -click C href "https://github.com/stdlib-js/string-format/tree/production" -click D href "https://github.com/stdlib-js/string-format/tree/esm" -click E href "https://github.com/stdlib-js/string-format/tree/deno" -click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b2ceb17..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The function does not compile if provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..42f692a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..dc7e76f --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 480db38be719756266f7d0ea0dd2e84b6b4022d1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 04:18:25 +0000 Subject: [PATCH 023/150] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..abe26f3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hB3R', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); diff --git a/package.json b/package.json index e8860dc..4875ff8 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/string-format", + "name": "@stdlib/error-tools-fmtprodmsg", "version": "0.0.3", "description": "Insert supplied variable values into a format string.", "license": "Apache-2.0", From 9bd1d35cdf4631c60841c21bd2f0ce72f1533970 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 12:18:02 +0000 Subject: [PATCH 024/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2736 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7ae7765..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 42f692a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l - - - - - - RollUp Visualizer - - - -
- - - - - From d0a7ad5eaa9c980ac6c0ac0e2a24c1ed4cc58f25 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 12:18:48 +0000 Subject: [PATCH 025/150] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 1092 --------- 38 files changed, 2709 insertions(+), 4465 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 3f46167..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T00:30:38.898Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9823e92..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a117f0b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -click B href "https://github.com/stdlib-js/string-format/tree/main" -click C href "https://github.com/stdlib-js/string-format/tree/production" -click D href "https://github.com/stdlib-js/string-format/tree/esm" -click E href "https://github.com/stdlib-js/string-format/tree/deno" -click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b2ceb17..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The function does not compile if provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..42f692a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..52ced4e --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 2ab64ca0c89415cfff7de9b51e7b72089985343d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 03:25:01 +0000 Subject: [PATCH 026/150] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..abe26f3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hB3R', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); diff --git a/package.json b/package.json index e8860dc..4875ff8 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/string-format", + "name": "@stdlib/error-tools-fmtprodmsg", "version": "0.0.3", "description": "Insert supplied variable values into a format string.", "license": "Apache-2.0", From e6cccab4fa2f64b16a2217f4eab84ca05b165aaf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 14:24:20 +0000 Subject: [PATCH 027/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2736 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7ae7765..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 42f692a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l - - - - - - RollUp Visualizer - - - -
- - - - - From 2914b0b27001e5825a435d9adc744fd080ec93f7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 14:24:52 +0000 Subject: [PATCH 028/150] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 1092 --------- 38 files changed, 2709 insertions(+), 4465 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 168e7f8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T00:54:18.788Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a117f0b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -click B href "https://github.com/stdlib-js/string-format/tree/main" -click C href "https://github.com/stdlib-js/string-format/tree/production" -click D href "https://github.com/stdlib-js/string-format/tree/esm" -click E href "https://github.com/stdlib-js/string-format/tree/deno" -click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5b1dd73 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..466ee9a --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From f9dce381745571e5ede29249a41232bddcc5b276 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 03:12:45 +0000 Subject: [PATCH 029/150] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..abe26f3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hB3R', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); diff --git a/package.json b/package.json index e8860dc..4875ff8 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/string-format", + "name": "@stdlib/error-tools-fmtprodmsg", "version": "0.0.3", "description": "Insert supplied variable values into a format string.", "license": "Apache-2.0", From aec82550a274f15c106862bc11a080d0a4d9ccd0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 13:35:17 +0000 Subject: [PATCH 030/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2736 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7ae7765..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5b1dd73..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l - - - - - - RollUp Visualizer - - - -
- - - - - From d66ad34cc77766c4eebb6b7e06f3ff3dc9f73d53 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 13:36:04 +0000 Subject: [PATCH 031/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 1092 ------ 38 files changed, 4064 insertions(+), 4465 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 68ea6ec..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T00:42:47.053Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ca63e2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9113bfe..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a117f0b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -click B href "https://github.com/stdlib-js/string-format/tree/main" -click C href "https://github.com/stdlib-js/string-format/tree/production" -click D href "https://github.com/stdlib-js/string-format/tree/esm" -click E href "https://github.com/stdlib-js/string-format/tree/deno" -click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5b1dd73 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0847890 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 82b081cd39bdc9fe67748a0fceceb03bc8aa8e90 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 3 Nov 2022 20:52:00 +0000 Subject: [PATCH 032/150] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..abe26f3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hB3R', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); diff --git a/package.json b/package.json index e8860dc..4875ff8 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/string-format", + "name": "@stdlib/error-tools-fmtprodmsg", "version": "0.0.3", "description": "Insert supplied variable values into a format string.", "license": "Apache-2.0", From edbd9c3e8b86369e9be4786ac7a5929becdc500b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 09:20:57 +0000 Subject: [PATCH 033/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4091 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7ae7765..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5b1dd73..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l - - - - - - RollUp Visualizer - - - -
- - - - - From 929a3ca0f06f2301093b0e8ef4420e2097b7dbb1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 09:21:45 +0000 Subject: [PATCH 034/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 781 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 1092 ------ 38 files changed, 4064 insertions(+), 4486 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 89b77e8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T20:42:03.954Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ca63e2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a117f0b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -click B href "https://github.com/stdlib-js/string-format/tree/main" -click C href "https://github.com/stdlib-js/string-format/tree/production" -click D href "https://github.com/stdlib-js/string-format/tree/esm" -click E href "https://github.com/stdlib-js/string-format/tree/deno" -click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5b1dd73 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..46fdbf7 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 605844163ff70f0ef4dff223633fa43fb96c60e0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 00:42:47 +0000 Subject: [PATCH 035/150] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..abe26f3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hB3R', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); diff --git a/package.json b/package.json index 8965fea..aa68ccf 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/string-format", + "name": "@stdlib/error-tools-fmtprodmsg", "version": "0.0.3", "description": "Insert supplied variable values into a format string.", "license": "Apache-2.0", From 0345a5d7db53ef52b5572e3dcf85773c9e6ba018 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 10:10:54 +0000 Subject: [PATCH 036/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4091 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7ae7765..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5b1dd73..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l - - - - - - RollUp Visualizer - - - -
- - - - - From d57710af6c444c571565fcd4125b1f1219c279ba Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 10:11:29 +0000 Subject: [PATCH 037/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 781 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 183 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 1092 ------ 38 files changed, 4064 insertions(+), 4491 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 14dbf05..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T00:33:49.937Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ca63e2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a117f0b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -click B href "https://github.com/stdlib-js/string-format/tree/main" -click C href "https://github.com/stdlib-js/string-format/tree/production" -click D href "https://github.com/stdlib-js/string-format/tree/esm" -click E href "https://github.com/stdlib-js/string-format/tree/deno" -click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5b1dd73 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3265b8e --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From a7c4b150a48c124b24186d0a8a1c81cf111232c4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 02:28:10 +0000 Subject: [PATCH 038/150] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..abe26f3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hB3R', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); diff --git a/package.json b/package.json index 56c60fd..8662bad 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/string-format", + "name": "@stdlib/error-tools-fmtprodmsg", "version": "0.0.3", "description": "Insert supplied variable values into a format string.", "license": "Apache-2.0", From 2ea003163861e9a68e6f459f453fde65accdc5e8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 11:40:18 +0000 Subject: [PATCH 039/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4091 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7ae7765..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5b1dd73..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l - - - - - - RollUp Visualizer - - - -
- - - - - From 6aabda7189ed2514e9d7d36803af22bb651c297e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 11:40:51 +0000 Subject: [PATCH 040/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 791 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 184 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 1092 ------ 38 files changed, 4064 insertions(+), 4502 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index addb7fa..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-01-01T00:31:53.210Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ca63e2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a117f0b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -click B href "https://github.com/stdlib-js/string-format/tree/main" -click C href "https://github.com/stdlib-js/string-format/tree/production" -click D href "https://github.com/stdlib-js/string-format/tree/esm" -click E href "https://github.com/stdlib-js/string-format/tree/deno" -click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c175320 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a6c1d3d --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 348457ce6f0c1a048ac46de05d27e508bfaba6fb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 03:16:30 +0000 Subject: [PATCH 041/150] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..abe26f3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hB3R', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); diff --git a/package.json b/package.json index 56c60fd..8662bad 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/string-format", + "name": "@stdlib/error-tools-fmtprodmsg", "version": "0.0.3", "description": "Insert supplied variable values into a format string.", "license": "Apache-2.0", From 5acdc6e981fb0fe5c30afd13a1588cf362d6e9da Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 11:00:53 +0000 Subject: [PATCH 042/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4091 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7ae7765..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c175320..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l - - - - - - RollUp Visualizer - - - -
- - - - - From dc07560222087cdddb370f66e0f00944033789ca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 11:01:33 +0000 Subject: [PATCH 043/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 791 --- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 184 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 1092 ---- 38 files changed, 6197 insertions(+), 4502 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index dc7039f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-02-01T00:34:19.561Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ca63e2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a117f0b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -click B href "https://github.com/stdlib-js/string-format/tree/main" -click C href "https://github.com/stdlib-js/string-format/tree/production" -click D href "https://github.com/stdlib-js/string-format/tree/esm" -click E href "https://github.com/stdlib-js/string-format/tree/deno" -click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c175320 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2ecf33a --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 243c792f54f8efd2c010b0f9bd284c4761f203f2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 00:36:22 +0000 Subject: [PATCH 044/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..abe26f3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hB3R', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); From cf0152df0f438153e698ee0ba5a07574d07c1d1a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 00:50:55 +0000 Subject: [PATCH 045/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6224 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7ae7765..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c175320..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l - - - - - - Rollup Visualizer - - - -
- - - - - From 50394847250c73ae25ac3eae70f4b5bf84beb288 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 00:51:43 +0000 Subject: [PATCH 046/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 236 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 1092 ---- 38 files changed, 6197 insertions(+), 4637 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index b1996da..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-03-01T00:35:14.156Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ca63e2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ca8e110..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c175320 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..55eded1 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 3a8b20934263d6ce702cc3b7dd79c29e18771e27 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 00:31:51 +0000 Subject: [PATCH 047/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..abe26f3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hB3R', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); From 0cba560fa295763621395f564029cc907a1a1a16 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 00:42:49 +0000 Subject: [PATCH 048/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6224 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7ae7765..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c175320..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l - - - - - - Rollup Visualizer - - - -
- - - - - From 19cdb1ba88d426b0c1bceaa0a40ccd98c4566d54 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 00:43:26 +0000 Subject: [PATCH 049/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 1092 ---- 38 files changed, 6197 insertions(+), 4643 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 223073d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-04-01T00:31:04.905Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ca63e2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ca8e110..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c175320 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d95ecd2 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 4bb39541c0a0644a041b979582d7304ca88e536b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 00:31:54 +0000 Subject: [PATCH 050/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..abe26f3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hB3R', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); From 8e6fb8330b75519d2576eefae186d818b8340682 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 00:45:20 +0000 Subject: [PATCH 051/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6224 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7ae7765..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c175320..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l - - - - - - Rollup Visualizer - - - -
- - - - - From d2b61a2354d3b4e26652ca399d1d0521b0f37f0b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 00:46:04 +0000 Subject: [PATCH 052/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 1092 ---- 38 files changed, 6197 insertions(+), 4643 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index b0aa3a6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-05-01T00:30:50.758Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ca63e2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ca8e110..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c175320 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4fd4b4b --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 6b03d698e9beac4f86c0510aff7c2c88a52f7cae Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 00:41:39 +0000 Subject: [PATCH 053/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..abe26f3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hB3R', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); From 1302a0a5eab04af88c737940a30583a2d88b98f9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 00:56:04 +0000 Subject: [PATCH 054/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6224 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7ae7765..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c175320..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l - - - - - - Rollup Visualizer - - - -
- - - - - From 90e8c7c3e1b735e874411a4b1478feee1b9ffe3e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 00:56:42 +0000 Subject: [PATCH 055/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 1092 ---- 38 files changed, 6197 insertions(+), 4643 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index de1d018..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-06-01T00:40:42.878Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ca63e2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ca8e110..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c175320 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8bd7b53 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From c859729d37731c8b8de339ae3b4c750ceb26df6e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 00:39:29 +0000 Subject: [PATCH 056/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..abe26f3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hB3R', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); From 8aca55d222d7d3420d95bf0d006f9bcc8912deb3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 00:52:12 +0000 Subject: [PATCH 057/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6224 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7ae7765..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c175320..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l - - - - - - Rollup Visualizer - - - -
- - - - - From e9b842500dea2280911d072d98c61ab855716fb5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 00:52:51 +0000 Subject: [PATCH 058/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 1092 ---- 38 files changed, 6197 insertions(+), 4643 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 25f42c8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-07-01T00:38:34.160Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ca63e2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ca8e110..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c175320 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c7fcb7b --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From fa0dd0639548f218e68a62d08c6f6d7cd9387924 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 00:35:47 +0000 Subject: [PATCH 059/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..abe26f3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hB3R', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); From d057ff87601f35c3bf4a5b3a6c171ce0800f4b40 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 00:53:52 +0000 Subject: [PATCH 060/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6224 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7ae7765..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c175320..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l - - - - - - Rollup Visualizer - - - -
- - - - - From 23e8c4e55781332b461979ea4dba1beff5a80aa4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 00:54:25 +0000 Subject: [PATCH 061/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 1092 ---- 38 files changed, 6197 insertions(+), 4643 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index e72ccf4..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-08-01T00:34:41.271Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ca63e2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 334eb59..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ca8e110..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6e8ba9e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( str, ...args ) - Insert supplied variable values into a format string. - - Parameters - ---------- - str: string - Input string. - - args: ...any - Variable values. - - Returns - ------- - out: string - Formatted string. - - Examples - -------- - > var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c175320 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e09d211 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 8f470b22e970fbffbd7725caf5ebafc9b926ba2d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 19 Aug 2023 00:39:36 +0000 Subject: [PATCH 062/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..630a353 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F,Ex', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); From 40b7bdda47a87ec84822234c2ac3943cb727a109 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 19 Aug 2023 00:50:49 +0000 Subject: [PATCH 063/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6224 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7ae7765..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c175320..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,l;if(!e(s))throw new TypeError(n("0hB3R",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,l=1;l - - - - - - Rollup Visualizer - - - -
- - - - - From efc5671e16c7c91b47c27b94bb856080dbfc94aa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 19 Aug 2023 00:51:25 +0000 Subject: [PATCH 064/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 783 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 1092 ---- 40 files changed, 6197 insertions(+), 4644 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ca63e2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -270,7 +263,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ca8e110..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 62bc2ca..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var s=i(function(q,a){ -function l(r){return typeof r=="string"}a.exports=l -});var g=i(function(y,o){ -var p=require('@stdlib/string-base-format-interpolate/dist'),v=require('@stdlib/string-base-format-tokenize/dist'),m=s();function u(r){var e,t,n;if(!m(r))throw new TypeError(u('1Of3F',r));for(e=v(r),t=new Array(arguments.length),t[0]=e,n=1;n var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..497ed08 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,f;if(!e(s))throw new TypeError(n("1Of3F,Ex",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,f=1;f=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..89b63a3 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From afcd1ad20f3375544f831d637eeec20c13e38e2b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 03:03:39 +0000 Subject: [PATCH 065/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..630a353 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F,Ex', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); From 1a9da255c0d6049450cf1456bb43ad359b9eab39 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 03:16:09 +0000 Subject: [PATCH 066/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6224 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 643f790..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 497ed08..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,f;if(!e(s))throw new TypeError(n("1Of3F,Ex",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,f=1;f - - - - - - Rollup Visualizer - - - -
- - - - - From f4bf8d7a391590ea7594591da12463bf6ce291b2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 03:16:45 +0000 Subject: [PATCH 067/150] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 783 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 1092 ---- 41 files changed, 6197 insertions(+), 4679 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 848916a..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ca63e2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -281,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ca8e110..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 62bc2ca..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var s=i(function(q,a){ -function l(r){return typeof r=="string"}a.exports=l -});var g=i(function(y,o){ -var p=require('@stdlib/string-base-format-interpolate/dist'),v=require('@stdlib/string-base-format-tokenize/dist'),m=s();function u(r){var e,t,n;if(!m(r))throw new TypeError(u('1Of3F',r));for(e=v(r),t=new Array(arguments.length),t[0]=e,n=1;n var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..497ed08 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.0.4-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.0.4-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,f;if(!e(s))throw new TypeError(n("1Of3F,Ex",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,f=1;f=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..877538a --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 8d25d009e77e66eaad631fb0f4cfdec3633d581b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 03:23:59 +0000 Subject: [PATCH 068/150] Update README.md for ESM bundle v0.1.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c06e012..4b300e3 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ limitations under the License. ## Usage ```javascript -import format from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs'; +import format from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.0-esm/index.mjs'; ``` #### format( str, ...args ) @@ -231,7 +231,7 @@ out = format( str, 7 ); - - - - From d660b5ebb2a927dd0b414d7605324e64623c09f1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 01:27:01 +0000 Subject: [PATCH 072/150] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 1092 ---- test/test.js | 1092 ---- 43 files changed, 6197 insertions(+), 5830 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 0880282..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T00:32:24.337Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index aa1197c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -281,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ca8e110..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 62bc2ca..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var s=i(function(q,a){ -function l(r){return typeof r=="string"}a.exports=l -});var g=i(function(y,o){ -var p=require('@stdlib/string-base-format-interpolate/dist'),v=require('@stdlib/string-base-format-tokenize/dist'),m=s();function u(r){var e,t,n;if(!m(r))throw new TypeError(u('1Of3F',r));for(e=v(r),t=new Array(arguments.length),t[0]=e,n=1;n var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c46fe65 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.1.0-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,f;if(!e(s))throw new TypeError(n("1Of3F,Ex",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,f=1;f=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..10c5dc4 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index c6289c2..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 67d42623a6084e32593139e5503b6e8902f9eda6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 3 Oct 2023 22:48:51 +0000 Subject: [PATCH 073/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..630a353 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F,Ex', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); From 8c2850d12c2404b68908e2a92db57439414027c3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 00:10:56 +0000 Subject: [PATCH 074/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6224 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 643f790..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c46fe65..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.1.0-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,f;if(!e(s))throw new TypeError(n("1Of3F,Ex",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,f=1;f - - - - - - Rollup Visualizer - - - -
- - - - - From 55b104a00ddec8a52164efaed427b0cafbc0111e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 00:11:33 +0000 Subject: [PATCH 075/150] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 1092 ---- test/test.js | 1092 ---- 42 files changed, 6197 insertions(+), 5829 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index aa1197c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -281,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ca8e110..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 62bc2ca..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var s=i(function(q,a){ -function l(r){return typeof r=="string"}a.exports=l -});var g=i(function(y,o){ -var p=require('@stdlib/string-base-format-interpolate/dist'),v=require('@stdlib/string-base-format-tokenize/dist'),m=s();function u(r){var e,t,n;if(!m(r))throw new TypeError(u('1Of3F',r));for(e=v(r),t=new Array(arguments.length),t[0]=e,n=1;n var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..baedc71 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.1.1-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,f;if(!e(s))throw new TypeError(n("1Of3F,Ex",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,f=1;f=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3b7fc31 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index c6289c2..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 97522b10b4e2005fe2267a04df2afabf430ac54a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 02:25:24 +0000 Subject: [PATCH 076/150] Update README.md for ESM bundle v0.1.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 35cd736..59182b3 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ limitations under the License. ## Usage ```javascript -import format from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs'; +import format from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs'; ``` #### format( str, ...args ) @@ -231,7 +231,7 @@ out = format( str, 7 ); - - - - From 282fbb34145651e56ae9f19a8d41cc47aea7fca7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 02:47:25 +0000 Subject: [PATCH 080/150] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 1092 ---- test/test.js | 1092 ---- 42 files changed, 6197 insertions(+), 5829 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index aa1197c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -281,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ca8e110..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 62bc2ca..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var s=i(function(q,a){ -function l(r){return typeof r=="string"}a.exports=l -});var g=i(function(y,o){ -var p=require('@stdlib/string-base-format-interpolate/dist'),v=require('@stdlib/string-base-format-tokenize/dist'),m=s();function u(r){var e,t,n;if(!m(r))throw new TypeError(u('1Of3F',r));for(e=v(r),t=new Array(arguments.length),t[0]=e,n=1;n var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..baedc71 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.1.1-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,f;if(!e(s))throw new TypeError(n("1Of3F,Ex",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,f=1;f=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..25a5a0a --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index c6289c2..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From c17a9d189a783b7a32b8d6f9fefce66bd25a892c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 00:32:43 +0000 Subject: [PATCH 081/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index c08c83c..630a353 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,7 +50,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F,Ex', str ) ); } tokens = tokenize( str ); args = new Array( arguments.length ); From 0dea31a70e202905ec98103f5518eca7f0558193 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 01:25:39 +0000 Subject: [PATCH 082/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6224 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 643f790..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index baedc71..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.1.1-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,f;if(!e(s))throw new TypeError(n("1Of3F,Ex",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,f=1;f - - - - - - Rollup Visualizer - - - -
- - - - - From 548c3b249ed73197b2f6764273abab996a277578 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 01:26:28 +0000 Subject: [PATCH 083/150] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 67 - package.json | 56 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ---- 43 files changed, 6197 insertions(+), 4779 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 22566ce..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T00:30:35.082Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index aa1197c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -281,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ca8e110..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 62bc2ca..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var s=i(function(q,a){ -function l(r){return typeof r=="string"}a.exports=l -});var g=i(function(y,o){ -var p=require('@stdlib/string-base-format-interpolate/dist'),v=require('@stdlib/string-base-format-tokenize/dist'),m=s();function u(r){var e,t,n;if(!m(r))throw new TypeError(u('1Of3F',r));for(e=v(r),t=new Array(arguments.length),t[0]=e,n=1;n var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..baedc71 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.1.1-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,f;if(!e(s))throw new TypeError(n("1Of3F,Ex",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,f=1;f=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8b5d377 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 1ce5ff1468168ef7a5621071a9532f5bf1617d1c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 7 Nov 2023 05:48:04 +0000 Subject: [PATCH 084/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 40d7310..d38ae26 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F,Ex', str ) ); } args = [ tokenize( str ) ]; for ( i = 1; i < arguments.length; i++ ) { From 814281e71b4286e992ffd7c58f1adb9b3e6d3f95 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 7 Nov 2023 05:48:33 +0000 Subject: [PATCH 085/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6224 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 643f790..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index baedc71..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.1.1-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o,f;if(!e(s))throw new TypeError(n("1Of3F,Ex",s));for(i=r(s),(o=new Array(arguments.length))[0]=i,f=1;f - - - - - - Rollup Visualizer - - - -
- - - - - From 0c3ad5410385783f907556b50899a42ac155f38a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 7 Nov 2023 05:49:12 +0000 Subject: [PATCH 086/150] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ---- 42 files changed, 6197 insertions(+), 4775 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index aa1197c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -281,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ca8e110..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0a5a1d1 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.1.1-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o;if(!e(s))throw new TypeError(n("1Of3F,Ex",s));for(i=[r(s)],o=1;o=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4f3676f --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 6b2c38eb99063440290846421fea907ade65f9cb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 00:35:16 +0000 Subject: [PATCH 087/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 40d7310..d38ae26 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F,Ex', str ) ); } args = [ tokenize( str ) ]; for ( i = 1; i < arguments.length; i++ ) { From 21cb200cb47a546b138c2bb14ed9b61c3205a804 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 01:08:57 +0000 Subject: [PATCH 088/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6224 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 643f790..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 0a5a1d1..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.1.1-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o;if(!e(s))throw new TypeError(n("1Of3F,Ex",s));for(i=[r(s)],o=1;o - - - - - - Rollup Visualizer - - - -
- - - - - From 8d21f679f9419aa098bf7360d8f5ada8f040f28d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 01:09:30 +0000 Subject: [PATCH 089/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 33 +- benchmark/benchmark.js | 73 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ---- 43 files changed, 6197 insertions(+), 4771 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 3ab2f32..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T00:32:53.441Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index aa1197c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -281,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 60823c7..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ca8e110..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0a5a1d1 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.1.1-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o;if(!e(s))throw new TypeError(n("1Of3F,Ex",s));for(i=[r(s)],o=1;o=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..013c4c4 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 8da48ca4659b517ea647a8d8c8e99b4813c4c295 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 21 Feb 2024 15:16:44 +0000 Subject: [PATCH 090/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 40d7310..a221e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F', str ) ); } args = [ tokenize( str ) ]; for ( i = 1; i < arguments.length; i++ ) { From 1b5a56fef65aa5e5eafcb2b76eb9214b9de9bdc1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 21 Feb 2024 15:23:49 +0000 Subject: [PATCH 091/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6224 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 643f790..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 0a5a1d1..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.1.1-esm/index.mjs";function e(t){return"string"==typeof t}function n(s){var i,o;if(!e(s))throw new TypeError(n("1Of3F,Ex",s));for(i=[r(s)],o=1;o - - - - - - Rollup Visualizer - - - -
- - - - - From f0d2768884ebf4c8c3f0588c5ae0ccacb69923ca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 21 Feb 2024 15:24:03 +0000 Subject: [PATCH 092/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 73 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ----- 43 files changed, 4862 insertions(+), 4779 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d4b596e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -283,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 63dcc06..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a4617be..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9c4d167 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.1-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..188afa4 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 798d914f5e05757265eaadef179e75471b6273b0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 21 Feb 2024 15:24:55 +0000 Subject: [PATCH 093/150] Update README.md for ESM bundle v0.2.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e8eab68..f6e20a9 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ limitations under the License. ## Usage ```javascript -import format from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs'; +import format from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.1-esm/index.mjs'; ``` #### format( str, ...args ) @@ -231,7 +231,7 @@ out = format( str, 7 ); - - - - From c612c22ecccff5df0d2cf2e6111b2e895ed9cf47 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 00:40:00 +0000 Subject: [PATCH 097/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 73 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ----- 44 files changed, 4862 insertions(+), 4781 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 1d36147..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T00:32:34.744Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d4b596e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -283,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 63dcc06..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a4617be..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..675b7cb --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.1-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..39f9b7d --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 2a13adf4cdb0253ebe9e2a521338dc6945188140 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 00:33:35 +0000 Subject: [PATCH 098/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 40d7310..a221e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F', str ) ); } args = [ tokenize( str ) ]; for ( i = 1; i < arguments.length; i++ ) { From 136c73e2bfb639448b68811388d2632719da9689 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 00:44:21 +0000 Subject: [PATCH 099/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4889 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 643f790..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 675b7cb..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.1-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i - - - - - - Rollup Visualizer - - - -
- - - - - From 2d91307f133c770f4dfb95931fc67b84bd45b972 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 00:44:36 +0000 Subject: [PATCH 100/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 73 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ----- 44 files changed, 4862 insertions(+), 4784 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 1266f51..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T00:32:35.058Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d4b596e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -283,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 63dcc06..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a4617be..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..675b7cb --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.1-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..39f9b7d --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From f2dd7308a8be73f5a6d065ed6793d0c1afa39a1f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 11 Apr 2024 20:43:10 +0000 Subject: [PATCH 101/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 40d7310..a221e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F', str ) ); } args = [ tokenize( str ) ]; for ( i = 1; i < arguments.length; i++ ) { From 4bf0eddc292a761adaaed65e0776e70b5372f073 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 11 Apr 2024 20:53:00 +0000 Subject: [PATCH 102/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4889 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 643f790..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 675b7cb..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.1-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i - - - - - - Rollup Visualizer - - - -
- - - - - From 0d5ee03540738c29bfaa63c8f22bd841baa10ad6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 11 Apr 2024 20:53:14 +0000 Subject: [PATCH 103/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 134 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 73 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ----- 43 files changed, 4862 insertions(+), 4785 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d4b596e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -283,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 63dcc06..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a4617be..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..675b7cb --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.1-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..39f9b7d --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From afaf2254d4390157a84c5196e8c9cd99b8d88044 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 00:32:59 +0000 Subject: [PATCH 104/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 40d7310..a221e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F', str ) ); } args = [ tokenize( str ) ]; for ( i = 1; i < arguments.length; i++ ) { From 8fcf86a2dc80da06e64d310ee48f751575df927c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 00:45:24 +0000 Subject: [PATCH 105/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4889 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 643f790..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 675b7cb..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.1-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i - - - - - - Rollup Visualizer - - - -
- - - - - From 25a3e6c421a9c5b01489f5cd7e544471947324cf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 00:45:44 +0000 Subject: [PATCH 106/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 248 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 73 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ----- 44 files changed, 4862 insertions(+), 4793 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index fdee2f7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-05-01T00:31:47.819Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d4b596e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f92a6c5..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -283,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 63dcc06..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a4617be..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..675b7cb --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.1-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..39f9b7d --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 71e651eee9d3ac2a4a52820856301f647bf49c25 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 00:35:10 +0000 Subject: [PATCH 107/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 40d7310..a221e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F', str ) ); } args = [ tokenize( str ) ]; for ( i = 1; i < arguments.length; i++ ) { From 68a910f758a60195119175e1b2a18be5ba66fe9d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 00:46:41 +0000 Subject: [PATCH 108/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4889 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 643f790..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 675b7cb..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.1-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i - - - - - - Rollup Visualizer - - - -
- - - - - From 191e16d1cb289b67513b5bab9f5e51d5cbe1ee7a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 00:46:56 +0000 Subject: [PATCH 109/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 248 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 73 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ----- 44 files changed, 4862 insertions(+), 4793 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 85c3be7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-06-01T00:33:58.200Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d4b596e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f92a6c5..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -283,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 63dcc06..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a4617be..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..675b7cb --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.1-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..39f9b7d --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 572a4a5f23e08580c2a3d72754f558279fec6418 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 00:38:46 +0000 Subject: [PATCH 110/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 40d7310..a221e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F', str ) ); } args = [ tokenize( str ) ]; for ( i = 1; i < arguments.length; i++ ) { From e47f9f0e5879595d99a82d05d19fc7c1b8abd8a5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 00:48:22 +0000 Subject: [PATCH 111/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4889 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 643f790..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 675b7cb..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.1-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i - - - - - - Rollup Visualizer - - - -
- - - - - From 9a85d2dfea0093eb70f05fa911159687165274c6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 00:48:42 +0000 Subject: [PATCH 112/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 38 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 73 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ----- 44 files changed, 4862 insertions(+), 4830 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index ef5c4c8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-07-01T00:37:20.621Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d4b596e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f92a6c5..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -283,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 63dcc06..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a4617be..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..675b7cb --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.1-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..39f9b7d --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From e306ffb70758273eb86fb77bf3ed57c1f70ad474 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 26 Jul 2024 19:17:08 +0000 Subject: [PATCH 113/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 40d7310..a221e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F', str ) ); } args = [ tokenize( str ) ]; for ( i = 1; i < arguments.length; i++ ) { From 87b3c3093f5b1a0bb3abfed352d765d31346887c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 26 Jul 2024 19:18:02 +0000 Subject: [PATCH 114/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4889 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 643f790..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 675b7cb..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.1-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i - - - - - - Rollup Visualizer - - - -
- - - - - From 4c5c28906ec7915fb907f95a024ba1a4f68ebe03 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 26 Jul 2024 19:18:13 +0000 Subject: [PATCH 115/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 152 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 73 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ----- 43 files changed, 4862 insertions(+), 4943 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d4b596e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -283,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 63dcc06..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a4617be..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d1670c8 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8225942 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 96fff530ffc328ede9bcb5c630b3e8d31511bb14 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 26 Jul 2024 19:18:29 +0000 Subject: [PATCH 116/150] Update README.md for ESM bundle v0.2.2 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4b09677..5a1b09b 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ limitations under the License. ## Usage ```javascript -import format from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs'; +import format from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs'; ``` #### format( str, ...args ) @@ -231,7 +231,7 @@ out = format( str, 7 ); - - - - From f458a58bc1cf28557f3d80ea26ed00ea2da6dbf3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 00:47:53 +0000 Subject: [PATCH 120/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 118 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 73 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ----- 44 files changed, 4862 insertions(+), 4912 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 8ccb312..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T00:37:23.248Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d4b596e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -283,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 63dcc06..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a4617be..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b0c8312 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9051526 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From bee0a54c328124452dd4730c3563ba6d2ec285eb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 15:14:56 +0000 Subject: [PATCH 121/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 40d7310..a221e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F', str ) ); } args = [ tokenize( str ) ]; for ( i = 1; i < arguments.length; i++ ) { From 6d2c51e572a6912476bd969900418f164c52d777 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 15:21:10 +0000 Subject: [PATCH 122/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4889 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 643f790..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b0c8312..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i - - - - - - Rollup Visualizer - - - -
- - - - - From 5d1ef058bf20f45ddff4877a5b12e34a954ec1bf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 15:21:25 +0000 Subject: [PATCH 123/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 152 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 73 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ----- 44 files changed, 4862 insertions(+), 4946 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 41560e2..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-03T15:13:50.261Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d4b596e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -283,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 63dcc06..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a4617be..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b0c8312 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9051526 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From b450fece65e3fc77ad449a398e9672b509819175 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 00:44:40 +0000 Subject: [PATCH 124/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 40d7310..a221e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F', str ) ); } args = [ tokenize( str ) ]; for ( i = 1; i < arguments.length; i++ ) { From 8cd84a6f115840743d4b4a8ae5752ae13a79d9ac Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 00:53:49 +0000 Subject: [PATCH 125/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4889 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 643f790..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b0c8312..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i - - - - - - Rollup Visualizer - - - -
- - - - - From 77c727df4eb2babe81e0bd2233b093f38a35ed6e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 00:54:05 +0000 Subject: [PATCH 126/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 152 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 73 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ----- 44 files changed, 4862 insertions(+), 4946 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 1600ab8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T00:43:34.486Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d4b596e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -283,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 63dcc06..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a4617be..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b0c8312 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9051526 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From f4bdb78a87d4504630ff2b0500b173a90a7de1a0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:30:11 +0000 Subject: [PATCH 127/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 40d7310..a221e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F', str ) ); } args = [ tokenize( str ) ]; for ( i = 1; i < arguments.length; i++ ) { From 8bbdf8e578672b75bbb7adb08e25e4451f6f39e5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:43:07 +0000 Subject: [PATCH 128/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4889 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 643f790..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param ...args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b0c8312..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i - - - - - - Rollup Visualizer - - - -
- - - - - From 891fef805677a474ca30d0c292fb9d3e2d19714a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:43:32 +0000 Subject: [PATCH 129/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 186 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 73 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ----- 43 files changed, 4862 insertions(+), 4979 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d4b596e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -283,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 63dcc06..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a4617be..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b0c8312 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9051526 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From a5ff8f26f5da7cb6c1c4618b8787a322e5265d38 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 00:44:33 +0000 Subject: [PATCH 130/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 40d7310..a221e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F', str ) ); } args = [ tokenize( str ) ]; for ( i = 1; i < arguments.length; i++ ) { From 0059480e9c7a1f2475d8cc599b0cdf27ced44896 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 00:52:33 +0000 Subject: [PATCH 131/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4889 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index cecb88d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b0c8312..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i - - - - - - Rollup Visualizer - - - -
- - - - - From 40424884b80a5e42e31696f3f7d799f709611931 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 00:52:45 +0000 Subject: [PATCH 132/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 186 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 73 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ----- 44 files changed, 4862 insertions(+), 4980 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index fdb2200..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T00:43:27.762Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d4b596e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -283,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 63dcc06..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a4617be..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b0c8312 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9051526 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 95aa74b3a6351980312d811e9423c6cab1bfb168 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 00:45:08 +0000 Subject: [PATCH 133/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 40d7310..a221e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F', str ) ); } args = [ tokenize( str ) ]; for ( i = 1; i < arguments.length; i++ ) { From 397c4b3ccebffe79ca6a08b7a0b1610efef46d91 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 00:51:09 +0000 Subject: [PATCH 134/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4889 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index cecb88d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b0c8312..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i - - - - - - Rollup Visualizer - - - -
- - - - - From 587c61e2462441abbebbc0dfa5f05ad0799eca16 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 00:51:24 +0000 Subject: [PATCH 135/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 186 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 73 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ----- 44 files changed, 4862 insertions(+), 4980 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 089f484..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T00:43:56.361Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d4b596e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -283,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 63dcc06..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a4617be..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b0c8312 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9051526 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 418c23d1053886c79f05ee5b48b6ca0c5d17ae45 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 00:51:34 +0000 Subject: [PATCH 136/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 40d7310..a221e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F', str ) ); } args = [ tokenize( str ) ]; for ( i = 1; i < arguments.length; i++ ) { From 581894d0ddff05fc7b3c13cb275ea3e7027d7abf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 00:59:06 +0000 Subject: [PATCH 137/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4889 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index cecb88d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b0c8312..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i - - - - - - Rollup Visualizer - - - -
- - - - - From df3030b84a716dc6b2b3adfe1e20b4d6111a4888 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 00:59:20 +0000 Subject: [PATCH 138/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 186 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 73 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ---- 45 files changed, 4862 insertions(+), 5085 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 502d45e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T00:50:27.199Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d4b596e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -283,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 63dcc06..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a4617be..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b0c8312 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9051526 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From f527126e1d88118b810ec413c42fb5f58596d404 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Dec 2024 01:18:35 +0000 Subject: [PATCH 139/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 40d7310..a221e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F', str ) ); } args = [ tokenize( str ) ]; for ( i = 1; i < arguments.length; i++ ) { From 660e9c2cf9c4c04281fa9fdfe6e57c96ce70c565 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Dec 2024 01:25:38 +0000 Subject: [PATCH 140/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4889 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index cecb88d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b0c8312..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i - - - - - - Rollup Visualizer - - - -
- - - - - From 6f79fe3a85d50960d9d61b47806d6f1666486f92 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Dec 2024 01:25:50 +0000 Subject: [PATCH 141/150] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 187 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 73 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ---- 44 files changed, 4862 insertions(+), 5085 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 95150e0..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d4b596e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -283,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 63dcc06..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a4617be..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b0c8312 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9051526 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 6976fd1c3ff3b84fcfd76ffffbb1cdafc4c3b79a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 02:02:45 +0000 Subject: [PATCH 142/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 40d7310..a221e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F', str ) ); } args = [ tokenize( str ) ]; for ( i = 1; i < arguments.length; i++ ) { From 93cbd5a78348f428b9a856d883bf088ebcb54098 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 02:56:32 +0000 Subject: [PATCH 143/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4889 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index cecb88d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b0c8312..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i - - - - - - Rollup Visualizer - - - -
- - - - - From 2696080b96f6264be3ccf11f0b114eae74e2ceea Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 02:56:44 +0000 Subject: [PATCH 144/150] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 187 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 73 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ---- 45 files changed, 4862 insertions(+), 5089 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 5c2657b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-02-24T01:44:51.482Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 758f430..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d4b596e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -283,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 63dcc06..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a4617be..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7acc8ab --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9051526 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From fbdc5129850d5adb506ab5cc4c1c3c063f95fa21 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 3 Mar 2025 00:28:58 +0000 Subject: [PATCH 145/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 40d7310..a221e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F', str ) ); } args = [ tokenize( str ) ]; for ( i = 1; i < arguments.length; i++ ) { From f8aef48a5d216afd797e0b171f00de697773c4e1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 3 Mar 2025 00:33:51 +0000 Subject: [PATCH 146/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4889 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index cecb88d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7acc8ab..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i - - - - - - Rollup Visualizer - - - -
- - - - - From 7d8a3de3b59508e36c304d504f787b8b5551e42b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 3 Mar 2025 00:34:02 +0000 Subject: [PATCH 147/150] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 187 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 73 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ---- 45 files changed, 4862 insertions(+), 5089 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index fd63b2c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-03-03T00:28:24.243Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 758f430..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d4b596e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -283,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 63dcc06..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a4617be..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7acc8ab --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9051526 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); From 6ada682b13d873b6ebd26c17c9b0d7466f3ab7d6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 17 Mar 2025 01:31:36 +0000 Subject: [PATCH 148/150] Transform error messages --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 40d7310..a221e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ function format( str ) { var i; if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1Of3F', str ) ); } args = [ tokenize( str ) ]; for ( i = 1; i < arguments.length; i++ ) { From 9e990c9a35c3d4a7d7e2785fb930efa68f43c597 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 17 Mar 2025 02:40:01 +0000 Subject: [PATCH 149/150] Remove files --- index.d.ts | 42 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4889 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index cecb88d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Inserts supplied variable values into a format string. -* -* @param str - input string -* @param args - variable values -* @throws invalid flags -* @returns formatted string -* -* @example -* var str = format( 'Hello %s!', 'world' ); -* // returns 'Hello world!' -* -* @example -* var str = format( 'Pi: ~%.2f', 3.141592653589793 ); -* // returns 'Pi: ~3.14' -*/ -declare function format( str: string, ...args: Array ): string; - - -// EXPORTS // - -export = format; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7acc8ab..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i - - - - - - Rollup Visualizer - - - -
- - - - - From ebddedc78e04c76381b0d800221b9571a5a7b636 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 17 Mar 2025 02:40:16 +0000 Subject: [PATCH 150/150] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 187 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 73 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 31 - docs/types/test.ts | 45 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 43 - lib/is_string.js | 42 - lib/main.js | 64 - package.json | 56 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1092 ---- 45 files changed, 4862 insertions(+), 5089 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/is_string.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index e603b51..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-03-17T01:20:38.202Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 758f430..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 58e76a6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d4b596e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '31 7 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -283,7 +274,7 @@ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 63dcc06..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var format = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var str; - var i; - - str = '%s %s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'Hello', 'World' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::positional', function benchmark( b ) { - var out; - var str; - var i; - - str = '%2$s %1$s!'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = format( str, 'World', 'Hello' ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a4617be..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format" -%% click B href "https://github.com/stdlib-js/string-format/tree/main" -%% click C href "https://github.com/stdlib-js/string-format/tree/production" -%% click D href "https://github.com/stdlib-js/string-format/tree/esm" -%% click E href "https://github.com/stdlib-js/string-format/tree/deno" -%% click F href "https://github.com/stdlib-js/string-format/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format -[production-url]: https://github.com/stdlib-js/string-format/tree/production -[deno-url]: https://github.com/stdlib-js/string-format/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-format/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-format/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 4d347ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import format from '../docs/types/index'; -export = format; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5809699..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){ -function g(e){return typeof e=="string"}n.exports=g -});var o=i(function(q,s){ -var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t var out = {{alias}}( 'Hello, %s!', 'World' ) - 'Hello, World!' - - > out = {{alias}}( '%s %s', 'Hello', 'World' ) - 'Hello World' - - > out = {{alias}}( 'Pi: %.2f', {{alias:@stdlib/constants/float64/pi}} ) - 'Pi: 3.14' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8e90a6e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import format = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - format( 'Hello World!' ); // $ExpectType string - format( 'Hello, %s!', 'Jane' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided a first argument other than a string... -{ - format( true ); // $ExpectError - format( false ); // $ExpectError - format( null ); // $ExpectError - format( undefined ); // $ExpectError - format( 5 ); // $ExpectError - format( [] ); // $ExpectError - format( {} ); // $ExpectError - format( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - format(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6070964..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var format = require( './../lib' ); - -var out = format( '%s %s!', 'Hello', 'World' ); -console.log( out ); -// => 'Hello World!' - -out = format( 'Pi: ~%.2f', 3.141592653589793 ); -console.log( out ); -// => 'Pi: ~3.14' - -out = format( '%-10s %-10s', 'a', 'b' ); -console.log( out ); -// => 'a b ' - -out = format( '%10s %10s', 'a', 'b' ); -console.log( out ); -// => ' a b' - -out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' ); -console.log( out ); -// => 'a b c' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7acc8ab --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-interpolate@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-format-tokenize@v0.2.2-esm/index.mjs";function r(s){var n,i;if("string"!=typeof s)throw new TypeError(r("1Of3F",s));for(n=[e(s)],i=1;i=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdstring", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9051526 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index acf1714..0000000 --- a/test/test.js +++ /dev/null @@ -1,1092 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var PI = require( '@stdlib/constants-float64-pi' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var NINF = require( '@stdlib/constants-float64-ninf' ); -var format = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof format, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a primitive string', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - null, - void 0, - true, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value ); - }; - } -}); - -tape( 'the function throws an error if provided a format string with an invalid format specifier', function test( t ) { - var values; - var i; - - values = [ - '%C', - '%S', - '%U', - '%Z' - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - format( value, 'beep' ); - }; - } -}); - -tape( 'the function returns a formatted string (`s` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%s'; - actual = format( str, 'beep' ); - expected = 'beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%s %s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6s'; - actual = format( str, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6s'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - - str = '%2s %2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, variable width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%*s'; - actual = format( str, 6, 'beep' ); - expected = ' beep'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %*s'; - actual = format( str, 6, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%*s %*s baz'; - actual = format( str, 6, 'beep', 4, 'boop' ); - expected = ' beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-6s'; - actual = format( str, 'beep' ); - expected = 'beep '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-6s'; - actual = format( str, 'boop' ); - expected = 'beep boop '; - - str = '%-2s %-2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep boop baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.2s'; - actual = format( str, 'beep' ); - expected = 'be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%6.2s'; - actual = format( str, 'beep' ); - expected = ' be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %6.2s'; - actual = format( str, 'boop' ); - expected = 'beep bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%6.8s %4.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, precision, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%06.2s'; - actual = format( str, 'beep' ); - expected = '0000be'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %06.2s'; - actual = format( str, 'boop' ); - expected = 'beep 0000bo'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%06.8s %04.2s baz'; - actual = format( str, 'beep', 'boop' ); - expected = 'beep bo00 b'; - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 70 ); - expected = 'F'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 75 ); - expected = 'beep K'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%c %c baz'; - actual = format( str, 70, 75 ); - expected = 'F K baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, string arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%c'; - actual = format( str, 'b' ); - expected = 'b'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %c'; - actual = format( str, 'boop' ); - expected = 'beep boop'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2c'; - actual = format( str, 80 ); - expected = ' P'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4c'; - actual = format( str, 90 ); - expected = 'beep Z'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2c %c baz'; - actual = format( str, 80, 90 ); - expected = ' P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`c` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2c'; - actual = format( str, 80 ); - expected = 'P '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4c'; - actual = format( str, 90 ); - expected = 'beep Z '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-2c %-c baz'; - actual = format( str, 80, 90 ); - expected = 'P Z baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%d'; - actual = format( str, 3 ); - expected = '3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %d'; - actual = format( str, 5.8 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%d %d baz'; - actual = format( str, 3, 5 ); - expected = '3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, sign)', function test( t ) { - var expected; - var actual; - var str; - - str = '%+d'; - actual = format( str, 3 ); - expected = '+3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %+d'; - actual = format( str, 5.8 ); - expected = 'beep +5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, 3, 5 ); - expected = '+3 +5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%+d %+d baz'; - actual = format( str, -3, -5 ); - expected = '-3 -5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2d'; - actual = format( str, 3 ); - expected = ' 3'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %4d'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2d %d baz'; - actual = format( str, 3.1, 5 ); - expected = ' 3 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-2d'; - actual = format( str, 3 ); - expected = '3 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-4d'; - actual = format( str, 5.2 ); - expected = 'beep 5 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-3d baz'; - actual = format( str, 3, 5 ); - expected = '3 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`d` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%02d'; - actual = format( str, 3 ); - expected = '03'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %04d'; - actual = format( str, 5.1 ); - expected = 'beep 0005'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%02d %d baz'; - actual = format( str, 3, 5 ); - expected = '03 5 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%f'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f %f baz'; - actual = format( str, PINF, NINF ); - expected = 'infinity -infinity baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%f'; - actual = format( str, NaN ); - expected = 'nan'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`F` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%F'; - actual = format( str, 3.14 ); - expected = '3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %F'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140000 5.000000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F %F baz'; - actual = format( str, PINF, NINF ); - expected = 'INFINITY -INFINITY baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%F'; - actual = format( str, NaN ); - expected = 'NAN'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, specified precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, variable precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.*f'; - actual = format( str, 3, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.*f'; - actual = format( str, 3, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.*f %.*f baz'; - actual = format( str, 3, PI, 3, PI ); - expected = '3.142 3.142 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`g` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%g'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %g'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032e-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%g %g baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032e-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3.G'; - actual = format( str, 100 ); - expected = '1E+02'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%G %G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`G` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#G'; - actual = format( str, PI ); - expected = '3.14159'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#3.G'; - actual = format( str, 100 ); - expected = '1.E+02'; // always contains a decimal point! - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#G'; - actual = format( str, 1.0003212e-10 ); - expected = 'beep 1.00032E-10'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#G %#G baz'; - actual = format( str, PI, 1.0003212e-10 ); - expected = '3.14159 1.00032E-10 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12f'; - actual = format( str, 3.14 ); - expected = ' 3.140000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%.3f'; - actual = format( str, 3.14 ); - expected = '3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%.3f'; - actual = format( str, PI ); - expected = '3.142'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%8.3f'; - actual = format( str, 3.14 ); - expected = ' 3.140'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = ' 3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`f` specifier, minimum width, left-justified, decimal precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-8.3f'; - actual = format( str, 3.14 ); - expected = '3.140 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-8.3f'; - actual = format( str, 5.0 ); - expected = 'beep 5.000 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%-8.3f %.3f baz'; - actual = format( str, 3.14, 5.0 ); - expected = '3.140 5.000 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%b %b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#b'; - actual = format( str, 3 ); - expected = '11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#b %#b baz'; - actual = format( str, 3, 5 ); - expected = '11 101 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12b'; - actual = format( str, 3 ); - expected = ' 11'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12b'; - actual = format( str, 5 ); - expected = 'beep 101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, left-justified)', function test( t ) { - var expected; - var actual; - var str; - - str = '%-12b'; - actual = format( str, 3 ); - expected = '11 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %-12b'; - actual = format( str, 5 ); - expected = 'beep 101 '; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`b` specifier, minimum width, zero-padded)', function test( t ) { - var expected; - var actual; - var str; - - str = '%012b'; - actual = format( str, 3 ); - expected = '000000000011'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %012b'; - actual = format( str, 5 ); - expected = 'beep 000000000101'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%o'; - actual = format( str, 12 ); - expected = '14'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %o'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%o %o baz'; - actual = format( str, 8, 9 ); - expected = '10 11 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`o` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#o'; - actual = format( str, 12 ); - expected = '014'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#o'; - actual = format( str, 5 ); - expected = 'beep 05'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#o %#o baz'; - actual = format( str, 8, 9 ); - expected = '010 011 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%x'; - actual = format( str, 12 ); - expected = 'c'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %x'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%x %x baz'; - actual = format( str, 14, 15 ); - expected = 'e f baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`x` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#x'; - actual = format( str, 12 ); - expected = '0xc'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#x'; - actual = format( str, 5 ); - expected = 'beep 0x5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#x %#x baz'; - actual = format( str, 14, 15 ); - expected = '0xe 0xf baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%X'; - actual = format( str, 12 ); - expected = 'C'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %X'; - actual = format( str, 5 ); - expected = 'beep 5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%X %X baz'; - actual = format( str, 14, 15 ); - expected = 'E F baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`X` specifier, alternate form)', function test( t ) { - var expected; - var actual; - var str; - - str = '%#X'; - actual = format( str, 12 ); - expected = '0XC'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %#X'; - actual = format( str, 5 ); - expected = 'beep 0X5'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%#X %#X baz'; - actual = format( str, 14, 15 ); - expected = '0XE 0XF baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`u` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%u'; - actual = format( str, 12 ); - expected = '12'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %u'; - actual = format( str, -5 ); - expected = 'beep 4294967291'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%u %u baz'; - actual = format( str, 14, 15 ); - expected = '14 15 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%e'; - actual = format( str, 12 ); - expected = '1.200000e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %e'; - actual = format( str, -5 ); - expected = 'beep -5.000000e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%e %e baz'; - actual = format( str, 14, 15 ); - expected = '1.400000e+01 1.500000e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`e` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2e'; - actual = format( str, 12 ); - expected = ' 1.20e+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2e'; - actual = format( str, -5 ); - expected = 'beep -5.00e+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2e %12.2e baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40e+01 1.50e+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier)', function test( t ) { - var expected; - var actual; - var str; - - str = '%E'; - actual = format( str, 12 ); - expected = '1.200000E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %E'; - actual = format( str, -5 ); - expected = 'beep -5.000000E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%E %E baz'; - actual = format( str, 14, 15 ); - expected = '1.400000E+01 1.500000E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`E` specifier, minimum width, precision)', function test( t ) { - var expected; - var actual; - var str; - - str = '%12.2E'; - actual = format( str, 12 ); - expected = ' 1.20E+01'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = 'beep %12.2E'; - actual = format( str, -5 ); - expected = 'beep -5.00E+00'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%12.2E %12.2E baz'; - actual = format( str, 14, 15 ); - expected = ' 1.40E+01 1.50E+01 baz'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -}); - -tape( 'the function returns a formatted string (`s` specifier, positional arguments)', function test( t ) { - var expected; - var actual; - var str; - - str = '%2$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%2$s %1$s %1$s!'; - actual = format( str, 'World', 'Hello' ); - expected = 'Hello World World!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - str = '%3$s %2$s %1$s!'; - actual = format( str, 'C', 'B', 'A' ); - expected = 'A B C!'; - t.strictEqual( actual, expected, 'returns expected output' ); - - t.end(); -});