Пример #1
0
  form.parse(req, function(err, fields, files) {
    if (err) {
      res.send("There was an error in processing your request.")
    }

    var brand = require('./maps/' + fields.brand + '.js')
    var parts = []

    switch (files.loadsheets[0].originalFilename.slice(-4).toUpperCase()) {
        case "XLSX":
            var loadsheet = XLSX.readFile(files.loadsheets[0].path)
            parts = XLSX.utils.sheet_to_row_object_array(loadsheet.Sheets[brand.tab])
            brand.transform(parts, res)
            break
        case ".XLS":
            var loadsheet = XLS.readFile(files.loadsheets[0].path)
            parts = XLS.utils.sheet_to_row_object_array(loadsheet.Sheets[brand.tab])
            brand.transform(parts, res)
            break
        case ".TXT":
        case ".CSV":
            csv()
            .from.path(files.loadsheets[0].path, {columns: true})
            .to.array(function(data) {
                brand.transform(data, res)
            })
            break
        default:
            res.send("Unknown file format.")
    }
    
  })
Пример #2
0
    it('should scale a rect twice on y',function(){
      var w = 20, h = 20;
      var rect = makeRect(w,h)
      expect(poly.aabb(rect)).to.eql([0,w,h,0])
      draw.poly(rect).stroke('blue')

      var m = mat.scale(1,2)
      poly.transform(rect,m)
      poly.transform(rect,m)

      expect(poly.aabb(rect)).to.eql([0,w,h*4,0])
      draw.poly(rect).stroke('red')
    })
Пример #3
0
		_js: function(module, filename, code, prevMap) {
			registerErrorHandler();

			if (!code) code = fs.readFileSync(filename, "utf8");

			// If there's a shebang, strip it while preserving line count.
			var match = /^#!.*([^\u0000]*)$/.exec(code);
			if (match) code = match[1];

			var cachedTransform = require("../compiler/compileSync").cachedTransformSync;
			var opts = clone(options);
			opts.sourceName = filename;
			opts.lines = opts.lines || 'sourcemap';
			opts.prevMap = prevMap;
			var streamlined = options.cache ?
				cachedTransform(code, filename, streamline, opts) :
				streamline(code, opts);
			if (streamlined instanceof sourceMap.SourceNode) {
				var streamlined = streamlined.toStringWithSourceMap({
					file: filename
				});
				var map = streamlined.map;
				if (prevMap) {
					map.applySourceMap(prevMap, filename);
				}
				sourceMaps[path.resolve(filename)] = new sourceMap.SourceMapConsumer(map.toString());
				module._compile(streamlined.code, filename)
			} else {
				module._compile(streamlined, filename);
			}
		},
Пример #4
0
function matchesSnapshot(query) {
  const { code } = babel.transform(query, {
    presets: [`@babel/preset-react`],
    plugins: [plugin],
  })
  expect(code).toMatchSnapshot()
}
Пример #5
0
 .then(() => {
     return currentGst.transform(
         chainProxy,
         currentGstConfig,
         context
     );
 })
function convertToInputFilter(prefix, type) {
  if (type instanceof GraphQLScalarType) {
    var name = type.name;
    var fields = scalarFilterMap[name];

    if (fields == null) return null;
    return new GraphQLInputObjectType({
      name: createTypeName(`${prefix}Query${name}`),
      fields: fields
    });
  } else if (type instanceof GraphQLInputObjectType) {
    return new GraphQLInputObjectType({
      name: createTypeName(`${prefix}{type.name}`),
      fields: _.transform(type.getFields(), function (out, fieldConfig, key) {
        var type = convertToInputFilter(`${prefix}${_.upperFirst(key)}`, fieldConfig.type);
        if (type) out[key] = { type };
      })
    });
  } else if (type instanceof GraphQLList) {
    var innerType = type.ofType;
    var innerFilter = convertToInputFilter(`${prefix}ListElem`, innerType);
    var innerFields = innerFilter ? innerFilter.getFields() : {};

    return new GraphQLInputObjectType({
      name: createTypeName(`${prefix}QueryList`),
      fields: (0, _extends3.default)({}, innerFields, {
        in: { type: new GraphQLList(innerType) }
      })
    });
  } else if (type instanceof GraphQLNonNull) {
    return convertToInputFilter(prefix, type.ofType);
  }

  return null;
}
Пример #7
0
	var parse = function(source)
	{
		return transform(esprima.parse(source, {
			comment: true,
			range: true,
			loc: true,
			tolerant: true,
			tokens: true
		}), source);
	};
Пример #8
0
 function changes(object, base) {
   return _.transform(object, function(result, value, key) {
     if (!_.isEqual(value, base[key])) {
       result[key] =
         _.isObject(value) && _.isObject(base[key])
           ? changes(value, base[key])
           : value
     }
   })
 }
