Skip to content

Commit 18daa6c

Browse files
committed
Auto-generated commit
1 parent c9ef7f4 commit 18daa6c

File tree

9 files changed

+108
-51
lines changed

9 files changed

+108
-51
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,8 @@ indent_size = 2
179179
[*.gypi]
180180
indent_style = space
181181
indent_size = 2
182+
183+
# Set properties for citation files:
184+
[*.{cff,cff.txt}]
185+
indent_style = space
186+
indent_size = 2

.github/workflows/productionize.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,6 @@ jobs:
8282
id: transform-error-messages
8383
uses: stdlib-js/transform-errors-action@main
8484

85-
# Format error messages:
86-
- name: 'Replace double quotes with single quotes in rewritten format string error messages'
87-
run: |
88-
find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \;
89-
90-
# Format string literal error messages:
91-
- name: 'Replace double quotes with single quotes in rewritten string literal error messages'
92-
run: |
93-
find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \;
94-
95-
# Format code:
96-
- name: 'Replace double quotes with single quotes in inserted `require` calls'
97-
run: |
98-
find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \;
99-
10085
# Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency:
10186
- name: 'Update dependencies in package.json'
10287
run: |

CITATION.cff

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ limitations under the License.
1818
1919
-->
2020

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+
2132
# countByAsync
2233

2334
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->

dist/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// <reference path="../docs/types/index.d.ts" />
2+
import countByAsync from '../docs/types/index';
3+
export = countByAsync;

dist/index.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/types/index.d.ts

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
* limitations under the License.
1717
*/
1818

19-
// TypeScript Version: 2.0
19+
// TypeScript Version: 4.1
2020

2121
/// <reference types="@stdlib/types"/>
2222

23-
import { Collection } from '@stdlib/types/object';
23+
import { Collection } from '@stdlib/types/array';
2424

