Skip to content

Commit 1861dae

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents 5e547fe + 63aa76b commit 1861dae

File tree

14 files changed

+503
-36
lines changed

14 files changed

+503
-36
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2021 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+
# Workflow name:
20+
name: update_namespace_definitions
21+
22+
# Workflow triggers:
23+
on:
24+
# Allow the workflow to be manually run:
25+
workflow_dispatch:
26+
27+
# Workflow jobs:
28+
jobs:
29+
30+
# Define a job for pushing changes to standalone packages...
31+
update:
32+
33+
# Define a display name:
34+
name: "Update Namespace Typescript Definitions"
35+
36+
# Define the type of virtual host machine:
37+
runs-on: ubuntu-latest
38+
39+
# Define the sequence of job steps...
40+
steps:
41+
42+
# Checkout the repository:
43+
- name: 'Checkout repository'
44+
uses: actions/checkout@v2
45+
with:
46+
# Specify whether to remove untracked files before checking out the repository:
47+
clean: true
48+
49+
# Limit clone depth to the most recent commit:
50+
fetch-depth: 1
51+
52+
# Specify whether to download Git-LFS files:
53+
lfs: false
54+
timeout-minutes: 10
55+
56+
# Install Node.js:
57+
- name: 'Install Node.js'
58+
uses: actions/setup-node@v2
59+
with:
60+
node-version: 15
61+
timeout-minutes: 5
62+
63+
# Install dependencies:
64+
- name: 'Install dependencies'
65+
run: |
66+
make install-node-modules
67+
timeout-minutes: 15
68+
69+
# Update namespace Typescript definitions:
70+
- name: 'Update namespace Typescript definitions'
71+
run: |
72+
make list-pkgs-namespaces | node lib/node_modules/@stdlib/_tools/scripts/create_namespace_types.js
73+
74+
# Create a pull request with the updated definitions:
75+
- name: Create Pull Request
76+
uses: peter-evans/create-pull-request@v3

lib/node_modules/@stdlib/_tools/scripts/create_namespace_types.js

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626

2727
var path = require( 'path' );
2828
var fs = require( 'fs' );
29+
var contains = require( '@stdlib/assert/contains' );
30+
var stdin = require( '@stdlib/process/read-stdin' );
31+
var stdinStream = require( '@stdlib/streams/node/stdin' );
32+
var reEOL = require( '@stdlib/regexp/eol' );
2933
var removePunctuation = require( '@stdlib/string/remove-punctuation' );
3034
var readJSON = require( '@stdlib/fs/read-json' ).sync;
3135
var replace = require( '@stdlib/string/replace' );
@@ -141,12 +145,13 @@ function createDefinitionFile( ns, imports, properties, description ) {
141145
}
142146

