Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Mar 6, 2022
1 parent 4e4fe0c commit 8115bae
Show file tree
Hide file tree
Showing 24 changed files with 2,944 additions and 10 deletions.
1 change: 0 additions & 1 deletion .github/.keepalive

This file was deleted.

13 changes: 11 additions & 2 deletions .github/workflows/bundle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ jobs:
# 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 deno.land link:
find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ <reference types=\"@stdlib\/types\"\/>/\/\/\/ <reference types=\"https:\/\/deno.land\/x\/stdlib_types\/index.d.ts\"\/>/g"
# Replace reference to `@stdlib/types` with CDN link:
find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ <reference types=\"@stdlib\/types\"\/>/\/\/\/ <reference types=\"https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/types@main\/index.d.ts\"\/>/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"
Expand All @@ -83,6 +83,9 @@ jobs:
find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?<section class=\"cli\">[\s\S]+<\!\-\- \/.cli \-\->//g"
find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?<section class=\"c\">[\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
- name: Publish to deno branch
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down Expand Up @@ -152,6 +155,9 @@ jobs:
# Wrap contents of `<script type="text/javascript">` tag contents in an IIFE:
find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<script type=\"text\/javascript\">([\s\S]+?)<\/script>/<script type=\"text\/javascript\">\n\(function \(\) {\1}\)\(\)\n<\/script>/g"
# Create package.json file for umd branch:
jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "main": "./bundle.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./umd/package.json
- name: Publish to umd branch
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down Expand Up @@ -227,6 +233,9 @@ jobs:
# Rewrite examples section to be a HTML file:
find ./esm -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\#\# Examples([\s\S]*)\`\`\`javascript([\s\S]+?)\`\`\`/\#\# Examples\1\`\`\`html\n<\!DOCTYPE html>\n<html lang=\"en\">\n<body>\n<script type=\"module\">\n\2\n<\/script>\n<\/body>\n<\/html>\n\`\`\`/g"
# Create package.json file for esm branch:
jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./index.mjs", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./esm/package.json
- name: Publish to esm branch
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,30 @@ jobs:
steps: ${{ toJson(steps) }}
channel: '#npm-ci'
if: failure()
increment:
runs-on: ubuntu-latest
steps:
- name: Checkout main branch
uses: actions/checkout@v2
with:
ref: main
- name: Increment version in `package.json` to the version number of the tag
run: |
VERSION=$(echo ${{ github.ref }} | sed -E 's/refs\/tags\/v?([0-9]+.[0-9]+.[0-9]+).*/\1/')
sed -Ei "s/\"version\": \"[^\"]+\"/\"version\": \"$VERSION\"/g" package.json
- name: Configure git
run: |
git config --local user.email "[email protected]"
git config --local user.name "stdlib-bot"
- name: Commit changes
run: |
git add package.json
git commit -m "Auto-generated commit"
- name: Push changes
run: |
SLUG=${{ github.repository }}
echo "Pushing changes to $SLUG..."
git push "https://$GITHUB_ACTOR:[email protected]/$SLUG.git" main
cancel:
runs-on: ubuntu-latest
timeout-minutes: 3
Expand Down
99 changes: 99 additions & 0 deletions .github/workflows/test_bundles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#/
# @license Apache-2.0
#
# Copyright (c) 2022 The Stdlib Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#/

# Workflow name:
name: Test Loading Bundles

# Workflow triggers:
on:
workflow_run:
workflows: ["bundle"]
types: [completed]
workflow_dispatch:

