How to use generic-names - 5 common examples

To help you get started, we’ve selected a few generic-names 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 gajus / babel-plugin-react-css-modules / src / requireCssModule.js View on Github external
export default (cssSourceFilePath: string, options: OptionsType): StyleModuleMapType => {
  // eslint-disable-next-line prefer-const
  let runner;

  let generateScopedName;

  if (options.generateScopedName && typeof options.generateScopedName === 'function') {
    generateScopedName = options.generateScopedName;
  } else {
    generateScopedName = genericNames(options.generateScopedName || optionsDefaults.generateScopedName, {
      context: options.context || process.cwd()
    });
  }

  const filetypeOptions = getFiletypeOptions(cssSourceFilePath, options.filetypes);

  const fetch = (to: string, from: string) => {
    const fromDirectoryPath = dirname(from);
    const toPath = resolve(fromDirectoryPath, to);

    return getTokens(runner, toPath, filetypeOptions);
  };

  const extraPlugins = getExtraPlugins(filetypeOptions);

  const plugins = [
github css-modules / css-modules-require-hook / src / extractor.js View on Github external
export default function extractor({
  append = [],
  prepend = [],
  createImportedName,
  generateScopedName,
  mode,
  use,
  rootDir: context = process.cwd(),
} = {}, fetch) {
  let scopedName;
  if (generateScopedName) {
    scopedName = typeof generateScopedName !== 'function'
      ? genericNames(generateScopedName || '[name]__[local]___[hash:base64:5]', {context})
      : generateScopedName;
  } else {
    // small fallback
    scopedName = (local, filename) => Scope.generateScopedName(local, relative(context, filename));
  }

  const plugins = (use || [
    ...prepend,
    Values,
    mode
      ? new LocalByDefault({mode})
      : LocalByDefault,
    createImportedName
      ? new ExtractImports({createImportedName})
      : ExtractImports,
    new Scope({generateScopedName: scopedName}),
github css-modules / postcss-icss-selectors / src / index.js View on Github external
module.exports = postcss.plugin(plugin, (options = {}) => (css, result) => {
  const { icssImports, icssExports } = extractICSS(css);
  const generateScopedName =
    options.generateScopedName ||
    genericNames("[name]__[local]---[hash:base64:5]");
  const input = (css && css.source && css.source.input) || {};
  const aliases = {};
  walkRules(css, rule => {
    const getAlias = name => {
      if (aliases[name]) {
        return aliases[name];
      }
      // icss-value contract
      const valueMsg = getValue(result.messages, name);
      if (valueMsg) {
        aliases[valueMsg.name] = name;
        return name;
      }
      const alias = generateScopedName(name, input.from, input.css);
      aliases[name] = alias;
      // icss-scoped contract
github css-modules / postcss-modules / src / index.js View on Github external
function getScopedNameGenerator(opts) {
  const scopedNameGenerator = opts.generateScopedName || generateScopedName;

  if (typeof scopedNameGenerator === "function") return scopedNameGenerator;
  return genericNames(scopedNameGenerator, {
    context: process.cwd(),
    hashPrefix: opts.hashPrefix
  });
}
github imdreamrunner / browser-vue-loader / src / processors / css / postcss-plugins / postcss-modules / index.js View on Github external
function getScopedNameGenerator (opts) {
  const scopedNameGenerator = opts.generateScopedName || generateScopedName

  if (typeof scopedNameGenerator === 'function') return scopedNameGenerator
  return genericNames(scopedNameGenerator, {context: process.cwd()})
}

generic-names

Helper for building generic names, similar to webpack

MIT
Latest version published 2 years ago

Package Health Score

68 / 100
Full package analysis

Popular generic-names functions