-
-
Notifications
You must be signed in to change notification settings - Fork 842
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
Planeshifter
merged 23 commits into
stdlib-js:develop
from
gunjjoshi:is-well-formed-string-package
Feb 27, 2024
Merged
Changes from 2 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 6b7d7e9
feat: added assert/is-well-formed-string
gunjjoshi 6cd7771
Update lib/node_modules/@stdlib/assert/is-well-formed-string/README.md
gunjjoshi bb2f66a
Update package.json
gunjjoshi e0c96de
Update lib/node_modules/@stdlib/assert/is-well-formed-string/lib/prim…
gunjjoshi 2928ca8
Update lib/node_modules/@stdlib/assert/is-well-formed-string/README.md
gunjjoshi bb7cbe4
Update lib/node_modules/@stdlib/assert/is-well-formed-string/README.md
gunjjoshi aa1220a
Update lib/node_modules/@stdlib/assert/is-well-formed-string/README.md
gunjjoshi 522ae16
Update lib/node_modules/@stdlib/assert/is-well-formed-string/README.md
gunjjoshi 0de80cc
Update lib/node_modules/@stdlib/assert/is-well-formed-string/docs/typ…
gunjjoshi 7055a64
Update lib/node_modules/@stdlib/assert/is-well-formed-string/docs/typ…
gunjjoshi f831f88
Update lib/node_modules/@stdlib/assert/is-well-formed-string/examples…
gunjjoshi 50930f7
Update lib/node_modules/@stdlib/assert/is-well-formed-string/lib/iswe…
gunjjoshi b458106
Update lib/node_modules/@stdlib/assert/is-well-formed-string/lib/iswe…
gunjjoshi 2c2c6ea
Update lib/node_modules/@stdlib/assert/is-well-formed-string/lib/iswe…
gunjjoshi 9710381
Update lib/node_modules/@stdlib/assert/is-well-formed-string/lib/iswe…
gunjjoshi a322028
Update lib/node_modules/@stdlib/assert/is-well-formed-string/lib/iswe…
gunjjoshi e887070
Update lib/node_modules/@stdlib/assert/is-well-formed-string/lib/iswe…
gunjjoshi 8227c93
Update lib/node_modules/@stdlib/assert/is-well-formed-string/lib/iswe…
gunjjoshi f1542e2
Update iswellformed.js
gunjjoshi 32bf6a4
Update iswellformed.js
gunjjoshi 462cda2
feat: added assert/is-well-formed-string
gunjjoshi cd5fc1f
Apply suggestions from code review
Planeshifter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
139 changes: 139 additions & 0 deletions
139
lib/node_modules/@stdlib/assert/is-well-formed-string/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<!-- | ||
|
||
@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( '\uD800\uD800' ); | ||
// returns false | ||
bool = isWellFormedString( '\uDBFF' ); | ||
// returns false | ||
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 | ||
gunjjoshi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
</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 | ||
gunjjoshi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
</section> | ||
|
||
<!-- /.examples --> | ||
|
||
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
||
<section class="related"> | ||
|
||
* * * | ||
|
||
## See Also | ||
|
||
- <span class="package-name">[`@stdlib/assert/is-String`][@stdlib/assert/is-String]</span><span class="delimiter">: </span><span class="description">test if a str is a String.</span> | ||
gunjjoshi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
</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> --> | ||
|
||
[@stdlib/assert/is-string]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-string | ||
gunjjoshi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<!-- </related-links> --> | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
220 changes: 220 additions & 0 deletions
220
lib/node_modules/@stdlib/assert/is-well-formed-string/benchmark/benchmark.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.