143147
/**
144-
* Main execution sequence.
148+
* Creates Typescript definition and test files for the namespace ass.
145149
*
146150
* @private
151+
* @param {string} fullPath - full namespace name
147152
* @returns {void}
148153
*/
149-
function main() {
154+
function create( fullPath ) {
150155
var RE_DOC_MAIN_DECLARE;
151156
var nsIdentifier;
152157
var description;
@@ -156,8 +161,8 @@ function main() {
156161
var properties;
157162
var indexFile;
158163
var tsDefPath;
159-
var fullPath;
160164
var testFile;
165+
var typesDir;
161166
var defFile;
162167
var pkgPath;
163168
var match;
@@ -171,15 +176,17 @@ function main() {
171176
var ns;
172177
var RE;
173178

174-
fullPath = process.argv[ 2 ];
175-
ns = path.basename( fullPath );
176179
importStmts = [];
177180
properties = [];
178181

182+
ns = path.basename( fullPath );
179183
entryPoint = require.resolve( fullPath );
180184
indexFile = fs.readFileSync( entryPoint, 'utf-8' );
181185
console.log( 'Loading '+entryPoint+'...' );
182186

187+
if ( !RE_NAMESPACE.test( indexFile ) ) {
188+
return;
189+
}
183190
nsIdentifier = RE_NAMESPACE.exec( indexFile )[ 1 ];
184191
nsIdentifier = removePunctuation( nsIdentifier );
185192
RE = new RegExp( 'setReadOnly\\( '+nsIdentifier+', \'([a-z0-9_]+)\', require\\( \'([^\']+)\' \\) \\)', 'ig' );
@@ -213,6 +220,15 @@ function main() {
213220
str = replace( str, '\n', '\n\t' );
214221
prop = '\t' + str + '\n' + prop;
215222
}
223+
else {
224+
tsDoc = tsDef.match( /(\/\*\*\n[\s\S]+?\*\/)\nexport =/ );
225+
if ( tsDoc && tsDoc[ 1 ] ) {
226+
str = tsDoc[ 1 ];
227+
str = replace( str, RE_EXAMPLE, onReplace );
228+
str = replace( str, '\n', '\n\t' );
229+
prop = '\t' + str + '\n' + prop;
230+
}
231+
}
216232
match = RE.exec( indexFile );
217233
if ( match ) {
218234
prop += '\n';
@@ -225,13 +241,18 @@ function main() {
225241
fullPath = path.join( entryPoint, '..', '..' );
226242
description = readJSON( path.join( fullPath, 'package.json' ) ).description;
227243

244+
typesDir = path.join( fullPath, 'docs', 'types' );
245+
if ( !fs.existsSync( typesDir ) ) {
246+
return;
247+
}
248+
228249
console.log( 'Writing definition file...' );
229250
defFile = createDefinitionFile( ns, importStmts, properties, description );
230-
fs.writeFileSync( path.join( fullPath, 'docs/types/index.d.ts' ), defFile );
251+
fs.writeFileSync( path.join( typesDir, 'index.d.ts' ), defFile );
231252

232253
console.log( 'Writing test file...' );
233254
testFile = createTestFile( ns );
234-
fs.writeFileSync( path.join( fullPath, 'docs/types/test.ts' ), testFile );
255+
fs.writeFileSync( path.join( typesDir, 'test.ts' ), testFile );
235256

236257
/**
237258
* Replaces variable names inside of example code to use exported namespace methods.
@@ -249,4 +270,40 @@ function main() {
249270
}
250271
}
251272

273+
/**
274+
* Callback invoked upon reading from `stdin`.
275+
*
276+
* @private
277+
* @param {(Error|null)} error - error object
278+
* @param {Buffer} data - data
279+
* @returns {void}
280+
*/
281+
function onRead( error, data ) {
282+
var lines;
283+
var i;
284+
if ( error ) {
285+
return console.error( error.message );
286+
}
287+
lines = data.toString().split( reEOL.REGEXP );
288+
for ( i = 0; i < lines.length; i++ ) {
289+
if ( lines[ i ] && !contains( lines[ i ], '_tools' ) ) {
290+
create( lines[ i ] );
291+
}
292+
}
293+
}
294+
295+
/**
296+
* Main execution sequence.
297+
*
298+
* @private
299+
* @returns {void}
300+
*/
301+
function main() {
302+
// Check if we are receiving data from `stdin`...
303+
if ( !stdinStream.isTTY ) {
304+
return stdin( onRead );
305+
}
306+
create( process.argv[ 2 ] );
307+
}
308+
252309
main();

lib/node_modules/@stdlib/array/docs/types/index.d.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,19 @@ import convertArray = require( '@stdlib/array/convert' );
2828
import convertArraySame = require( '@stdlib/array/convert-same' );
2929
import arrayCtors = require( '@stdlib/array/ctors' );
3030
import DataView = require( '@stdlib/array/dataview' );
31+
import datespace = require( '@stdlib/array/datespace' );
3132
import arrayDataType = require( '@stdlib/array/dtype' );
3233
import arrayDataTypes = require( '@stdlib/array/dtypes' );
3334
import filledarray = require( '@stdlib/array/filled' );
3435
import Float32Array = require( '@stdlib/array/float32' );
3536
import Float64Array = require( '@stdlib/array/float64' );
3637
import iterator2array = require( '@stdlib/array/from-iterator' );
38+
import incrspace = require( '@stdlib/array/incrspace' );
3739
import Int8Array = require( '@stdlib/array/int8' );
3840
import Int16Array = require( '@stdlib/array/int16' );
3941
import Int32Array = require( '@stdlib/array/int32' );
42+
import linspace = require( '@stdlib/array/linspace' );
43+
import logspace = require( '@stdlib/array/logspace' );
4044
import arrayMinDataType = require( '@stdlib/array/min-dtype' );
4145
import arrayNextDataType = require( '@stdlib/array/next-dtype' );
4246
import typedarraypool = require( '@stdlib/array/pool' );
@@ -266,6 +270,36 @@ interface Namespace {
266270
*/
267271
DataView: typeof DataView;
268272

273+
/**
274+
* Generates an array of linearly spaced dates.
275+
*
276+
* @param start - start time as either a `Date` object, Unix timestamp, JavaScript timestamp, or date string
277+
* @param stop - stop time as either a `Date` object, Unix timestamp, JavaScript timestamp, or date string
278+
* @param length - output array length (default: 100)
279+
* @param options - function options
280+
* @param options.round - specifies how sub-millisecond times should be rounded: [ 'floor', 'ceil', 'round' ] (default: 'floor' )
281+
* @throws length argument must a positive integer
282+
* @throws must provide valid options
283+
* @returns array of dates
284+
*
285+
* @example
286+
* var stop = '2014-12-02T07:00:54.973Z';
287+
* var start = new Date( stop ) - 60000;
288+
*
289+
* var arr = ns.datespace( start, stop, 6 );
290+
* // returns [...]
291+
*
292+
* @example
293+
* // Equivalent of Math.ceil():
294+
* var arr = ns.datespace( 1417503655000, 1417503655001, 3, { 'round': 'ceil' } );
295+
* // returns [...]
296+
*
297+
* // Equivalent of Math.round():
298+
* var arr = ns.datespace( 1417503655000, 1417503655001, 3, { 'round': 'round' } );
299+
* // returns [...]
300+
*/
301+
datespace: typeof datespace;
302+
269303
/**
270304
* Returns the data type of an array.
271305
*
@@ -359,6 +393,21 @@ interface Namespace {
359393
*/
360394
iterator2array: typeof iterator2array;
361395

396+
/**
397+
* Generates a linearly spaced numeric array using a provided increment.
398+
*
399+
* @param x1 - first array value
400+
* @param x2 - array element bound
401+
* @param increment - increment (default: 1)
402+
* @throws length of created array must be less than `4294967295` (`2**32 - 1`)
403+
* @returns linearly spaced numeric array
404+
*
405+
* @example
406+
* var arr = ns.incrspace( 0, 11, 2 );
407+
* // returns [ 0, 2, 4, 6, 8, 10 ]
408+
*/
409+
incrspace: typeof incrspace;
410+
362411
/**
363412
* Typed array constructor which returns a typed array representing an array of twos-complement 8-bit signed integers in the platform byte order.
364413
*/
@@ -374,6 +423,36 @@ interface Namespace {
374423
*/
375424
Int32Array: typeof Int32Array;
376425

426+
/**
427+
* Generates a linearly spaced numeric array.
428+
*
429+
* @param x1 - first array value
430+
* @param x2 - last array value
431+
* @param len - length of output array (default: 100)
432+
* @throws third argument must be a nonnegative integer
433+
* @returns linearly spaced numeric array
434+
*
435+
* @example
436+
* var arr = ns.linspace( 0, 100, 6 );
437+
* // returns [ 0, 20, 40, 60, 80, 100 ]
438+
*/
439+
linspace: typeof linspace;
440+
441+
/**
442+
* Generates a logarithmically spaced numeric array.
443+
*
444+
* @param a - exponent of start value
445+
* @param b - exponent of end value
446+
* @param len - length of output array (default: 10)
447+
* @throws third argument must be a nonnegative integer
448+
* @returns logarithmically spaced numeric array
449+
*
450+
* @example
451+
* var arr = ns.logspace( 0, 2, 6 );
452+
* // returns [ 1, ~2.5, ~6.31, ~15.85, ~39.81, 100 ]
453+
*/
454+
logspace: typeof logspace;
455+
377456
/**
378457
* Returns the minimum array data type of the closest "kind" necessary for storing a provided scalar value.
379458
*

lib/node_modules/@stdlib/assert/docs/types/index.d.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import deepEqual = require( '@stdlib/assert/deep-equal' );
2626
import deepHasOwnProp = require( '@stdlib/assert/deep-has-own-property' );
2727
import deepHasProp = require( '@stdlib/assert/deep-has-property' );
2828
import hasArrayBufferSupport = require( '@stdlib/assert/has-arraybuffer-support' );
29+
import hasArrowFunctionSupport = require( '@stdlib/assert/has-arrow-function-support' );
2930
import hasAsyncAwaitSupport = require( '@stdlib/assert/has-async-await-support' );
3031
import hasAsyncIteratorSymbolSupport = require( '@stdlib/assert/has-async-iterator-symbol-support' );
3132
import hasBigIntSupport = require( '@stdlib/assert/has-bigint-support' );
@@ -76,6 +77,7 @@ import isArrayLike = require( '@stdlib/assert/is-array-like' );
7677
import isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' );
7778
import isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' );
7879
import isArrayBufferView = require( '@stdlib/assert/is-arraybuffer-view' );
80+
import isArrowFunction = require( '@stdlib/assert/is-arrow-function' );
7981
import isASCII = require( '@stdlib/assert/is-ascii' );
8082
import isBetween = require( '@stdlib/assert/is-between' );
8183
import isBetweenArray = require( '@stdlib/assert/is-between-array' );
@@ -473,6 +475,17 @@ interface Namespace {
473475
*/
474476
hasArrayBufferSupport: typeof hasArrayBufferSupport;
475477

478+
/**
479+
* Tests for native arrow function support.
480+
*
481+
* @returns boolean indicating if an environment has native arrow function support
482+
*
483+
* @example
484+
* var bool = ns.hasArrowFunctionSupport();
485+
* // returns <boolean>
486+
*/
487+
hasArrowFunctionSupport: typeof hasArrowFunctionSupport;
488+
476489
/**
477490
* Tests for native `async/await` support.
478491
*
@@ -1266,6 +1279,27 @@ interface Namespace {
12661279
*/
12671280
isArrayBufferView: typeof isArrayBufferView;
12681281

1282+
/**
1283+
* Tests if a value is an arrow function.
1284+
*
1285+
* @param value - value to test
1286+
* @returns boolean indicating whether value is an arrow function
1287+
*
1288+
* @example
1289+
* var arrow = () => {};
1290+
* var bool = ns.isArrowFunction( arrow );
1291+
* // returns true
1292+
*
1293+
* @example
1294+
* function beep() {
1295+
* return 'beep';
1296+
* }
1297+
1298+
* var bool = ns.isArrowFunction( beep );
1299+
* // returns false
1300+
*/
1301+
isArrowFunction: typeof isArrowFunction;
1302+
12691303
/**
12701304
* Tests whether a character belongs to the ASCII character set and whether this is true for all characters in a provided string.
12711305
*

lib/node_modules/@stdlib/buffer/docs/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ interface Namespace {
6060
* var ctor = require( `@stdlib/buffer/ctor` );
6161
*
6262
* var b = new ctor( [ 1, 2, 3, 4 ] );
63-
* // returns <Buffer>
63+
* // returns <ns.Buffer>
6464
*/
6565
Buffer: typeof Buffer;
6666

0 commit comments

Comments
 (0)