2525
/**
2626
* Interface defining function options.
2727
*/
28-
interface Options {
28+
interface Options<T, V> {
2929
/**
3030
* The maximum number of pending invocations at any one time.
3131
*/
@@ -39,109 +39,119 @@ interface Options {
3939
/**
4040
* Execution context.
4141
*/
42-
thisArg?: any;
42+
thisArg?: ThisParameterType<Indicator<T, V>>;
43+
}
44+
45+
/**
46+
* Interface defining a results object.
47+
*/
48+
interface Results {
49+
/**
50+
* Results for an individual group.
51+
*/
52+
[ key: string ]: number;
4353
}
4454

4555
/**
4656
* Callback invoked either upon processing all collection elements or upon encountering an error.
4757
*/
48-
type DoneNullary = () => void;
58+
type Nullary = () => void;
4959

5060
/**
5161
* Callback invoked either upon processing all collection elements or upon encountering an error.
5262
*
5363
* @param error - encountered error or null
5464
*/
55-
type DoneUnary = ( error: Error | null ) => void;
65+
type Unary = ( error: Error | null ) => void;
5666

5767
/**
5868
* Callback invoked either upon processing all collection elements or upon encountering an error.
5969
*
6070
* @param error - encountered error or null
6171
* @param result - counts
6272
*/
63-
type DoneBinary = ( error: Error | null, result: any ) => void;
73+
type Binary = ( error: Error | null, result: Results ) => void;
6474

6575
/**
6676
* Callback invoked either upon processing all collection elements or upon encountering an error.
6777
*
6878
* @param error - encountered error or null
6979
* @param result - counts
7080
*/
71-
type DoneCallback = DoneNullary | DoneUnary | DoneBinary;
81+
type Callback = Nullary | Unary | Binary;
7282

7383
/**
74-
* Callback function.
84+
* Callback function to invoke once the predicate function has finished processing a collection value.
7585
*/
76-
type Nullary = () => void;
86+
type NullaryNext = () => void;
7787

7888
/**
79-
* Callback function.
89+
* Callback function to invoke once the predicate function has finished processing a collection value.
8090
*
8191
* @param error - encountered error or null
8292
*/
83-
type Unary = ( error: Error | null ) => void;
93+
type UnaryNext = ( error: Error | null ) => void;
8494

8595
/**
86-
* Callback function.
96+
* Callback function to invoke once the predicate function has finished processing a collection value.
8797
*
8898
* @param error - encountered error or null
8999
* @param group - value group
90100
*/
91-
type Binary = ( error: Error | null, group: string ) => void;
101+
type BinaryNext = ( error: Error | null, group: string | Symbol | number ) => void;
92102

93103
/**
94-
* Callback function.
104+
* Callback function to invoke once the predicate function has finished processing a collection value.
95105
*
96106
* @param error - encountered error or null
97107
* @param group - value group
98108
*/
99-
type Callback = Nullary | Unary | Binary;
109+
type Next = NullaryNext | UnaryNext | BinaryNext;
100110

101111
/**
102-
* Checks whether an element in a collection passes a test.
112+
* Returns the group to which a collection element belongs.
103113
*
104114
* @param value - collection value
105115
* @param next - a callback to be invoked after processing a collection `value`
106116
*/
107-
type BinaryIndicator = ( value: any, next: Callback ) => void;
117+
type BinaryIndicator<T, V> = ( this: V, value: T, next: Next ) => void;
108118

109119
/**
110-
* Checks whether an element in a collection passes a test.
120+
* Returns the group to which a collection element belongs.
111121
*
112122
* @param value - collection value
113123
* @param index - collection index
114124
* @param next - a callback to be invoked after processing a collection `value`
115125
*/
116-
type TernaryIndicator = ( value: any, index: number, next: Callback ) => void;
126+
type TernaryIndicator<T, V> = ( this: V, value: T, index: number, next: Next ) => void;
117127

118128
/**
119-
* Checks whether an element in a collection passes a test.
129+
* Returns the group to which a collection element belongs.
120130
*
121131
* @param value - collection value
122132
* @param index - collection index
123133
* @param collection - input collection
124134
* @param next - a callback to be invoked after processing a collection `value`
125135
*/
126-
type QuaternaryIndicator = ( value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length
136+
type QuaternaryIndicator<T, V> = ( this: V, value: T, index: number, collection: Collection<T>, next: Next ) => void;
127137

128138
/**
129-
* Checks whether an element in a collection passes a test.
139+
* Returns the group to which a collection element belongs.
130140
*
131141
* @param value - collection value
132142
* @param index - collection index
133143
* @param collection - input collection
134144
* @param next - a callback to be invoked after processing a collection `value`
135145
*/
136-
type Indicator = Unary | BinaryIndicator | TernaryIndicator | QuaternaryIndicator; // tslint-disable-line max-line-length
146+
type Indicator<T, V> = BinaryIndicator<T, V> | TernaryIndicator<T, V> | QuaternaryIndicator<T, V>;
137147

138148
/**
139149
* Invokes an indicator function for each element in a collection.
140150
*
141151
* @param collection - input collection
142152
* @param done - function to invoke upon completion
143153
*/
144-
type FactoryFunction = ( collection: Collection, done: DoneCallback ) => void;
154+
type FactoryFunction<T> = ( collection: Collection<T>, done: Callback ) => void;
145155

146156
/**
147157
* Interface for `countByAsync`.
@@ -154,7 +164,6 @@ interface CountByAsync {
154164
*
155165
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
156166
*
157-
*
158167
* @param collection - input collection
159168
* @param options - function options
160169
* @param options.thisArg - execution context
@@ -195,7 +204,7 @@ interface CountByAsync {
195204
*
196205
* countByAsync( files, indicator, done );
197206
*/
198-
( collection: Collection, options: Options, indicator: Indicator, done: DoneCallback ): void; // tslint-disable-line max-line-length
207+
<T = unknown, V = unknown>( collection: Collection<T>, options: Options<T, V>, indicator: Indicator<T, V>, done: Callback ): void;
199208

200209
/**
201210
* Groups values according to an indicator function and returns group counts.
@@ -204,7 +213,6 @@ interface CountByAsync {
204213
*
205214
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
206215
*
207-
*
208216
* @param collection - input collection
209217
* @param indicator - indicator function specifying which group an element in the input collection belongs to
210218
* @param done - function to invoke upon completion
@@ -241,7 +249,7 @@ interface CountByAsync {
241249
*
242250
* countByAsync( files, indicator, done );
243251
*/
244-
( collection: Collection, indicator: Indicator, done: DoneCallback ): void;
252+
<T = unknown, V = unknown>( collection: Collection<T>, indicator: Indicator<T, V>, done: Callback ): void; // tslint:disable-line:no-unnecessary-generics
245253

246254
/**
247255
* Returns a function for grouping values according to an indicator function and returns group counts.
@@ -250,7 +258,6 @@ interface CountByAsync {
250258
*
251259
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
252260
*
253-
*
254261
* @param options - function options
255262
* @param options.thisArg - execution context
256263
* @param options.limit - maximum number of pending invocations at any one time
@@ -300,7 +307,7 @@ interface CountByAsync {
300307
* // Try to read each element in `files`:
301308
* countByAsync( files, done );
302309
*/
303-
factory( options: Options, indicator: Indicator ): FactoryFunction;
310+
factory<T = unknown, V = unknown>( options: Options<T, V>, indicator: Indicator<T, V> ): FactoryFunction<T>;
304311

305312
/**
306313
* Returns a function for grouping values according to an indicator function and returns group counts.
@@ -309,7 +316,6 @@ interface CountByAsync {
309316
*
310317
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
311318
*
312-
*
313319
* @param options - function options
314320
* @param options.thisArg - execution context
315321
* @param options.limit - maximum number of pending invocations at any one time
@@ -355,7 +361,7 @@ interface CountByAsync {
355361
* // Try to read each element in `files`:
356362
* countByAsync( files, done );
357363
*/
358-
factory( indicator: Indicator ): FactoryFunction;
364+
factory<T = unknown, V = unknown>( indicator: Indicator<T, V> ): FactoryFunction<T>; // tslint:disable-line:no-unnecessary-generics
359365
}
360366

361367
/**
@@ -365,7 +371,6 @@ interface CountByAsync {
365371
*
366372
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
367373
*
368-
*
369374
* @param collection - input collection
370375
* @param options - function options
371376
* @param options.thisArg - execution context

docs/types/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ const done = ( error: Error | null, result: any ) => {
106106

107107
// Attached to main export is a `factory` method which returns a function...
108108
{
109-
countByAsync.factory( indicator ); // $ExpectType FactoryFunction
110-
countByAsync.factory( { 'series': true }, indicator ); // $ExpectType FactoryFunction
109+
countByAsync.factory( indicator ); // $ExpectType FactoryFunction<number>
110+
countByAsync.factory( { 'series': true }, indicator ); // $ExpectType FactoryFunction<number>
111111
}
112112

113113
// The compiler throws an error if the `factory` method is provided an options argument which is not an object...

0 commit comments

Comments
 (0)