當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript WriteStream.write方法代碼示例

本文整理匯總了TypeScript中fs.WriteStream.write方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript WriteStream.write方法的具體用法?TypeScript WriteStream.write怎麽用?TypeScript WriteStream.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在fs.WriteStream的用法示例。


在下文中一共展示了WriteStream.write方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: tsTypeToString

 _.forEach(interf.properties, (prop) => {
     var typename = tsTypeToString(prop.tsType, prop.option.associated !== null);
     if (prop.option.associated === null) {
         stream.write(`    ${prop.name}?: ${typename};\n`);
     }
     else {
         stream.write(`    ${prop.name}Id?: number;\n`);
     }
 });
開發者ID:Perlmint,項目名稱:TypedSequelize,代碼行數:9,代碼來源:writer.ts

示例2: switch

   _.forEach(interf.relationships, (rel) => {
       const capitalizedName = _.upperFirst(rel.name);
       const typeName = rel.targetName + "Interface";
       switch(rel.type) {
       case RelationshipType.OneToMany:
           stream.write(`
 get${capitalizedName}(): Promise<${typeName}[]>;
 set${capitalizedName}(vals: ${typeName}[]): Promise<${typeName}[]>;
 remove${capitalizedName}(val: ${typeName}): Promise<void>;
 add${capitalizedName}(val: ${typeName}): Promise<void>;`);
           break;
       case RelationshipType.ManyToOne:
           stream.write(`
 get${capitalizedName}(): Promise<${typeName}>;
 set${capitalizedName}(vals: ${typeName}): Promise<${typeName}>;`);
           break;
       }
   });
開發者ID:Perlmint,項目名稱:TypedSequelize,代碼行數:18,代碼來源:writer.ts

示例3: relative

 _.forEach(info.imports, (items: string[], moduleName: string) => {
     if (moduleName[0] === ".") {
         moduleName = relative(writeInfo.outDir,
                               join(dirname(writeInfo.srcPath), moduleName))
             .replace(new RegExp("\\\\", "g"), "/");
     }
     const joinedItems = _.uniq(items).join(", ");
     stream.write(`import { ${joinedItems} } from '${moduleName}';\n`);
 });
開發者ID:Perlmint,項目名稱:TypedSequelize,代碼行數:9,代碼來源:writer.ts

示例4: writeInterface

function writeInterface(stream: WriteStream, interf: Interface, name: string) {
    stream.write(`export interface ${name}Interface {\n`);
    if (!interf.hasPrimaryKey) {
        stream.write(`    id?: number; // auto generated property\n`);
    }
    if (interf.createdAt) {
        stream.write(`    ${interf.createdAt}?: Date; // auto generated property\n`);
    }
    if (interf.updatedAt) {
        stream.write(`    ${interf.updatedAt}?: Date; // auto generated property\n`);
    }
    _.forEach(interf.properties, (prop) => {
        var typename = tsTypeToString(prop.tsType, prop.option.associated !== null);
        if (prop.option.associated === null) {
            stream.write(`    ${prop.name}?: ${typename};\n`);
        }
        else {
            stream.write(`    ${prop.name}Id?: number;\n`);
        }
    });
    stream.write("}\n\n");
}
開發者ID:Perlmint,項目名稱:TypedSequelize,代碼行數:22,代碼來源:writer.ts

示例5: writeModelDef

function writeModelDef(stream: WriteStream, interf: Interface, name: string) {
    stream.write(`export interface ${name}Instance extends sequelize.Instance<${name}Interface>, ${name}Interface {`);
    _.forEach(interf.relationships, (rel) => {
        const capitalizedName = _.upperFirst(rel.name);
        const typeName = rel.targetName + "Interface";
        switch(rel.type) {
        case RelationshipType.OneToMany:
            stream.write(`
  get${capitalizedName}(): Promise<${typeName}[]>;
  set${capitalizedName}(vals: ${typeName}[]): Promise<${typeName}[]>;
  remove${capitalizedName}(val: ${typeName}): Promise<void>;
  add${capitalizedName}(val: ${typeName}): Promise<void>;`);
            break;
        case RelationshipType.ManyToOne:
            stream.write(`
  get${capitalizedName}(): Promise<${typeName}>;
  set${capitalizedName}(vals: ${typeName}): Promise<${typeName}>;`);
            break;
        }
    });
    stream.write("\n}\n\n");
    stream.write(`interface ${name}Model extends sequelize.Model<${name}Instance, ${name}Interface> {}\n\n`);
    stream.write(`var ${name}Initialized: boolean = false;\n`);
    stream.write(`export var ${name}: ${name}Model;\n`);
    stream.write(`export function init${name}(seq: sequelize.Sequelize): ${name}Model {
  if (${name}Initialized) {
    return ${name};
  }

`);
    stream.write(`  ${name} = <${name}Model>seq.define<${name}Instance, ${name}Interface>('${name}', {\n`);
    stream.write(
        _.filter(_.map(interf.properties, (prop) => makeProperty(prop))).join(",\n"));
    stream.write("  }, {");
    stream.write("\n");
    stream.write("    indexes: [\n");
    stream.write(
        _.map(interf.indexes, (index) => {
            const fields = index.fields.map((d) => `"${d}"`).join(", ");
            return `      {
        fields: [${fields}]
      }`;
        }).join(",\n")
    );
    stream.write("    ]");
    stream.write("  });\n");
    _.forEach(interf.relationships, (rel) => {
        let moduleName = "";
        if (rel.targetModule != undefined) {
            moduleName = `require('${rel.targetModule}_models').`;
        }
        stream.write(`
  // for setup relation. can't use import in funcion scope
  var ${rel.targetName} = ${moduleName}init${rel.targetName}(seq);`);
        switch (rel.type) {
        case RelationshipType.OneToMany:
            stream.write(`
  ${name}.hasMany(${rel.targetName}, {as: '${rel.name}'});`);
            break;
        case RelationshipType.ManyToOne:
            stream.write(`
  ${name}.belongsTo(${rel.targetName}, {as: '${rel.name}'});`);
        }
    });
    stream.write(`

  ${name}Initialized = true;
  return ${name};
}

`);
}
開發者ID:Perlmint,項目名稱:TypedSequelize,代碼行數:72,代碼來源:writer.ts


注:本文中的fs.WriteStream.write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。