Пример #9
0
			it('should accept callback function', (done) => {
				im.transform(imageFile, 'dst.jpg', { strip: true }, (err, dst) => {
					if (err) {
						return done(err);
					}

					dst.should.equal('dst.jpg');
					done();
				});
			});
function convertToInputFilter(
  prefix: string,
  type: GraphQLInputType
): ?GraphQLInputObjectType {
  if (type instanceof GraphQLScalarType) {
    const name = type.name
    const fields = scalarFilterMap[name]

    if (fields == null) return null
    return new GraphQLInputObjectType({
      name: createTypeName(`${prefix}Query${name}`),
      fields: fields,
    })
  } else if (type instanceof GraphQLInputObjectType) {
    const fields = _.transform(type.getFields(), (out, fieldConfig, key) => {
      const type = convertToInputFilter(
        `${prefix}${_.upperFirst(key)}`,
        fieldConfig.type
      )
      if (type) out[key] = { type }
    })
    if (Object.keys(fields).length === 0) {
      return null
    }
    return new GraphQLInputObjectType({
      name: createTypeName(`${prefix}{type.name}`),
      fields: fields,
    })
  } else if (type instanceof GraphQLList) {
    const innerType = type.ofType
    const innerFilter = convertToInputFilter(`${prefix}ListElem`, innerType)
    const innerFields = innerFilter ? innerFilter.getFields() : {}

    let fields
    if (innerType instanceof GraphQLInputObjectType) {
      fields = {
        elemMatch: { type: innerFilter },
      }
    } else {
      fields = {
        ...innerFields,
        in: { type: new GraphQLList(innerType) },
      }
    }

    return new GraphQLInputObjectType({
      name: createTypeName(`${prefix}QueryList`),
      fields,
    })
  } else if (type instanceof GraphQLNonNull) {
    return convertToInputFilter(prefix, type.ofType)
  }

  return null
}
Пример #11
0
 jsx: function(source) {
   var renderedCode = '';
   try {
     renderedCode = jsx.transform(source).code;
   } catch (e) {
     if (console) {
       console.error(e.message);
     }
   }
   return renderedCode;
 },
Пример #12
0
 filter: function(path, buffer) {
   if (!/\.js$/.test(path)) return buffer
   try {
     return new Buffer(babel.transform(buffer.toString(), {
       filename: path,
       sourceMaps: "inline",
     }).code)
   } catch(e) {
     return new Buffer("console.error(" + JSON.stringify(e + "") + ")")
   }
 },
Пример #13
0
			it('should support streams', () => {
				return im
					.transform(fs.createReadStream(imageFile), fs.createWriteStream('test.jpg', { encoding: 'binary' }), {
						quality: 10,
						strip: true,
						sharpen: { mode: 'variable' }
					})
					.then(() => {
						isJPG('test.jpg').should.be.true();
					});
			});
Пример #14
0
			it('should ignore invalid actions', () => {
				return im
					.transform('src.jpg', 'dst.jpg', {
						quality: 10,
						exec: 'no',
						foobar: 'monkey'
					})
					.then((commands) => {
						commands.should.eql(['-quality 10']);
					});
			});
Пример #15
0
    it('should scale a rect x.5',function(){
      var w = 20, h = 20;
      var rect = makeRect(w,h)
      expect(poly.aabb(rect)).to.eql([0,w,h,0])
      draw.poly(rect).stroke('blue')

      var m = mat.scale(.5,.5)
      poly.transform(rect,m)

      expect(poly.aabb(rect)).to.eql([0,w/2,h/2,0])
      draw.poly(rect).stroke('red')
    })
Пример #16
0
Reform.prototype.buildColumn = function(stack,orders){
  var dist = false;
  var s;
  for(var name in stack){
    s = stack[name];
    dist = dist ? dist : s.dist;
    Column.build(s.expr,name,s.dist);
  }
  this.output = Column.transform();
  this.orders = {};
  var colmap  = Column.maps();
  var res     = [];

  var order,cl,al,value;
  var orderLen = orders.length;
  var op = this.output;
  for(var i = 0;i < orderLen;i++){
    order = orders[i];
    cl = Lexter.text(order.expr).join("");
    al = cl;
    if(!op[cl] && !op["*"]){
      if(!colmap[cl]){
        Column.build(order.expr,cl,"",true);
      }else{
        al = colmap[cl];
      }
    }

    value = order.type == Select.ORDER.DESC ? "DESC" : "ASC";
    this.orders[al] = value;
    res.push(cl+" "+value);
  }

  this.distinct = dist;
  this.column = Column.getAll(this.groups);
  this.output = Column.transform();

  return res;
}
Пример #17
0
    it('should scale a rect from right',function(){
      var w = 20, h = 20;
      var rect = makeRect(w,h)
      expect(poly.aabb(rect)).to.eql([0,w,h,0])
      draw.poly(rect).stroke('blue')

      var m = mat.translate(-w,-h)
      mat.scale(2,2,m)
      mat.translate(w,h,m)

      poly.transform(rect,m)

      expect(poly.aabb(rect)).to.eql([-h,w,h,-w])
      draw.poly(rect).stroke('red')
    })