# Workflow jobs:
jobs:
test-umd:
runs-on: ubuntu-latest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
steps:
- name: Checkout branch with UMD build
uses: actions/checkout@v2
with:
ref: umd
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 17
- name: Try loading UMD module
run: |
node --eval "require( './bundle.js' )" || exit $?
- 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()
test-esm:
runs-on: ubuntu-latest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
steps:
- name: Checkout branch with ESM build
uses: actions/checkout@v2
with:
ref: esm
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 17
- name: Try loading ESM
run: |
node --experimental-network-imports --eval "import( './index.mjs' )" || exit $?
- 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()
test-deno:
runs-on: ubuntu-latest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
steps:
- name: Checkout branch with Deno build
uses: actions/checkout@v2
with:
ref: deno
- name: Install Deno
uses: denoland/setup-deno@v1
with:
deno-version: vx.x.x
- name: Try loading Deno build
run: |
deno eval "import main from './mod.js'" || exit $?
- 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()
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,20 @@ Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
-->

[umd]: https://github.com/umdjs/umd
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules

[deno-url]: https://github.com/stdlib-js/string/tree/deno
[umd-url]: https://github.com/stdlib-js/string/tree/umd
[esm-url]: https://github.com/stdlib-js/string/tree/esm

[chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
[chat-url]: https://gitter.im/stdlib-js/stdlib/

[stdlib]: https://github.com/stdlib-js/stdlib

[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors

[umd]: https://github.com/umdjs/umd
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules

[deno-url]: https://github.com/stdlib-js/string/tree/deno
[umd-url]: https://github.com/stdlib-js/string/tree/umd
[esm-url]: https://github.com/stdlib-js/string/tree/esm

[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/string/main/LICENSE

<!-- <toc-links> -->
Expand Down
9 changes: 9 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,15 @@ setReadOnly( string, 'snakecase', require( './../snakecase' ) );
*/
setReadOnly( string, 'splitGraphemeClusters', require( './../split-grapheme-clusters' ) );

/**
* @name sprintf
* @memberof string
* @readonly
* @type {Function}
* @see {@link module:@stdlib/string/sprintf}
*/
setReadOnly( string, 'sprintf', require( './../sprintf' ) );

/**
* @name startcase
* @memberof string
Expand Down
115 changes: 115 additions & 0 deletions sprintf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<!--
@license Apache-2.0
Copyright (c) 2022 The Stdlib Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

# sprintf

> Insert supplied variable values into a format string.
<section class="intro">

</section>

<!-- /.intro -->

<section class="usage">

## Usage

```javascript
var sprintf = require( '@stdlib/string/sprintf' );
```

#### sprintf( str, ...args )

Inserts supplied variable values into a format string.

```javascript
var str = 'Hello, %s! My name is %s.';
var out = sprintf( str, 'world', 'Bob' );
// returns 'Hello, world! My name is Bob.'
```

The format string is a string literal containing zero or more conversion specifications, each of which results in a string value being inserted to the output string. A conversion specification consists of a percent sign (`%`) followed by one or more of the following flags, width, precision, and conversion type characters:

| type | description | notes |
| ---- | -------------------------| ------------ |
| s | string | |
| c | character | |
| d | signed decimal integer | |
| i | signed decimal integer | |
| u | unsigned decimal integer | |
| b | unsigned binary integer | |
| o | unsigned octal integer | |
| x | unsigned hexadecimal | |
| X | unsigned hexadecimal | |
| f | floating point | |
| e | floating point | |
| E | floating point | |
| g | floating point | |
| G | floating point | |

</section>

<!-- /.usage -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var sprintf = require( '@stdlib/string/sprintf' );

var out = sprintf( '%s %s!', 'Hello', 'World' );
// returns 'Hello World!'

out = sprintf( 'Pi: ~%.2f', 3.141592653589793 );
// returns 'Pi: ~3.14'

out = sprintf( '%-10s %-10s', 'a', 'b' );
// returns 'a b '

out = sprintf( '%10s %10s', 'a', 'b' );
// returns ' a b'

out = sprintf( '%2$s %1$s %3$s', 'b', 'a', 'c' );
// returns 'a b c'
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

</section>

<!-- /.links -->
Loading

0 comments on commit 8115bae

Please sign in to comment.