@stdlib/string-base-left-pad 0.0.2 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CITATION.cff ADDED
@@ -0,0 +1,30 @@
1
+ cff-version: 1.2.0
2
+ title: stdlib
3
+ message: >-
4
+ If you use this software, please cite it using the
5
+ metadata from this file.
6
+
7
+ type: software
8
+
9
+ authors:
10
+ - name: The Stdlib Authors
11
+ url: https://github.com/stdlib-js/stdlib/graphs/contributors
12
+
13
+ repository-code: https://github.com/stdlib-js/stdlib
14
+ url: https://stdlib.io
15
+
16
+ abstract: |
17
+ Standard library for JavaScript and Node.js.
18
+
19
+ keywords:
20
+ - JavaScript
21
+ - Node.js
22
+ - TypeScript
23
+ - standard library
24
+ - scientific computing
25
+ - numerical computing
26
+ - statistical computing
27
+
28
+ license: Apache-2.0 AND BSL-1.0
29
+
30
+ date-released: 2016
package/NOTICE CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2022 The Stdlib Authors.
1
+ Copyright (c) 2016-2023 The Stdlib Authors.
package/README.md CHANGED
@@ -18,6 +18,17 @@ limitations under the License.
18
18
 
19
19
  -->
20
20
 
21
+
22
+ <details>
23
+ <summary>
24
+ About stdlib...
25
+ </summary>
26
+ <p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
27
+ <p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
28
+ <p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
29
+ <p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
30
+ </details>
31
+
21
32
  # lpad
22
33
 
