Skip to content

feat: add assert/is-well-formed-string #1388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3f86dfb
feat: added string/is-well-formed-string
gunjjoshi Feb 26, 2024
6b7d7e9
feat: added assert/is-well-formed-string
gunjjoshi Feb 26, 2024
6cd7771
Update lib/node_modules/@stdlib/assert/is-well-formed-string/README.md
gunjjoshi Feb 27, 2024
bb2f66a
Update package.json
gunjjoshi Feb 27, 2024
e0c96de
Update lib/node_modules/@stdlib/assert/is-well-formed-string/lib/prim…
gunjjoshi Feb 27, 2024
2928ca8
Update lib/node_modules/@stdlib/assert/is-well-formed-string/README.md
gunjjoshi Feb 27, 2024
bb7cbe4
Update lib/node_modules/@stdlib/assert/is-well-formed-string/README.md
gunjjoshi Feb 27, 2024
aa1220a
Update lib/node_modules/@stdlib/assert/is-well-formed-string/README.md
gunjjoshi Feb 27, 2024
522ae16
Update lib/node_modules/@stdlib/assert/is-well-formed-string/README.md
gunjjoshi Feb 27, 2024
0de80cc
Update lib/node_modules/@stdlib/assert/is-well-formed-string/docs/typ…
gunjjoshi Feb 27, 2024
7055a64
Update lib/node_modules/@stdlib/assert/is-well-formed-string/docs/typ…
gunjjoshi Feb 27, 2024
f831f88
Update lib/node_modules/@stdlib/assert/is-well-formed-string/examples…
gunjjoshi Feb 27, 2024
50930f7
Update lib/node_modules/@stdlib/assert/is-well-formed-string/lib/iswe…
gunjjoshi Feb 27, 2024
b458106
Update lib/node_modules/@stdlib/assert/is-well-formed-string/lib/iswe…
gunjjoshi Feb 27, 2024
2c2c6ea
Update lib/node_modules/@stdlib/assert/is-well-formed-string/lib/iswe…
gunjjoshi Feb 27, 2024
9710381
Update lib/node_modules/@stdlib/assert/is-well-formed-string/lib/iswe…
gunjjoshi Feb 27, 2024
a322028
Update lib/node_modules/@stdlib/assert/is-well-formed-string/lib/iswe…
gunjjoshi Feb 27, 2024
e887070
Update lib/node_modules/@stdlib/assert/is-well-formed-string/lib/iswe…
gunjjoshi Feb 27, 2024
8227c93
Update lib/node_modules/@stdlib/assert/is-well-formed-string/lib/iswe…
gunjjoshi Feb 27, 2024
f1542e2
Update iswellformed.js
gunjjoshi Feb 27, 2024
32bf6a4
Update iswellformed.js
gunjjoshi Feb 27, 2024
462cda2
feat: added assert/is-well-formed-string
gunjjoshi Feb 27, 2024
cd5fc1f
Apply suggestions from code review
Planeshifter Feb 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 151 additions & 0 deletions lib/node_modules/@stdlib/assert/is-well-formed-string/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<!--

@license Apache-2.0

Copyright (c) 2024 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.

-->

# isWellFormedString

> Test if a string is well-formed.

<section class="usage">

## Usage

```javascript
var isWellFormedString = require( '@stdlib/assert/is-well-formed-string' );
```

#### isWellFormedString( str )

Tests if a `string` is well-formed.

<!-- eslint-disable no-new-wrappers -->

```javascript
var bool = isWellFormedString( '' );
// returns true

bool = isWellFormedString( new String( '' ) );
// returns true

bool = isWellFormedString( '\uDBFF' );
// returns false

bool = isWellFormedString( '\uDBFFFF\uDBFF' );
// returns false

bool = isWellFormedString( [] );
// returns false

bool = isWellFormedString( '-5' );
// returns true

bool = isWellFormedString( null );
// returns false
```

#### isWellFormedString.isPrimitive( str )

Tests if a `string` is a well-formed `string` primitive.

<!-- eslint-disable no-new-wrappers -->

```javascript
var bool = isWellFormedString.isPrimitive( '' );
// returns true

bool = isWellFormedString.isPrimitive( new String( '' ) );
// returns false
```

#### isWellFormedString.isObject( str )

Tests if a `string` is a well-formed `String` object.

<!-- eslint-disable no-new-wrappers -->

```javascript
var bool = isWellFormedString.isObject( '' );
// returns false

bool = isWellFormedString.isObject( new String( '' ) );
// returns true
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

<!-- eslint-disable no-new-wrappers -->

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

```javascript
var isWellFormedString = require( '@stdlib/assert/is-well-formed-string' );

var bool = isWellFormedString( '' );
// returns true

bool = isWellFormedString( new String( '' ) );
// returns true

bool = isWellFormedString( '\uDBFF' );
// returns false

bool = isWellFormedString( '\uDBFF\uDBFF' );
// returns false

bool = isWellFormedString( [] );
// returns false

bool = isWellFormedString( '-5' );
// returns true

bool = isWellFormedString( null );
// returns false
```

</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">

<!-- <related-links> -->


<!-- </related-links> -->

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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.
*/

/* eslint-disable no-new-wrappers, no-undefined, no-empty-function */

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var isWellFormedString = require( './../lib' );


// MAIN //

bench( pkg+'::primitives', function benchmark( b ) {
var strs;
var bool;
var i;

strs = [
'',
'\uDBFF',
'Hello World',
'3.14',
'\uDBFF\uDBFF',
-4.0,
NaN,
true,
false,
null,
undefined
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isWellFormedString( strs[ i % strs.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();
});

bench( pkg+'::objects', function benchmark( b ) {
var strs;
var bool;
var i;

strs = [
[],
{},
function noop() {},
new String( '' ),
new String( '\uDBFF' ),
new String( '\uDBFFFF\uDBFF' )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isWellFormedString( strs[ i % strs.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();
});

bench( pkg+'::primitives:isPrimitive', function benchmark( b ) {
var strs;
var bool;
var i;

strs = [
'',
'\uDBFF',
'Hello World',
'3.14',
'\uDBFF\uDBFF',
-4.0,
NaN,
true,
false,
null,
undefined
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isWellFormedString.isPrimitive( strs[ i % strs.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();
});

bench( pkg+'::objects:isPrimitive', function benchmark( b ) {
var strs;
var bool;
var i;

strs = [
[],
{},
function noop() {},
new String( '' ),
new String( '\uDBFF' ),
new String( '\uDBFFFF\uDBFF' )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isWellFormedString.isPrimitive( strs[ i % strs.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();
});

bench( pkg+'::primitives:isObject', function benchmark( b ) {
var strs;
var bool;
var i;

strs = [
'',
'\uDBFF',
'Hello World',
'3.14',
'\uDBFF\uDBFF',
-4.0,
NaN,
true,
false,
null,
undefined
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isWellFormedString.isObject( strs[ i % strs.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();
});

bench( pkg+'::objects:isObject', function benchmark( b ) {
var strs;
var bool;
var i;

strs = [
[],
{},
function noop() {},
new String( '' ),
new String( '\uDBFF' ),
new String( '\uDBFFFF\uDBFF' )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isWellFormedString.isObject( strs[ i % strs.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();
});
Loading