Skip to content

Commit

Permalink
version 0.8.2
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 042696f
Author: Morgas <[email protected]>
Date:   Thu Dec 14 15:34:35 2017 +0100

    fix comment

commit 52fdc46
Author: Morgas <[email protected]>
Date:   Wed Dec 13 22:03:09 2017 +0100

    indent

commit 34107af
Author: Morgas <[email protected]>
Date:   Mon Dec 11 01:56:02 2017 +0100

    publish preparations

commit 0085a0d
Author: Morgas <[email protected]>
Date:   Sat Dec 9 18:08:09 2017 +0100

    score functions

commit 99e76b4
Author: Morgas <[email protected]>
Date:   Fri Dec 8 19:33:14 2017 +0100

    docs
  • Loading branch information
Morgas01 committed Dec 14, 2017
1 parent 7a5a51b commit 202696f
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 42 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ JavaScript data processing framework for fun

- Node
1. cli
```
npm install morgas
```
```
npm install morgas
```
2. js
```js
```js
require("morgas");
// creates global "Morgas" and "µ" namespaces
```
```
In Node context every module is available via `µ.getModule("<name>")`.

##Node custom modules
Expand Down
5 changes: 3 additions & 2 deletions lib/build.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
let fs=require("fs");
let path=require("path");

console.log(process.argv);
require("..");

require("./..");
let packageJson=require("../package");
if(packageJson.version!=µ.version) µ.logger.warn(`code version (${µ.version}) not equals to npm package version (${packageJson.version})!`)

let dependencyParser=require("./dependencyParser");
let minify=require("./minify");
Expand Down
13 changes: 9 additions & 4 deletions lib/dependencyParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

var SC=µ.shortcut({
File:"File",
adopt:"adopt",
flatten:"flatten",
uniquify:"uniquify"
uniquify:"uniquify",
removeIf:"array.removeIf"
});

var morgasJsFile=new SC.File(µ.dirname).changePath("Morgas.js");
Expand Down Expand Up @@ -99,6 +99,12 @@
};

return explodeFolders(this.sources)
.then(files=>
{
files=SC.uniquify(files,f=>f.getAbsolutePath());
SC.removeIf(files,f=>morgasJsFile.equals(f));
return files;
})
.then(files=>Promise.all(files.map(parseFile)))
.then(sorting(relativeTo))
.then(parsedFiles=>
Expand Down Expand Up @@ -195,8 +201,7 @@
)
)
)
.then(SC.flatten)
.then(files=>SC.uniquify(files,f=>f.getAbsolutePath()));
.then(SC.flatten);
};

var scRegex=/SC=SC\(((?:[^\)]+||\);))\);/m;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "morgas",
"version": "0.8.1",
"version": "0.8.2",
"description": "dependency free framework for fun",
"homepage": "https://github.com/Morgas01/Morgas.js",
"bugs": {
Expand Down
4 changes: 0 additions & 4 deletions src/Morgas.Dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
"Morgas.util.array.remove.js"
]
},
"Morgas.js": {
"deps": [],
"uses": []
},
"Morgas.NodePatch.Compare.js": {
"deps": [
"Morgas.NodePatch.js"
Expand Down
4 changes: 0 additions & 4 deletions src/Morgas.ModuleDependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
"array.removeIf"
]
},
"Morgas.js": {
"deps": [],
"uses": []
},
"Morgas.NodePatch.Compare.js": {
"deps": [
"NodePatch"
Expand Down
2 changes: 1 addition & 1 deletion src/Morgas.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function MorgasInit(oldµ){
Morgas={version:"0.8.0"};
Morgas={version:"0.8.2"};
µ=Morgas;
/**
* revert "µ" to its old value
Expand Down
68 changes: 47 additions & 21 deletions src/Morgas.util.fuzzySearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,8 @@
scorers
}={})
{
if(!scorers)
{
term=term.trim();
let words=term.split(/\s+/);
scorers=[
FUZZ.scoreFunctions.string.complete(term),
FUZZ.scoreFunctions.string.wordOrder(words),
FUZZ.scoreFunctions.string.words(words)
];

let camelCaseWords=term.match(/(:?\b[a-z]|[A-Z])[a-z]*/g);
if(camelCaseWords)
{
scorers.push(FUZZ.scoreFunctions.string.wordOrder(camelCaseWords));
scorers.push(FUZZ.scoreFunctions.string.words(camelCaseWords));
}
}
else
{
scorers=[].concat(scorers);
}
if(!scorers) scorers=[FUZZ.scoreFunctions.misc.query(term)];
else scorers=[].concat(scorers);

let rtn=[];
for(let index=0;index<data.length;index++)
Expand Down Expand Up @@ -111,10 +92,55 @@
return 1-toFind.length/words.length;
};
},
},
object:{
property:function(key,scorers)
{
return function(data)
{
if(data&&key in data) return FUZZ.score(data[key],scorers);
return 0;
}
}
},
misc:{
query:function(term)
{
term=term.trim();
let words=term.split(/\s+/);
let scorers=[
FUZZ.scoreFunctions.string.complete(term),
FUZZ.scoreFunctions.string.wordOrder(words),
FUZZ.scoreFunctions.string.words(words)
];

let camelCaseWords=term.match(/(:?\b[a-z]|[A-Z])[a-z]*/g);
if(camelCaseWords)
{
scorers.push(FUZZ.scoreFunctions.string.wordOrder(camelCaseWords));
scorers.push(FUZZ.scoreFunctions.string.words(camelCaseWords));
}
return function(data)
{
return FUZZ.score(data,scorers);
};
},
cache:function(scorers)
{
let cache=new WeakMap();
return function(data)
{
if(!cache.has(data)) cache.set(data,FUZZ.score(data,scorers));
return cache.get(data);
};
}
}
};
FUZZ.score=function(data,scorers)
{
// shortcut for arrays with only 1 entry
if(scorers.length==1) return scorers[0](data);

let score=0;
let totalWeight=0;
for(let scorer of scorers)
Expand Down

0 comments on commit 202696f

Please sign in to comment.