Пример #18
0
    it('should scale a rect from center on x',function(){
      var w = 20, h = 20;
      var rect = makeRect(w,h)
      expect(poly.aabb(rect)).to.eql([0,w,h,0])
      draw.poly(rect).stroke('blue')

      var m = mat.translate(-w/2,0)
      mat.scale(2,1,m)
      mat.translate(w/2,0,m)

      poly.transform(rect,m)

      expect(poly.aabb(rect)).to.eql([0,w+w/2,h,-w/2])
      draw.poly(rect).stroke('red')
    })
Пример #19
0
    it('should scale an offset rect from center on x',function(){
      var w = 20, h = 20, x = 10, y = 10;
      var rect = makeRect(w,h,x,y)
      expect(poly.aabb(rect)).to.eql([y,x+w,y+h,x])
      draw.poly(rect).stroke('blue')

      var m = mat.translate(-(x+w/2),0)
      mat.scale(2,1,m)
      mat.translate((x+w/2),0,m)

      poly.transform(rect,m)

      draw.poly(rect).stroke('red')
      expect(poly.aabb(rect)).to.eql([y,x+w+w/2,y+h,x-w/2])
    })
Пример #20
0
function transform({ filename, options, src }) {
  options = options || { platform: '', projectRoot: '', inlineRequires: false };

  const OLD_BABEL_ENV = process.env.BABEL_ENV;
  process.env.BABEL_ENV = options.dev ? 'development' : 'production';

  try {
    const babelConfig = buildBabelConfig(filename, options);
    const { ast, ignored } = babel.transform(src, babelConfig);

    if (ignored) {
      return {
        ast: null,
        code: src,
        filename,
        map: null,
      };
    } else {
      const result = generate(
        ast,
        {
          comments: false,
          compact: false,
          filename,
          retainLines: !!options.retainLines,
          sourceFileName: filename,
          sourceMaps: true,
        },
        src
      );

      return {
        ast,
        code: result.code,
        filename,
        map: options.generateSourceMaps ? result.map : result.rawMappings.map(compactMapping),
      };
    }
  } catch (e) {
    console.error(e);
    throw e;
  } finally {
    process.env.BABEL_ENV = OLD_BABEL_ENV;
  }
}
function convertToInputType(
  type: GraphQLType,
  typeMap: Set<GraphQLType>
): ?GraphQLInputType {
  // track types already processed in current tree, to avoid infinite recursion
  if (typeMap.has(type)) {
    return null
  }
  const nextTypeMap = new Set(Array.from(typeMap).concat([type]))

  if (type instanceof GraphQLScalarType || type instanceof GraphQLEnumType) {
    return type
  } else if (type instanceof GraphQLObjectType) {
    const fields = _.transform(type.getFields(), (out, fieldConfig, key) => {
      const type = convertToInputType(fieldConfig.type, nextTypeMap)
      if (type) out[key] = { type }
    })
    if (Object.keys(fields).length === 0) {
      return null
    }
    return new GraphQLInputObjectType({
      name: createTypeName(`${type.name}InputObject`),
      fields,
    })
  } else if (type instanceof GraphQLList) {
    let innerType = convertToInputType(type.ofType, nextTypeMap)
    return innerType ? new GraphQLList(makeNullable(innerType)) : null
  } else if (type instanceof GraphQLNonNull) {
    let innerType = convertToInputType(type.ofType, nextTypeMap)
    return innerType ? new GraphQLNonNull(makeNullable(innerType)) : null
  } else {
    let message = type ? `for type: ${type.name}` : ``
    if (type instanceof GraphQLInterfaceType) {
      message = `GraphQLInterfaceType not yet implemented ${message}`
    } else if (type instanceof GraphQLUnionType) {
      message = `GraphQLUnionType not yet implemented ${message}`
    } else {
      message = `Invalid input type ${message}`
    }
    report.verbose(message)
  }

  return null
}
function convertToInputType(type, typeMap) {
  // track types already processed in current tree, to avoid infinite recursion
  if (typeMap.has(type)) {
    return null;
  }
  var nextTypeMap = new Set(Array.from(typeMap).concat([type]));

  if (type instanceof GraphQLScalarType || type instanceof GraphQLEnumType) {
    return type;
  } else if (type instanceof GraphQLObjectType) {
    var fields = _.transform(type.getFields(), function (out, fieldConfig, key) {
      var type = convertToInputType(fieldConfig.type, nextTypeMap);
      if (type) out[key] = { type };
    });
    if (Object.keys(fields).length === 0) {
      return null;
    }
    return new GraphQLInputObjectType({
      name: createTypeName(`${type.name}InputObject`),
      fields
    });
  } else if (type instanceof GraphQLList) {
    var innerType = convertToInputType(type.ofType, nextTypeMap);
    return innerType ? new GraphQLList(makeNullable(innerType)) : null;
  } else if (type instanceof GraphQLNonNull) {
    var _innerType = convertToInputType(type.ofType, nextTypeMap);
    return _innerType ? new GraphQLNonNull(makeNullable(_innerType)) : null;
  } else {
    var message = type ? `for type: ${type.name}` : ``;
    if (type instanceof GraphQLInterfaceType) {
      message = `GraphQLInterfaceType not yet implemented ${message}`;
    } else if (type instanceof GraphQLUnionType) {
      message = `GraphQLUnionType not yet implemented ${message}`;
    } else {
      message = `Invalid input type ${message}`;
    }
    report.verbose(message);
  }

  return null;
}
Пример #23
0
			it('should create commands in order on transform', () => {
				const expected = [
					'-quality 10',
					'-strip',
					'-unsharp 0.8x0.8+1.2+0.05',
					'-filter Catrom -resize 100x\\!',
					'-crop 10x12+1+2'
				];

				return im
					.transform(imageFile, 'dst.jpg', {
						quality: 10,
						strip: true,
						sharpen: { mode: 'variable' },
						resize: { width: 100, flag: '!' },
						crop: { width: 10, height: 12, x: 1, y: 2 },
						rotate: { angle: 20 }
					})
					.then((commands) => {
						commands.should.eql(expected);
					});
			});
