How to use the prettier/standalone.js.format function in prettier

To help you get started, we’ve selected a few prettier examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github oslabs-beta / preducks / src / utils / createReduxFiles.util.ts View on Github external
}

    actionCreatorsText += curActionCreatorText;
  });

  // import all shared interfaces
  const interfaceNameArray = Object.keys(storeConfig.interfaces);
  const interfacesImportText = interfaceNameArray.length
    ? `import {${interfaceNameArray.toString()}} from '../Interfaces';\n\n`
    : '';
  // exoirt an enum with all actions
  const actionTypesEnumText = `export enum ${reducerName}ActionTypes{${actions.toString()}};\n\n`;
  const typeGuardText = `export type ${reducerName}ActionInterfaceUnion = ${actionInterfaceNames.join(
    '|',
  )};\n\n`;
  zip.file(actionTypesFile, format(
    interfacesImportText + actionInterfacesText + actionTypesEnumText + typeGuardText,
    {
      parser: 'typescript',
      plugins: [parserTypescript]
    },
    (err) => {
      if (err) {
        throw new Error(err.message);
      } else {
        console.log('action types written successfully');
      }
    },
  ));

//   // ///// ACTIONS STUFF /////////////////////////////
github oslabs-beta / preducks / src / utils / createReduxFiles.util.ts View on Github external
numberOfActions ? `${reducerName}ActionInterfaceUnion` : 'any'
}) => {
    switch(action.type){\n`;

  Object.keys(storeConfig.reducers[reducerName].actions).forEach((actionTypeName) => {
    // need each action name to do cases for each action type
    reducerText += `case ${reducerName}ActionTypes.${actionTypeName}:
    // your logic here!
    return state;\n`;
  });
  reducerText += `default:
      return state;
    }
  };`;

  zip.file(reducerFile, format(
    importText + storeSliceInterfaceText + initialStateText + reducerText,
    {
      parser: 'typescript',
      plugins: [parserTypescript]
    },
    (err) => {
      if (err) {
        throw new Error(err.message);
      } else {
        console.log('reducer files written successfully');
      }
    },
  ));
}
github oslabs-beta / preducks / src / utils / createReduxFiles.util.ts View on Github external
// CREATE INTERFACES
  interfaceObjKeys.forEach((interfaceName) => {
    let curInterface = `export interface ${interfaceName} {\n`;
    Object.keys(interfaceObj[interfaceName]).forEach((property) => {
      // loop thru all properties of the current interface
      const curType = interfaceObj[interfaceName][property];
      curInterface += `${property}: ${curType};\n`;
      // because curType needs to be flexible (can be an interface that was previously defined)
      // we need to add this UI to the frontend so that each interface that is created is now
      // an available type that can be applied when building subsequent interfaces.
    });
    curInterface += '}\n\n';
    data += curInterface;
  });

  zip.file(filePath, format(
    data,
    {
      parser: 'typescript',
      plugins: [parserTypescript]
    },
    (err) => {
      if (err) {
        throw new Error(err.message);
      } else {
        console.log('interfaces written successfully');
      }
    },
  ))
};
github oslabs-beta / preducks / src / utils / createComponentFiles.util.ts View on Github external
components.forEach((component: any) => {
    zip.file(`src/components/${component.title}.tsx`, format(componentRender(component, components), {
      singleQuote: true,
      trailingComma: 'es5',
      bracketSpacing: true,
      jsxBracketSameLine: true,
      parser: 'typescript',
      plugins: [parserTypescript]
    }));
  });
  return path;
github Khan / flow-to-ts / src / convert.js View on Github external
tsCode += "\n";
  }

  if (options && options.prettier) {
    const prettierOptions = {
      parser: "typescript",
      plugins,
      semi: options.semi,
      singleQuote: options.singleQuote,
      tabWidth: options.tabWidth,
      trailingComma: options.trailingComma,
      bracketSpacing: options.bracketSpacing,
      arrowParens: options.arrowParens,
      printWidth: options.printWidth
    };
    return prettier.format(tsCode, prettierOptions).trim();
  } else {
    return tsCode;
  }
};