Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

docsearch.js

Package Overview
Dependencies
Maintainers
5
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

docsearch.js - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

coverage/coverage.json

12

CHANGELOG.md

@@ -0,1 +1,13 @@

<a name="1.0.2"></a>
## [1.0.2](https://github.com/algolia/docsearch/compare/v1.0.1...v1.0.2) (2015-12-28)
### Bug Fixes
* **debut:** do not enable debug by default ([188f49e](https://github.com/algolia/docsearch/commit/188f49e))
* **url:** Removes concatenation of URL with hash if it contains a hash ([348df1c](https://github.com/algolia/docsearch/commit/348df1c)), closes [#53](https://github.com/algolia/docsearch/issues/53)
* **usage:** fixed usage to match the latest prototype version ([f6edc9e](https://github.com/algolia/docsearch/commit/f6edc9e))
<a name="1.0.1"></a>

@@ -2,0 +14,0 @@ ## [1.0.1](https://github.com/algolia/docsearch/compare/v1.0.0...v1.0.1) (2015-12-24)

22

dist/npm/src/lib/DocSearch.js

@@ -54,3 +54,3 @@ 'use strict';

*/
var usage = 'Usage:\n documentationSearch({\n apiKey,\n indexName,\n inputSelector,\n [ options.{hint,debug} ]\n})';
var usage = 'Usage:\n documentationSearch({\n apiKey,\n indexName,\n inputSelector,\n [ appId ],\n [ algoliaOptions.{hitsPerPage} ]\n [ autocompleteOptions.{hint,debug} ]\n})';

@@ -70,3 +70,3 @@ var DocSearch = (function () {

var autocompleteOptions = _ref$autocompleteOptions === undefined ? {
debug: true,
debug: false,
hint: false

@@ -184,3 +184,3 @@ } : _ref$autocompleteOptions;

return groupedHits.map(function (hit) {
var url = hit.anchor ? hit.url + '#' + hit.anchor : hit.url;
var url = DocSearch.formatURL(hit);
var category = _utilsJs2['default'].getHighlightedValue(hit, 'lvl0');

@@ -203,2 +203,18 @@ var subcategory = _utilsJs2['default'].getHighlightedValue(hit, 'lvl1') || category;

}, {
key: 'formatURL',
value: function formatURL(hit) {
var url = hit.url;
var anchor = hit.anchor;
if (url) {
var containsAnchor = url.indexOf('#') !== -1;
if (containsAnchor) return url;else if (anchor) return hit.url + '#' + hit.anchor;
return url;
} else if (anchor) return '#' + hit.anchor;
/* eslint-disable */
console.warn('no anchor nor url for : ', JSON.stringify(hit));
/* eslint-enable */
return null;
}
}, {
key: 'getSuggestionTemplate',

@@ -205,0 +221,0 @@ value: function getSuggestionTemplate() {

2

dist/npm/src/lib/version.js

@@ -6,3 +6,3 @@ 'use strict';

});
exports['default'] = '1.0.1';
exports['default'] = '1.0.2';
module.exports = exports['default'];

@@ -22,3 +22,3 @@ document.addEventListener("DOMContentLoaded", function(){

if(distance(p.pos, center) < distance(p.v, [0, 0]) * 0.6) {
recycle(p, center);
recycle(p, center);
}

@@ -25,0 +25,0 @@ else{

(function($) {
$('.join-form').on('submit', function() {
$('#join-form').on('submit', function() {
var $button = $(this).find('button');

@@ -4,0 +4,0 @@ var $email = $(this).find('input[name="email"]');

{
"name": "docsearch.js",
"version": "1.0.1",
"version": "1.0.2",
"description": "Add an autocomplete dropdown to your documentation",

@@ -5,0 +5,0 @@ "main": "dist/npm/index.js",

@@ -27,3 +27,5 @@ import Hogan from 'hogan.js';

inputSelector,
[ options.{hint,debug} ]
[ appId ],
[ algoliaOptions.{hitsPerPage} ]
[ autocompleteOptions.{hint,debug} ]
})`;

@@ -40,3 +42,3 @@ class DocSearch {

autocompleteOptions = {
debug: true,
debug: false,
hint: false

@@ -135,3 +137,3 @@ }

return groupedHits.map((hit) => {
let url = hit.anchor ? `${hit.url}#${hit.anchor}` : hit.url;
let url = DocSearch.formatURL(hit);
let category = utils.getHighlightedValue(hit, 'lvl0');

@@ -160,2 +162,17 @@ let subcategory = utils.getHighlightedValue(hit, 'lvl1') || category;

static formatURL(hit) {
const {url, anchor} = hit;
if (url) {
const containsAnchor = url.indexOf('#') !== -1;
if (containsAnchor) return url;
else if (anchor) return `${hit.url}#${hit.anchor}`;
return url;
}
else if (anchor) return `#${hit.anchor}`;
/* eslint-disable */
console.warn('no anchor nor url for : ', JSON.stringify(hit));
/* eslint-enable */
return null;
}
static getSuggestionTemplate() {

@@ -162,0 +179,0 @@ const template = Hogan.compile(templates.suggestion);

@@ -1,1 +0,1 @@

export default '1.0.1';
export default '1.0.2';

@@ -7,2 +7,3 @@ /* eslint-env mocha */

import sinon from 'sinon';
import {waitForAndRun} from './helpers';

@@ -334,2 +335,27 @@ describe('DocSearch', () => {

describe('handleSelected', () => {
it('should change the location', (done) => {
// Given
const options = {
apiKey: 'key',
indexName: 'foo',
inputSelector: '#input'
};
// When
let ds = new DocSearch(options);
ds.autocomplete.trigger('autocomplete:selected', {url: 'https://website.com/doc/page'});
// Then asynchronously
waitForAndRun(() => {
// escape as soon as the URL has changed
return window.location.href !== 'about:blank';
}, () => {
// then
expect(window.location.href).toEqual('https://website.com/doc/page');
done();
}, 100);
});
});
describe('formatHits', () => {

@@ -713,2 +739,66 @@ it('should not mutate the input', () => {

});
it('should not add the anchor to the url if one is set but it is already in the URL', () => {
// Given
let input = [{
hierarchy: {
lvl0: 'Ruby',
lvl1: 'API',
lvl2: null,
lvl3: null,
lvl4: null,
lvl5: null
},
content: 'foo bar',
url: 'http://foo.bar/#anchor',
anchor: 'anchor'
}];
// When
let actual = DocSearch.formatHits(input);
// Then
expect(actual[0].url).toEqual('http://foo.bar/#anchor');
});
it('should just use the URL if no anchor is provided', () => {
// Given
let input = [{
hierarchy: {
lvl0: 'Ruby',
lvl1: 'API',
lvl2: null,
lvl3: null,
lvl4: null,
lvl5: null
},
content: 'foo bar',
url: 'http://foo.bar/'
}];
// When
let actual = DocSearch.formatHits(input);
// Then
expect(actual[0].url).toEqual(input[0].url);
});
it('should return the anchor if there is no URL', () => {
// Given
let input = [{
hierarchy: {
lvl0: 'Ruby',
lvl1: 'API',
lvl2: null,
lvl3: null,
lvl4: null,
lvl5: null
},
content: 'foo bar',
anchor: 'anchor'
}];
// When
let actual = DocSearch.formatHits(input);
// Then
expect(actual[0].url).toEqual('#' + input[0].anchor);
});
});

@@ -715,0 +805,0 @@

@@ -6,1 +6,29 @@ /* eslint-env mocha */

global.xit = it.skip;
/**
* Wait for max `escapeTime` ms and run `runFunction` except if `escapeFunction` returned true
*/
function waitForAndRun(escapeFunction, runFunction, escapeTime) {
// check the escapeFunction every millisecond so as soon as it is met we can escape the function
var interval = setInterval(function() {
if (escapeFunction()) {
clearMe();
runFunction();
}
}, 1);
// in case we never reach the escapeFunction, we will time out
// at the escapeTime
var timeOut = setTimeout(function() {
clearMe();
runFunction();
}, escapeTime);
// clear the interval and the timeout
function clearMe() {
clearInterval(interval);
clearTimeout(timeOut);
}
}
module.exports = {
waitForAndRun
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc