diff --git a/lib/node_modules/@stdlib/regexp/duration-string/README.md b/lib/node_modules/@stdlib/regexp/duration-string/README.md new file mode 100644 index 000000000000..57543321124a --- /dev/null +++ b/lib/node_modules/@stdlib/regexp/duration-string/README.md @@ -0,0 +1,160 @@ + + +# reDurationString + +> [Regular expression][mdn-regexp] to match a duration string. + +
+ +## Usage + +```javascript +var reDurationString = require( '@stdlib/regexp/duration-string' ); +``` + +#### reDurationString() + +Returns a [regular expression][mdn-regexp] to match a duration string. + +```javascript +var RE_DURATION = reDurationString(); +// returns + +var parts = RE_DURATION.exec( '3d2ms' ); +/* returns + [ + '3d2ms', + '3d', + undefined, + undefined, + undefined, + '2ms', + index: 0, + input: '3d2ms', + groups: undefined + ] +*/ + +parts = RE_SEMVER.exec( '4h3m20s' ); +/* returns + [ + '4h3m20s', + undefined, + '4h', + '3m', + '20s', + undefined, + index: 0, + input: '4h3m20s', + groups: undefined + ] +*/ +``` + +#### reDurationString.REGEXP + +[Regular expression][mdn-regexp] to match a duration string. + +```javascript +var bool = reDurationString.REGEXP.test( '3d12h' ); +// returns true +``` + +
+ + + +
+ +## Notes + +- A duration string is a string containing a sequence of time units. A time unit is a nonnegative integer followed by a unit identifier. The following unit identifiers are supported: + + - `d`: days + - `h`: hours + - `m`: minutes + - `s`: seconds + - `ms`: milliseconds + + For example, the string `1m3s10ms` is a duration string containing three time units: `1m` (1 minute), `3s` (3 seconds), and `10ms` (10 milliseconds). The string `60m` is a duration string containing a single time unit: `60m` (60 minutes). Time units must be supplied in descending order of magnitude (i.e., days, hours, minutes, seconds, milliseconds). + +- Duration strings are case insensitive. For example, the string `1M3S10MS` is equivalent to `1m3s10ms`. + +- The regular expression captures the following groups: + + 1. The days component. + 2. The hours component. + 3. The minutes component. + 4. The seconds component. + 5. The milliseconds component. + +
+ + + +
+ +## Examples + + + +```javascript +var reDurationString = require( '@stdlib/regexp/duration-string' ); + +var RE_DURATION = reDurationString(); + +var bool = RE_DURATION.test( '3d12h' ); +// returns true + +bool = RE_DURATION.test( '1M3S10MS' ); +// returns true + +bool = RE_DURATION.test( '1y.0w.0d' ); +// returns false + +bool = RE_DURATION.test( '1y3w' ); +// returns false + +bool = RE_DURATION.test( 'beep' ); +// returns false +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/regexp/duration-string/benchmark/benchmark.js b/lib/node_modules/@stdlib/regexp/duration-string/benchmark/benchmark.js new file mode 100644 index 000000000000..081e7be95aef --- /dev/null +++ b/lib/node_modules/@stdlib/regexp/duration-string/benchmark/benchmark.js @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var reDurationString = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + '3d', + '3d2h', + '21h', + '21h3m', + '3m30s', + '3m', + '3m30ms', + '3m30s40ms', + '40ms', + '3d4m', + '3d4m30s', + '3d4m30s40ms', + '3d4h5m6s7ms', + '1.0.0', + '3 days', + '3 days 2 hours', + 'beep boop', + '3d 2h' + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = reDurationString.REGEXP.test( values[ i%values.length ] ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/regexp/duration-string/docs/repl.txt b/lib/node_modules/@stdlib/regexp/duration-string/docs/repl.txt new file mode 100644 index 000000000000..9c753c531c1e --- /dev/null +++ b/lib/node_modules/@stdlib/regexp/duration-string/docs/repl.txt @@ -0,0 +1,57 @@ + +{{alias}}() + Returns a regular expression to match a duration string. + + A duration string is a string containing a sequence of time units. A time + unit is a nonnegative integer followed by a unit identifier. The following + unit identifiers are supported: + + - d: days + - h: hours + - m: minutes + - s: seconds + - ms: milliseconds + + For example, the string `1m3s10ms` is a duration string containing three + time units: `1m` (1 minute), `3s` (3 seconds), and `10ms` (10 milliseconds). + The string `60m` is a duration string containing a single time unit: `60m` + (60 minutes). Time units must be supplied in descending order of magnitude + (i.e., days, hours, minutes, seconds, milliseconds). + + Duration strings are case insensitive. For example, the string `1M3S10MS` is + equivalent to `1m3s10ms`. + + The regular expression captures the following groups: + + 1. The days component. + 2. The hours component. + 3. The minutes component. + 4. The seconds component. + 5. The milliseconds component. + + Returns + ------- + re: RegExp: Regular expression + Regular expression to match a duration string. + + Examples + -------- + > var RE = {{alias}}(); + > var parts = RE.exec( '3d2ms' ) + [...] + > parts = RE.exec( '4h3m20s' ) + [...] + + +{{alias}}.REGEXP + Regular expression to match a duration string. + + Examples + -------- + > var bool = {{alias}}.REGEXP.test( '3d2ms' ) + true + > bool = {{alias}}.REGEXP.test( 'foo' ) + false + + See Also + -------- diff --git a/lib/node_modules/@stdlib/regexp/duration-string/docs/types/index.d.ts b/lib/node_modules/@stdlib/regexp/duration-string/docs/types/index.d.ts new file mode 100644 index 000000000000..68fe26612e52 --- /dev/null +++ b/lib/node_modules/@stdlib/regexp/duration-string/docs/types/index.d.ts @@ -0,0 +1,106 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2022 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 + +/** +* Interface for a regular expression to match duration strings. +*/ +interface ReDurationString { + /** + * Returns a regular expression to match a duration string. + * + * @returns regular expression + * + * @example + * var RE_DURATION = reDurationString(); + * // returns + * + * var bool = RE_DURATION.test( '20ms' ); + * // returns true + * + * bool = RE_DURATION.test( '3d21h' ); + * // returns true + * + * bool = RE_DURATION.test( '2s 40ms' ); + * // returns false + * + * bool = RE_DURATION.test( '20' ); + * // returns false + */ + (): RegExp; + + /** + * Regular expression to match a duration string. + * + * @example + * var bool = reDurationString.REGEXP.test( '3m20s40ms' ); + * // returns true + */ + REGEXP: RegExp; +} + +/** +* Returns a regular expression to match a duration string. +* +* ## Notes +* +* - A duration string is a string containing a sequence of time units. A time unit is a nonnegative integer followed by a unit identifier. The following unit identifiers are supported: +* +* - `d`: days +* - `h`: hours +* - `m`: minutes +* - `s`: seconds +* - `ms`: milliseconds +* +* For example, the string `1m3s10ms` is a duration string containing three time units: `1m` (1 minute), `3s` (3 seconds), and `10ms` (10 milliseconds). The string `60m` is a duration string containing a single time unit: `60m` (60 minutes). Time units must be supplied in descending order of magnitude (i.e., days, hours, minutes, seconds, milliseconds). +* +* - Duration strings are case insensitive. For example, the string `1M3S10MS` is equivalent to `1m3s10ms`. +* +* - The regular expression captures the following groups: +* +* 1. The days component. +* 2. The hours component. +* 3. The minutes component. +* 4. The seconds component. +* 5. The milliseconds component. +* +* @returns regular expression +* +* @example +* var RE_DURATION = reDurationString(); +* // returns +* +* var bool = RE_DURATION.test( '3d23h' ); +* // returns true +* +* bool = RE_DURATION.test( '2H30M' ); +* // returns true +* +* bool = RE_DURATION.test( 'abc' ); +* // returns false +* +* bool = RE_DURATION.test( 'foo bar' ); +* // returns false +*/ +declare var reDurationString: ReDurationString; + + +// EXPORTS // + +export = reDurationString; diff --git a/lib/node_modules/@stdlib/regexp/duration-string/docs/types/test.ts b/lib/node_modules/@stdlib/regexp/duration-string/docs/types/test.ts new file mode 100644 index 000000000000..3422d9cd8580 --- /dev/null +++ b/lib/node_modules/@stdlib/regexp/duration-string/docs/types/test.ts @@ -0,0 +1,39 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2022 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 reDurationString = require( './index' ); + + +// TESTS // + +// The function returns a regular expression... +{ + reDurationString(); // $ExpectType RegExp +} + +// The compiler throws an error if the function is provided arguments... +{ + reDurationString( true ); // $ExpectError + reDurationString( [], 123 ); // $ExpectError +} + +// Attached to main export is a `REGEXP` property whose value is a regular expression... +{ + // tslint:disable-next-line:no-unused-expression + reDurationString.REGEXP; // $ExpectType RegExp +} diff --git a/lib/node_modules/@stdlib/regexp/duration-string/examples/index.js b/lib/node_modules/@stdlib/regexp/duration-string/examples/index.js new file mode 100644 index 000000000000..f5c325165e2b --- /dev/null +++ b/lib/node_modules/@stdlib/regexp/duration-string/examples/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 reDurationString = require( './../lib' ); + +var RE_DURATION = reDurationString(); + +var bool = RE_DURATION.test( '3d12h' ); +console.log( bool ); +// => true + +bool = RE_DURATION.test( '1M3S10MS' ); +console.log( bool ); +// => true + +bool = RE_DURATION.test( '1y.0w.0d' ); +console.log( bool ); +// => false + +bool = RE_DURATION.test( '1y3w' ); +console.log( bool ); +// => false + +bool = RE_DURATION.test( 'beep' ); +console.log( bool ); +// => false diff --git a/lib/node_modules/@stdlib/regexp/duration-string/lib/index.js b/lib/node_modules/@stdlib/regexp/duration-string/lib/index.js new file mode 100644 index 000000000000..836fbcd4579f --- /dev/null +++ b/lib/node_modules/@stdlib/regexp/duration-string/lib/index.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +/** +* Regular expression to match a duration string. +* +* @module @stdlib/regexp/duration-string +* +* @example +* var reDurationString = require( '@stdlib/regexp/duration-string' ); +* +* var RE_DURATION = reDurationString(); +* // returns +* +* var parts = RE_DURATION.exec( '3d2ms' ); +* // returns [...] +* +* parts = RE_DURATION.exec( '2ms' ); +* // returns [...] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var REGEXP = require( './regexp.js' ); + + +// MAIN // + +setReadOnly( main, 'REGEXP', REGEXP ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/regexp/duration-string/lib/main.js b/lib/node_modules/@stdlib/regexp/duration-string/lib/main.js new file mode 100644 index 000000000000..ee87177d2766 --- /dev/null +++ b/lib/node_modules/@stdlib/regexp/duration-string/lib/main.js @@ -0,0 +1,61 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; + +// MAIN // + +/** +* Returns a regular expression to match a duration string. +* +* ## Notes +* +* - A duration string is a string containing a sequence of time units. A time unit is a nonnegative integer followed by a unit identifier. The following unit identifiers are supported: +* +* - `d`: days +* - `h`: hours +* - `m`: minutes +* - `s`: seconds +* - `ms`: milliseconds +* +* For example, the string `1m3s10ms` is a duration string containing three time units: `1m` (1 minute), `3s` (3 seconds), and `10ms` (10 milliseconds). The string `60m` is a duration string containing a single time unit: `60m` (60 minutes). Time units must be supplied in descending order of magnitude (i.e., days, hours, minutes, seconds, milliseconds). +* +* - Duration strings are case insensitive. For example, the string `1M3S10MS` is equivalent to `1m3s10ms`. +* +* - The regular expression captures the following groups: +* +* 1. The days component. +* 2. The hours component. +* 3. The minutes component. +* 4. The seconds component. +* 5. The milliseconds component. +* +* @returns {RegExp} regular expression +* +* @example +* var RE_DURATION = reDurationString(); +* // returns +*/ +function reDurationString() { + return /^(\d+d)?(\d+h)?(\d+m)?(\d+s)?(\d+ms)?$/i; +} + + +// EXPORTS // + +module.exports = reDurationString; diff --git a/lib/node_modules/@stdlib/regexp/duration-string/lib/regexp.js b/lib/node_modules/@stdlib/regexp/duration-string/lib/regexp.js new file mode 100644 index 000000000000..73d75c7454e5 --- /dev/null +++ b/lib/node_modules/@stdlib/regexp/duration-string/lib/regexp.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 reDurationString = require( './main.js' ); + + +// MAIN // + +/** +* Matches a duration string. +* +* Regular Expression: `/^(\d+d)?(\d+h)?(\d+m)?(\d+s)?(\d+ms)?$/` +* +* - `^` +* - start of input +* +* - `(\d+d)?` +* - capture a group of one or more digits followed by the literal character `d` for the number of days (optional) + +* - `(\d+h)?` +* - capture a group of one or more digits followed by the literal character `h` for the number of hours (optional) + +* - `(\d+m)?` +* - capture a group of one or more digits followed by the literal character `m` for the number of minutes (optional) + +* - `(\d+s)?` +* - capture a group of one or more digits followed by the literal character `s` for the number of seconds (optional) + +* - `(\d+ms)?` +* - capture a group of one or more digits followed by the literal character `ms` for the number of milliseconds (optional) +* +* - `$` +* - end of input +* +* @constant +* @type {RegExp} +* @default /^(\d+d)?(\d+h)?(\d+m)?(\d+s)?(\d+ms)?$/ +*/ +var RE_DURATION = reDurationString(); + + +// EXPORTS // + +module.exports = RE_DURATION; diff --git a/lib/node_modules/@stdlib/regexp/duration-string/package.json b/lib/node_modules/@stdlib/regexp/duration-string/package.json new file mode 100644 index 000000000000..a4d4a7fb3f61 --- /dev/null +++ b/lib/node_modules/@stdlib/regexp/duration-string/package.json @@ -0,0 +1,62 @@ +{ + "name": "@stdlib/regexp/duration-string", + "version": "0.0.0", + "description": "Regular expression to match a duration 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": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "regex", + "regexp", + "re", + "regular", + "expression", + "duration", + "string", + "match" + ] +} diff --git a/lib/node_modules/@stdlib/regexp/duration-string/test/test.js b/lib/node_modules/@stdlib/regexp/duration-string/test/test.js new file mode 100644 index 000000000000..ab3ad851120f --- /dev/null +++ b/lib/node_modules/@stdlib/regexp/duration-string/test/test.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 isRegExp = require( '@stdlib/assert/is-regexp' ); +var reDurationString = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.equal( typeof reDurationString, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a regular expression', function test( t ) { + t.equal( isRegExp( reDurationString.REGEXP ), true, 'exports a regular expression' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/regexp/duration-string/test/test.main.js b/lib/node_modules/@stdlib/regexp/duration-string/test/test.main.js new file mode 100644 index 000000000000..36f0961c7b80 --- /dev/null +++ b/lib/node_modules/@stdlib/regexp/duration-string/test/test.main.js @@ -0,0 +1,100 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 reDurationString = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.equal( typeof reDurationString, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the returned regular expression matches a duration string', function test( t ) { + var values; + var RE; + var i; + + RE = reDurationString(); + values = [ + '3d', + '3d2h', + '21h', + '21h3m', + '3m30s', + '3m', + '3m30ms', + '3m30s40ms', + '40ms', + '3d4m', + '3d4m30s', + '3d4m30s40ms', + '3d4h5m6s7ms', + '3D', + '3D2h', + '21H', + '21h3M', + '3M30S', + '3M', + '3M30MS', + '3M30S40MS', + '40MS', + '3D4M', + '3D4M30S', + '3D4M30S40MS', + '3D4H5M6S7MS' + ]; + for ( i = 0; i < values.length; i++ ) { + t.equal( RE.test( values[i] ), true, 'returns expected value when provided '+values[i] ); + } + t.end(); +}); + +tape( 'the returned regular expression matches an empty string', function test( t ) { + var RE = reDurationString(); + t.equal( RE.test( '' ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the returned regular expression does not match a non-duration string', function test( t ) { + var values; + var RE; + var i; + + RE = reDurationString(); + values = [ + '1.0.0', + '3 days', + '3 days 2 hours', + 'beep boop', + '3d 2h', + 'foo' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.equal( RE.test( values[i] ), false, 'returns expected value when provided '+values[i] ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/regexp/duration-string/test/test.regexp.js b/lib/node_modules/@stdlib/regexp/duration-string/test/test.regexp.js new file mode 100644 index 000000000000..b4513315fd02 --- /dev/null +++ b/lib/node_modules/@stdlib/regexp/duration-string/test/test.regexp.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 RE = require( './../lib/regexp.js' ); + + +// TESTS // + +tape( 'main export is a regular expression', function test( t ) { + t.ok( true, __filename ); + t.equal( RE instanceof RegExp, true, 'main export is a regular expression' ); + t.end(); +}); + +tape( 'the regular expression matches valid duration strings', function test( t ) { + var values; + var i; + + values = [ + '3d', + '3d2h', + '21h', + '21h3m', + '3m30s', + '3m', + '3m30ms', + '3m30s40ms', + '40ms', + '3d4m', + '3d4m30s', + '3d4m30s40ms', + '3d4h5m6s7ms', + '3D', + '3D2h', + '21H', + '21h3M', + '3M30S', + '3M', + '3M30MS', + '3M30S40MS', + '40MS', + '3D4M', + '3D4M30S', + '3D4M30S40MS', + '3D4H5M6S7MS' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.equal( RE.test( values[i] ), true, 'returns expected value when provided '+values[i] ); + } + t.end(); +}); + +tape( 'the regular expression matches an empty string', function test( t ) { + t.equal( RE.test( '' ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the regular expression does not match invalid duration strings', function test( t ) { + var values; + var i; + + values = [ + '1.0.0', + '3 days', + '3 days 2 hours', + 'beep boop', + '3d 2h', + 'foo' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.equal( RE.test( values[i] ), false, 'returns expected value when provided '+values[i] ); + } + t.end(); +});