23
34
  [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
@@ -71,6 +82,9 @@ str = lpad( 'boop', 12, 'beep' );
71
82
  var str = lpad( 'boop', 10, 'beep' ); // => length 12
72
83
  // returns 'beepbeepboop'
73
84
 
85
+ str = str.substring( 0, 10 ); // => length 10
86
+ // returns 'beepbeepbo'
87
+
74
88
  str = str.substring( str.length-10 ); // => length 10
75
89
  // returns 'epbeepboop'
76
90
  ```
@@ -109,14 +123,28 @@ str = lpad( 'boop', 12, 'beep' );
109
123
  <!-- eslint no-undef: "error" -->
110
124
 
111
125
  ```javascript
112
- var discreteUniform = require( '@stdlib/random-base-discrete-uniform' );
126
+ var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
127
+ var papply = require( '@stdlib/utils-papply' );
128
+ var papplyRight = require( '@stdlib/utils-papply-right' );
129
+ var naryFunction = require( '@stdlib/utils-nary-function' );
130
+ var map = require( '@stdlib/utils-map' );
131
+ var logEach = require( '@stdlib/console-log-each' );
113
132
  var lpad = require( '@stdlib/string-base-left-pad' );
114
133
 
134
+ // Define a string to pad:
115
135
  var str = 'beep';
116
- var i;
117
- for ( i = 0; i < 100; i++ ) {
118
- console.log( lpad( str, discreteUniform( str.length, str.length+10 ), 'b' ) );
119
- }
136
+
137
+ // Generate random lengths:
138
+ var lens = discreteUniform( 10, str.length, str.length+10 );
139
+
140
+ // Create a function for creating padded strings:
141
+ var fcn = naryFunction( papply( papplyRight( lpad, 'b' ), str ), 1 );
142
+
143
+ // Generate padded strings:
144
+ var out = map( lens, fcn );
145
+
146
+ // Print results:
147
+ logEach( '%s', out );
120
148
  ```
121
149
 
122
150
  </section>
@@ -157,7 +185,7 @@ See [LICENSE][stdlib-license].
157
185
 
158
186
  ## Copyright
159
187
 
160
- Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
188
+ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
161
189
 
162
190
  </section>
163
191
 
@@ -170,8 +198,8 @@ Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
170
198
  [npm-image]: http://img.shields.io/npm/v/@stdlib/string-base-left-pad.svg
171
199
  [npm-url]: https://npmjs.org/package/@stdlib/string-base-left-pad
172
200
 
173
- [test-image]: https://github.com/stdlib-js/string-base-left-pad/actions/workflows/test.yml/badge.svg?branch=v0.0.2
174
- [test-url]: https://github.com/stdlib-js/string-base-left-pad/actions/workflows/test.yml?query=branch:v0.0.2
201
+ [test-image]: https://github.com/stdlib-js/string-base-left-pad/actions/workflows/test.yml/badge.svg?branch=v0.1.1
202
+ [test-url]: https://github.com/stdlib-js/string-base-left-pad/actions/workflows/test.yml?query=branch:v0.1.1
175
203
 
176
204
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/string-base-left-pad/main.svg
177
205
  [coverage-url]: https://codecov.io/github/stdlib-js/string-base-left-pad?branch=main
@@ -184,7 +212,7 @@ Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
184
212
  -->
185
213
 
186
214
  [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
187
- [chat-url]: https://gitter.im/stdlib-js/stdlib/
215
+ [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
188
216
 
189
217
  [stdlib]: https://github.com/stdlib-js/stdlib
190
218
 
@@ -0,0 +1,3 @@
1
+ /// <reference path="../docs/types/index.d.ts" />
2
+ import lpad from '../docs/types/index';
3
+ export = lpad;
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";var a=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var u=a(function(p,n){
2
+ var c=require('@stdlib/string-base-repeat/dist'),l=require('@stdlib/math-base-special-ceil/dist');function s(r,e,i){var t=(e-r.length)/i.length;return t<=0?r:(t=l(t),c(i,t)+r)}n.exports=s
3
+ });var v=u();module.exports=v;
4
+ /** @license Apache-2.0 */
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../lib/main.js", "../lib/index.js"],
4
+ "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// MODULES //\n\nvar repeat = require( '@stdlib/string-base-repeat' );\nvar ceil = require( '@stdlib/math-base-special-ceil' );\n\n\n// MAIN //\n\n/**\n* Left pads a string such that the padded string has a length of at least `len`.\n*\n* @param {string} str - string to pad\n* @param {NonNegativeInteger} len - minimum string length\n* @param {string} pad - string used to pad\n* @returns {string} padded string\n*\n* @example\n* var str = lpad( 'a', 5, ' ' );\n* // returns ' a'\n*\n* @example\n* var str = lpad( 'beep', 10, 'b' );\n* // returns 'bbbbbbbeep'\n*\n* @example\n* var str = lpad( 'boop', 12, 'beep' );\n* // returns 'beepbeepboop'\n*/\nfunction lpad( str, len, pad ) {\n\tvar n = ( len - str.length ) / pad.length;\n\tif ( n <= 0 ) {\n\t\treturn str;\n\t}\n\tn = ceil( n );\n\treturn repeat( pad, n ) + str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = lpad;\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* Left pad a string such that the padded string has a length of at least `len`.\n*\n* @module @stdlib/string-base-left-pad\n*\n* @example\n* var lpad = require( '@stdlib/string-base-left-pad' );\n*\n* var str = lpad( 'a', 5, ' ' );\n* // returns ' a'\n*\n* str = lpad( 'beep', 10, 'b' );\n* // returns 'bbbbbbbeep'\n*\n* str = lpad( 'boop', 12, 'beep' );\n* // returns 'beepbeepboop'\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,4BAA6B,EAC/CC,EAAO,QAAS,gCAAiC,EAyBrD,SAASC,EAAMC,EAAKC,EAAKC,EAAM,CAC9B,IAAIC,GAAMF,EAAMD,EAAI,QAAWE,EAAI,OACnC,OAAKC,GAAK,EACFH,GAERG,EAAIL,EAAMK,CAAE,EACLN,EAAQK,EAAKC,CAAE,EAAIH,EAC3B,CAKAJ,EAAO,QAAUG,ICpBjB,IAAIK,EAAO,IAKX,OAAO,QAAUA",
6
+ "names": ["require_main", "__commonJSMin", "exports", "module", "repeat", "ceil", "lpad", "str", "len", "pad", "n", "main"]
7
+ }
@@ -16,7 +16,7 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
- // TypeScript Version: 2.0
19
+ // TypeScript Version: 4.1
20
20
 
21
21
  /**
22
22
  * Left pads a string such that the padded string has a length of at least `len`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/string-base-left-pad",
3
- "version": "0.0.2",
3
+ "version": "0.1.1",
4
4
  "description": "Left pad a string.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -37,16 +37,21 @@
37
37
  "url": "https://github.com/stdlib-js/stdlib/issues"
38
38
  },
39
39
  "dependencies": {
40
- "@stdlib/math-base-special-ceil": "^0.0.x",
41
- "@stdlib/string-base-repeat": "^0.0.x"
40
+ "@stdlib/math-base-special-ceil": "^0.1.1",
41
+ "@stdlib/string-base-repeat": "^0.1.1"
42
42
  },
43
43
  "devDependencies": {
44
- "@stdlib/assert-is-string": "^0.0.x",
45
- "@stdlib/bench": "^0.0.x",
46
- "@stdlib/random-base-discrete-uniform": "^0.0.x",
44
+ "@stdlib/assert-is-string": "^0.1.1",
45
+ "@stdlib/bench": "^0.1.0",
46
+ "@stdlib/console-log-each": "^0.1.0",
47
+ "@stdlib/random-array-discrete-uniform": "^0.1.0",
48
+ "@stdlib/utils-map": "^0.1.0",
49
+ "@stdlib/utils-nary-function": "^0.1.0",
50
+ "@stdlib/utils-papply": "^0.1.1",
51
+ "@stdlib/utils-papply-right": "^0.1.1",
47
52
  "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
48
53
  "istanbul": "^0.4.1",
49
- "tap-spec": "5.x.x"
54
+ "tap-min": "git+https://github.com/Planeshifter/tap-min.git"
50
55
  },
51
56
  "engines": {
52
57
  "node": ">=0.10.0",
@@ -79,7 +84,7 @@
79
84
  "left"
80
85
  ],
81
86
  "funding": {
82
- "type": "patreon",
83
- "url": "https://www.patreon.com/athan"
87
+ "type": "opencollective",
88
+ "url": "https://opencollective.com/stdlib"
84
89
  }
85
90
  }
package/docs/repl.txt DELETED
@@ -1,38 +0,0 @@
1
-
2
- {{alias}}( str, len, pad )
3
- Left pads a string such that the padded string has a length of at least
4
- `len`.
5
-
6
- An output string is not guaranteed to have a length of exactly `len`, but to
7
- have a length of at least `len`. To generate a padded string having a length
8
- equal to `len`, post-process a padded string by trimming off excess
9
- characters.
10
-
11
- Parameters
12
- ----------
13
- str: string
14
- Input string.
15
-
16
- len: integer
17
- Minimum string length.
18
-
19
- pad: string
20
- String used to pad.
21
-
22
- Returns
23
- -------
24
- out: string
25
- Padded string.
26
-
27
- Examples
28
- --------
29
- > var out = {{alias}}( 'a', 5, ' ' )
30
- ' a'
31
- > out = {{alias}}( 'beep', 10, 'b' )
32
- 'bbbbbbbeep'
33
- > out = {{alias}}( 'boop', 12, 'beep' )
34
- 'beepbeepboop'
35
-
36
- See Also
37
- --------
38
-
@@ -1,59 +0,0 @@
1
- /*
2
- * @license Apache-2.0
3
- *
4
- * Copyright (c) 2022 The Stdlib Authors.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
-
19
- import lpad = require( './index' );
20
-
21
-
22
- // TESTS //
23
-
24
- // The function returns a string...
25
- {
26
- lpad( 'abd', 5, ' ' ); // $ExpectType string
27
- lpad( 'abd', 4, 'x' ); // $ExpectType string
28
- }
29
-
30
- // The compiler throws an error if the function is provided arguments having invalid types...
31
- {
32
- lpad( true, 6, ' ' ); // $ExpectError
33
- lpad( false, 6, ' ' ); // $ExpectError
34
- lpad( 3, 6, ' ' ); // $ExpectError
35
- lpad( [], 6, ' ' ); // $ExpectError
36
- lpad( {}, 6, ' ' ); // $ExpectError
37
- lpad( ( x: number ): number => x, 6, ' ' ); // $ExpectError
38
-
39
- lpad( 'abd', true, ' ' ); // $ExpectError
40
- lpad( 'abd', false, ' ' ); // $ExpectError
41
- lpad( 'abd', 'abc', ' ' ); // $ExpectError
42
- lpad( 'abd', [], 0, ' ' ); // $ExpectError
43
- lpad( 'abd', {}, 0, ' ' ); // $ExpectError
44
- lpad( 'abd', ( x: number ): number => x, 0, ' ' ); // $ExpectError
45
-
46
- lpad( 'abd', 6, true ); // $ExpectError
47
- lpad( 'abd', 6, false ); // $ExpectError
48
- lpad( 'abd', 6, 123 ); // $ExpectError
49
- lpad( 'abd', 6, [] ); // $ExpectError
50
- lpad( 'abd', 6, {} ); // $ExpectError
51
- lpad( 'abd', 6, /[a-z]/ ); // $ExpectError
52
- }
53
-
54
- // The compiler throws an error if the function is provided insufficient arguments...
55
- {
56
- lpad(); // $ExpectError
57
- lpad( 'abc' ); // $ExpectError
58
- lpad( 'abc', 6 ); // $ExpectError
59
- }