castor-load-custom
Advanced tools
Comparing version 1.4.2 to 1.5.0
53
index.js
@@ -8,8 +8,12 @@ /*jshint node:true, laxcomma:true*/ | ||
, CSV = require('csv-string') | ||
, funex = require('funex') | ||
, filtrex = require('filtrex') | ||
, S = require('string') | ||
, transtype = require('transtype') | ||
, evaluator = require('notevil') | ||
, transtype = require('transtype') | ||
, _ = require('lodash') | ||
, _s = require('underscore.string') | ||
; | ||
_.mixin(_s.exports()); | ||
var trimString = function trimString(str) { | ||
@@ -47,2 +51,14 @@ if (typeof str !== 'string') { | ||
// | ||
// .template | ||
// | ||
if (options.schema[key].template) { | ||
try { | ||
values[key] = _.template(options.schema[key].template, values); | ||
} | ||
catch(e) { | ||
values[key] = e.toString(); | ||
} | ||
} | ||
// | ||
// .path | ||
@@ -79,14 +95,6 @@ // | ||
// | ||
if (options.schema[key].transform && | ||
typeof options.schema[key].transform === 'string') { | ||
var fn = funex('input.' + options.schema[key].transform); | ||
var re = fn({input: S(values[key])}); | ||
if (typeof re.s === 'string') { | ||
values[key] = re.toString(); | ||
} | ||
else { | ||
values[key] = re; | ||
} | ||
if (options.schema[key].transform && typeof options.schema[key].transform === 'string') { | ||
var exp = 'return input.' + options.schema[key].transform + '.value()'; | ||
var func1 = evaluator.Function('input', exp); | ||
values[key] = func1(_.chain(values[key])); | ||
} | ||
@@ -97,11 +105,6 @@ | ||
// | ||
if (options.schema[key].textizer && | ||
typeof options.schema[key].textizer === 'string') { | ||
var fn2 = funex('input.' + options.schema[key].textizer); | ||
var re2 = fn2({input: S(values[key])}); | ||
if (re2) { | ||
text += re2.toString(); | ||
} | ||
if (options.schema[key].textizer && typeof options.schema[key].textizer === 'string') { | ||
var exp2 = 'return input.' + options.schema[key].textizer + '.value()'; | ||
var func2 = evaluator.Function('input', exp2); | ||
text += func2(_.chain(values[key])); | ||
} | ||
@@ -157,3 +160,3 @@ | ||
// (Mongo 2.6 does not insert the document if any indexing does not work) | ||
values[key] = S(values[key]).truncate(250).toString(); | ||
values[key] = values[key].toString().truncate(250).toString(); | ||
} | ||
@@ -160,0 +163,0 @@ } |
{ | ||
"name": "castor-load-custom", | ||
"version": "1.4.2", | ||
"version": "1.5.0", | ||
"description": "custom loader for castor", | ||
@@ -26,6 +26,8 @@ "main": "index.js", | ||
"csv-string": "^2.2.2", | ||
"funex": "^0.2.2", | ||
"filtrex": "^0.5.4", | ||
"string": "^2.1.0", | ||
"transtype": "^1.0.0" | ||
"transtype": "^1.0.0", | ||
"lodash": "^2.4.1", | ||
"underscore.string": "^2.4.0", | ||
"notevil": "^0.8.1" | ||
}, | ||
@@ -32,0 +34,0 @@ "peerDependencies": { |
14179
152
9
+ Addedlodash@^2.4.1
+ Addednotevil@^0.8.1
+ Addedunderscore.string@^2.4.0
+ Addedhoister@0.0.2(transitive)
+ Addednotevil@0.8.1(transitive)
- Removedfunex@^0.2.2
- Removedfunex@0.2.2(transitive)