Skip to content

Commit cc2fa9a

Browse files
committed
Move function to separate package and use in remark plugin
1 parent d07517c commit cc2fa9a

File tree

9 files changed

+375
-46
lines changed

9 files changed

+375
-46
lines changed

lib/node_modules/@stdlib/_tools/markdown/namespace-toc/lib/toc.js

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@
2222

2323
var logger = require( 'debug' );
2424
var replace = require( '@stdlib/string/replace' );
25-
var uncapitalize = require( '@stdlib/string/uncapitalize' );
26-
var isUppercase = require( '@stdlib/assert/is-uppercase' );
27-
var startsWith = require( '@stdlib/string/starts-with' );
2825
var contains = require( '@stdlib/assert/contains' );
29-
var WHITELIST = require( './whitelist.json' );
26+
var uncapitalizeDescription = require( '@stdlib/_tools/utils/uncapitalize-pkg-description' );
3027

3128

3229
// VARIABLES //
@@ -65,46 +62,6 @@ function hasMultipleSignatures( headers ) {
6562
return false;
6663
}
6764

68-
/**
69-
* Extracts the first word in a string.
70-
*
71-
* @private
72-
* @param {string} str - input string
73-
* @returns {string} first word
74-
*/
75-
function extractFirstWord( str ) {
76-
var pos = str.indexOf( ' ' );
77-
if ( pos === -1 ) {
78-
return str;
79-
}
80-
return str.substr( 0, pos );
81-
}
82-
83-
/**
84-
* Uncapitalizes a package description.
85-
*
86-
* @private
87-
* @param {string} descr - package description
88-
* @returns {string} capitalzied package description
89-
*/
90-
function uncapitalizeDescription( descr ) {
91-
var firstWord;
92-
var elem;
93-
var i;
94-
95-
firstWord = extractFirstWord( descr );
96-
if ( isUppercase( firstWord ) ) {
97-
return descr;
98-
}
99-
for ( i = 0; i < WHITELIST.length; i++ ) {
100-
elem = WHITELIST[ i ];
101-
if ( startsWith( firstWord, elem ) ) {
102-
return descr;
103-
}
104-
}
105-
return uncapitalize( descr );
106-
}
107-
10865

10966
// MAIN //
11067

lib/node_modules/@stdlib/_tools/remark/plugins/remark-stdlib-related/lib/transformer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var logger = require( 'debug' );
2525
var visit = require( 'unist-util-visit' );
2626
var rootDir = require( '@stdlib/_tools/utils/root-dir' );
2727
var pkg2related = require( '@stdlib/namespace/pkg2related' );
28-
var uncapitalize = require( '@stdlib/string/uncapitalize' );
28+
var uncapitalizeDescription = require( '@stdlib/_tools/utils/uncapitalize-pkg-description' );
2929
var readJSON = require( '@stdlib/fs/read-json' ).sync;
3030

3131

@@ -134,7 +134,7 @@ function transformer( tree, file ) {
134134
if ( meta instanceof Error ) {
135135
throw meta;
136136
}
137-
description = uncapitalize( meta.description );
137+
description = uncapitalizeDescription( meta.description );
138138
content += '- [`'+related[ i ]+'`]['+related[ i ]+']: '+description;
139139
content += '\n';
140140
links.push( '['+related[ i ]+']: https://github.com/stdlib-js/stdlib' );
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2021 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# Uncapitalize Description
22+
23+
> Uncapitalizes a `stdlib` package description.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var uncapitalizeDescription = require( '@stdlib/_tools/utils/uncapitalize-pkg-description' );
31+
```
32+
33+
#### uncapitalizeDescription( str )
34+
35+
Uncapitalizes a `stdlib` package description.
36+
37+
```javascript
38+
var out = uncapitalizeDescription( 'Test for deep equality between two values.' );
39+
// returns 'test for deep equality between two values.'
40+
```
41+
42+
</section>
43+
44+
<!-- /.usage -->
45+
46+
<section class="examples">
47+
48+
## Examples
49+
50+
<!-- eslint no-undef: "error" -->
51+
52+
```javascript
53+
var uncapitalizeDescription = require( '@stdlib/_tools/utils/uncapitalize-pkg-description' );
54+
55+
var out = uncapitalizeDescription( 'Replace search occurrences with a replacement string.' );
56+
// returns 'replace search occurrences with a replacement string.'
57+
58+
out = uncapitalizeDescription( 'Poisson distribution constructor.' );
59+
// returns 'Poisson distribution constructor.'
60+
61+
out = uncapitalizeDescription( 'Return a JSON representation of an error object.' );
62+
// returns 'return a JSON representation of an error object.'
63+
```
64+
65+
</section>
66+
67+
<!-- /.examples -->
68+
69+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
70+
71+
<section class="related">
72+
73+
<!-- /.related -->
74+
75+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
76+
77+
<section class="links">
78+
79+
</section>
80+
81+
<!-- /.links -->
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
'use strict';
20+
21+
var uncapitalizeDescription = require( './../lib' );
22+
23+
console.log( uncapitalizeDescription( 'Replace search occurrences with a replacement string.' ) );
24+
// => 'replace search occurrences with a replacement string.'
25+
26+
console.log( uncapitalizeDescription( 'Poisson distribution constructor.' ) );
27+
// => 'Poisson distribution constructor.'
28+
29+
console.log( uncapitalizeDescription( 'Return a JSON representation of an error object.' ) );
30+
// => 'return a JSON representation of an error object.'
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
'use strict';
20+
21+
/**
22+
* Uncapitalize a package description.
23+
*
24+
* @module @stdlib/_tools/utils/uncapitalize-pkg-description
25+
*
26+
* @example
27+
* var uncapitalizeDescription = require( '@stdlib/_tools/utils/uncapitalize-pkg-description' );
28+
*
29+
* var out = uncapitalizeDescription( 'Test for deep equality between two values.' );
30+
* // returns 'test for deep equality between two values.'
31+
*/
32+
33+
// MODULES //
34+
35+
var uncapitalizeDescription = require( './main.js' );
36+
37+
38+
// EXPORTS //
39+
40+
module.exports = uncapitalizeDescription;
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+
'use strict';
20+
21+
// MODULES //
22+
23+
var uncapitalize = require( '@stdlib/string/uncapitalize' );
24+
var isUppercase = require( '@stdlib/assert/is-uppercase' );
25+
var startsWith = require( '@stdlib/string/starts-with' );
26+
var PROPER_NOUNS = require( './proper_nouns.json' );
27+
28+
29+
// FUNCTIONS //
30+
31+
/**
32+
* Extracts the first word in a string.
33+
*
34+
* @private
35+
* @param {string} str - input string
36+
* @returns {string} first word
37+
*/
38+
function extractFirstWord( str ) {
39+
var pos = str.indexOf( ' ' );
40+
if ( pos === -1 ) {
41+
return str;
42+
}
43+
return str.substr( 0, pos );
44+
}
45+
46+
47+
// MAIN //
48+
49+
/**
50+
* Uncapitalizes a package description.
51+
*
52+
* @param {string} descr - package description
53+
* @returns {string} capitalzied package description
54+
*/
55+
function uncapitalizeDescription( descr ) {
56+
var firstWord;
57+
var elem;
58+
var i;
59+
60+
firstWord = extractFirstWord( descr );
61+
if ( isUppercase( firstWord ) ) {
62+
return descr;
63+
}
64+
for ( i = 0; i < PROPER_NOUNS.length; i++ ) {
65+
elem = PROPER_NOUNS[ i ];
66+
if ( startsWith( firstWord, elem ) ) {
67+
return descr;
68+
}
69+
}
70+
return uncapitalize( descr );
71+
}
72+
73+
74+
// EXPORTS //
75+
76+
module.exports = uncapitalizeDescription;

lib/node_modules/@stdlib/_tools/markdown/namespace-toc/lib/whitelist.json renamed to lib/node_modules/@stdlib/_tools/utils/uncapitalize-pkg-description/lib/proper_nouns.json

File renamed without changes.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"name": "@stdlib/string/_tools/utils/uncapitalize-pkg-description",
3+
"version": "0.0.0",
4+
"description": "Uncapitalize a package description.",
5+
"license": "Apache-2.0",
6+
"author": {
7+
"name": "The Stdlib Authors",
8+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9+
},
10+
"contributors": [
11+
{
12+
"name": "The Stdlib Authors",
13+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14+
}
15+
],
16+
"main": "./lib",
17+
"directories": {
18+
"example": "./examples",
19+
"lib": "./lib",
20+
"test": "./test"
21+
},
22+
"scripts": {},
23+
"homepage": "https://github.com/stdlib-js/stdlib",
24+
"repository": {
25+
"type": "git",
26+
"url": "git://github.com/stdlib-js/stdlib.git"
27+
},
28+
"bugs": {
29+
"url": "https://github.com/stdlib-js/stdlib/issues"
30+
},
31+
"dependencies": {},
32+
"devDependencies": {},
33+
"engines": {
34+
"node": ">=0.10.0",
35+
"npm": ">2.7.0"
36+
},
37+
"os": [
38+
"aix",
39+
"darwin",
40+
"freebsd",
41+
"linux",
42+
"macos",
43+
"openbsd",
44+
"sunos",
45+
"win32",
46+
"windows"
47+
],
48+
"keywords": [
49+
"stdlib",
50+
"tools",
51+
"package",
52+
"pkg",
53+
"description",
54+
"capitalize",
55+
"decapitalize",
56+
"uncapitalize",
57+
"lowercase",
58+
"lower",
59+
"case"
60+
]
61+
}

0 commit comments

Comments
 (0)