Skip to content

Commit dcd772e

Browse files
committed
Fix splicing bug and set identifier to package name
1 parent bc2a8e5 commit dcd772e

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

lib/node_modules/@stdlib/_tools/search/pkg-index/lib/create.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var logger = require( 'debug' );
2424
var lunr = require( 'lunr' );
2525
var lowercase = require( '@stdlib/string/lowercase' );
2626
var replace = require( '@stdlib/string/replace' );
27+
var dirname = require( '@stdlib/utils/dirname' );
2728
var sectionText = require( './section_text.js' );
2829

2930

@@ -36,13 +37,43 @@ var RE_LINKS = /\[([^\]]+)\]\[[^\]]+\]/g;
3637
var RE_TRAILING_PERIOD = /\.$/;
3738

3839

40+
// FUNCTIONS //
41+
42+
/**
43+
* Returns the last index of a specified string.
44+
*
45+
* ## Notes
46+
*
47+
* - We assume that `searchValue.length < str.length`.
48+
*
49+
* @private
50+
* @param {string} str - string to search
51+
* @param {string} searchValue - string to match
52+
* @returns {integer} index
53+
*/
54+
function lastIndexOf( str, searchValue ) {
55+
var len;
56+
var N;
57+
var i;
58+
59+
len = str.length;
60+
N = searchValue.length;
61+
for ( i = len-N; i >= 0; i-- ) {
62+
if ( str.substring( i, i+N ) === searchValue ) {
63+
return i;
64+
}
65+
}
66+
return -1;
67+
}
68+
69+
3970
// MAIN //
4071

4172
/**
4273
* Returns a serialized lunr.js search index.
4374
*
4475
* @private
45-
* @param {(EmptyArray|StringArray)} files - list of files and their associated contents
76+
* @param {(EmptyArray|ObjectArray)} files - list of files and their associated contents
4677
* @returns {Object} serialized search index
4778
*/
4879
function createIndex( files ) {
@@ -60,7 +91,9 @@ function createIndex( files ) {
6091
var file;
6192
var blob;
6293
var desc;
94+
var id;
6395
var i;
96+
var j;
6497

6598
this.field( 'title', {
6699
'boost': 10
@@ -87,11 +120,16 @@ function createIndex( files ) {
87120
desc = replace( desc, RE_TRAILING_PERIOD, '' );
88121
debug( 'Description: %s', desc );
89122

123+
id = dirname( files[ i ].file );
124+
j = lastIndexOf( id, '@' );
125+
id = id.substring( j );
126+
debug( 'id: %s', id );
127+
90128
blob = {
91129
'title': title,
92130
'description': desc,
93131
'introduction': sectionText( file, 'intro' ),
94-
'id': files[ i ].file
132+
'id': id
95133
};
96134
debug( 'File data: %s', JSON.stringify( blob ) );
97135
this.add( blob );

lib/node_modules/@stdlib/_tools/search/pkg-index/lib/extract.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323
var visit = require( 'unist-util-visit' );
2424

2525

26-
// VARIABLES //
27-
28-
var splice = Array.prototype.splice;
29-
30-
3126
// MAIN //
3227

3328
/**
@@ -58,20 +53,17 @@ function sectionNodes( ast, name ) {
5853
*/
5954
function replacer( node, index, parent ) {
6055
var type;
61-
var arr;
62-
6356
if ( FLG ) {
6457
return;
6558
}
6659
type = isSectionTag( node, name );
6760
if ( scope && parent === scope ) {
6861
if ( type === 'end' ) {
6962
// Replace scope by nodes belonging to the given section...
70-
arr = [ 0, scope.children.length, {
63+
scope.children.splice( 0, scope.children.length, {
7164
'type': 'root',
7265
'children': nodes
73-
}];
74-
splice.apply( scope.children, arr );
66+
});
7567

7668
// Set a flag indicating that we have processed a section having the specified name:
7769
FLG = true;

lib/node_modules/@stdlib/_tools/search/pkg-index/lib/remove_elements.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ var visit = require( 'unist-util-visit' );
3232
* @param {Node} node - reference node
3333
* @param {number} index - position of `node` in `parent`
3434
* @param {Node} parent - parent of `node`
35+
* @returns {number} next index to visit
3536
*/
3637
function remove( node, index, parent ) {
3738
if ( parent ) {
3839
parent.children.splice( index, 1 );
40+
return index;
3941
}
4042
}
4143

0 commit comments

Comments
 (0)