Пример #24
0
 .to.array(function(data) {
     brand.transform(data, res)
 })
Пример #25
0
Transformers.source = function(source) {
  return transform(visitors.react, source).code;
};
Пример #26
0
var fs = require("fs"),
    path = require("path"),
    MetaScript = require(path.join(__dirname, "..", "MetaScript.js"));

var filename = path.join(__dirname, "somemeta.js");
var source = fs.readFileSync(filename),
    program = MetaScript.compile(source);

console.log("--PROGRAM--");
console.log(program);

source = MetaScript.transform(source, filename, { WHAT:  true });

console.log("--TRANSFORM--");
console.log(source);
Пример #27
0
 it('should subtract each array value from the num of max color palette, 256', function(){
   console.log('here is test ' + value);
   expect(value).not.to.be.eql(changeColor.transform(value));
 });
Пример #28
0
var path = require('path');
var fs = require('fs');
var ziffy = require(path.join('..','ziffy'));

var hello = ziffy.convert('ziffy');
console.log(hello);

if (process.argv[2]) {
  var fileStream = fs.createReadStream(process.argv[2]);
  var writeStream = process.stdout;
  if (process.argv[3]) {
    writeStream = fs.createWriteStream(process.argv[3]);
  }
  ziffy.transform(fileStream).pipe(writeStream);
}
 fn: function() { return transform(ast); }
Пример #30
0
function transformCode(
filename,
localPath,
sourceCode,
transformerPath,
isScript,
options,
assetExts,
assetRegistryPath,
asyncRequireModulePath,
dynamicDepsInPackages)
{
  const isJson = filename.endsWith('.json');

  if (isJson) {
    sourceCode = 'module.exports=' + sourceCode;
  }

  const transformFileStartLogEntry = {
    action_name: 'Transforming file',
    action_phase: 'start',
    file_name: filename,
    log_entry_label: 'Transforming file',
    start_timestamp: process.hrtime() };


  const plugins = options.dev ?
  [] :
  [[inlinePlugin, options], [constantFoldingPlugin, options]];

  // $FlowFixMe TODO t26372934 Plugin system
  const transformer = require(transformerPath);

  const transformerArgs = {
    filename,
    localPath,
    options,
    plugins,
    src: sourceCode };


  const transformResult = isAsset(filename, assetExts) ?
  assetTransformer.transform(
  transformerArgs,
  assetRegistryPath,
  options.assetDataPlugins) :

  transformer.transform(transformerArgs);

  const postTransformArgs = [
  filename,
  localPath,
  sourceCode,
  isScript,
  options,
  transformFileStartLogEntry,
  asyncRequireModulePath,
  dynamicDepsInPackages];


  return transformResult instanceof Promise ?
  transformResult.then((_ref) => {let ast = _ref.ast;return postTransform.apply(undefined, postTransformArgs.concat([ast]));}) :
  postTransform.apply(undefined, postTransformArgs.concat([transformResult.ast]));
}