From 8d92f69f16edbafd4ec1335f3f282184d4b6024f Mon Sep 17 00:00:00 2001 From: Gopal Shah Date: Wed, 24 May 2017 22:55:05 -0700 Subject: [PATCH] add saving and loading feature --- README.md | 4 ++++ dist/wade.js | 22 +++++++++++++++++----- dist/wade.min.js | 2 +- src/index.js | 22 +++++++++++++++++----- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index d48af79..35f1dd2 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,10 @@ search("App"); Combined with libraries like [Moon](http://moonjs.ga), you can create a simple real-time search. +### Loading/Saving Data + + + ### Pipeline Wade uses a pipeline to preprocess data and search queries. By default, this pipeline will: diff --git a/dist/wade.js b/dist/wade.js index e556edd..7eee78d 100644 --- a/dist/wade.js +++ b/dist/wade.js @@ -130,12 +130,17 @@ return results; } - for(var i = 0; i < data.length; i++) { - data[i] = Wade.process(data[i]); - } + if(Array.isArray(data)) { + for(var i = 0; i < data.length; i++) { + data[i] = Wade.process(data[i]); + } - search.index = Wade.index(data); - search.data = data; + search.index = Wade.index(data); + search.data = data; + } else { + search.index = data.index; + search.data = data.data; + } return search; } @@ -187,6 +192,13 @@ return index; } + Wade.save = function(search) { + return { + data: search.data, + index: search.index + } + } + Wade.version = "0.2.0"; return Wade; diff --git a/dist/wade.min.js b/dist/wade.min.js index 80b7039..464c347 100644 --- a/dist/wade.min.js +++ b/dist/wade.min.js @@ -3,4 +3,4 @@ * Copyright 2017 Kabir Shah * Released under the MIT License */ -!function(e,o){"object"==typeof module&&module.exports?module.exports=o():e.Wade=o()}(this,function(){var e=["about","after","all","also","am","an","and","another","any","are","as","at","be","because","been","before","being","between","both","but","by","came","can","come","could","did","do","each","for","from","get","got","has","had","he","have","her","here","him","himself","his","how","if","in","into","is","it","like","make","many","me","might","more","most","much","must","my","never","now","of","on","only","or","other","our","out","over","said","same","see","should","since","some","still","such","take","than","that","the","their","them","then","there","these","they","this","those","through","to","too","under","up","very","was","way","we","well","were","what","where","which","while","who","with","would","you","your","a","i"],o=/\.|\,|\!/g,n=function(e,o){for(var n=o,r=0;r