How to use foreach - 9 common examples

To help you get started, we’ve selected a few foreach 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 martinandert / react-inline / src / transformStyleSheetObjectIntoSpecification.js View on Github external
export default function transformStyleSheetObjectIntoSpecification(content) {
  assertPlainObject(content);

  let styles = {};

  foreach(content, (value, key) => {
    if (isMediaQueryDeclaration.test(key)) {
      processMediaQuery(styles, key.substring(1), value);
    } else if (isStandaloneSelector.test(key)) {
      assert(false, 'stand-alone selectors are not allowed at the top-level');
    } else if (hasAttachedSelector.test(key)) {
      var [styleName, selectorName] = splitSelector(key);
      processStyleAndSelector(styles, styleName, selectorName, value);
    } else {
      processStyle(styles, key, value);
    }
  });

  return styles;
}
github martinandert / react-inline / src / transformStyleSheetObjectIntoSpecification.js View on Github external
function processStyleAndMediaQuery(styles, styleName, mediaQueryName, content) {
  assertPlainObject(content);

  let style       = initStyleSpec(styles, styleName);
  let mediaQuery  = initMediaQuerySpec(style.mediaQueries, mediaQueryName);

  foreach(content, (value, key) => {
    if (isMediaQueryDeclaration.test(key)) {
      assert(false, 'media queries cannot be nested into each other');
    } else if (isStandaloneSelector.test(key)) {
      processStyleAndMediaQueryAndSelector(styles, styleName, mediaQueryName, key, value);
    } else if (hasAttachedSelector.test(key)) {
      assert(false, 'styles cannot be nested into each other');
    } else {
      processRule(mediaQuery.rules, key, value);
    }
  });
}
github martinandert / babel-plugin-css-in-js / src / transformStyleSheetObjectIntoSpecification.js View on Github external
function processStyle(styles, styleName, content, parent) {
  assertPlainObject(content);

  const style = initStyleSpec(styles, styleName, parent);

  foreach(content, (value, key) => {
    if (isMediaQueryDeclaration.test(key)) {
      processStyleAndMediaQuery(styles, styleName, key.substring(1), value, parent);
    } else if (isStandaloneSelector.test(key)) {
      processStyleAndSelector(styles, styleName, key, value, parent);
    } else if (hasAttachedSelector.test(key)) {
      assert(false, 'styles cannot be nested into each other');
    } else {
      processRule(style.rules, key, value);
    }
  });
}
github erykpiast / autocompleted-select / src / js / spec / model.spec.js View on Github external
test('Should be an object with functions as properties', () => {

            assert.isObject(model);

            each(model, (prop) => assert.isFunction(prop));
        });
github martinandert / babel-plugin-css-in-js / src / transformSpecificationIntoCSS.js View on Github external
function processSelectors(css, name, selectors, level, parent, options) {
  if (isEmpty(selectors)) { return; }

  foreach(selectors, (value, key) => {
    processRules(css, name + key, value.rules, level, parent, options);
  });
}
github martinandert / babel-plugin-css-in-js / src / index.js View on Github external
this.file.metadata.css = css;

        if (css && css.length) {
          context[KEY].cache[this.cssInJS.filename] = css;
        } else {
          delete context[KEY].cache[this.cssInJS.filename];
        }

        if (this.cssInJS.options.bundleFile && Object.keys(context[KEY].cache).length) {
          const bundleFile = join(process.cwd(), this.cssInJS.options.bundleFile);
          const output = [];

          mkDirPSync(dirname(bundleFile));

          foreach(context[KEY].cache, (fileCSS) => {
            output.push(fileCSS);
          });

          writeFileSync(bundleFile, output.join(''), { encoding: 'utf8' });
        }

        context[KEY].visiting[filename] = false;
      },
    },
github martinandert / react-inline / src / buildCSS.js View on Github external
export default function(stylesheets, options) {
  let css = '';

  foreach(stylesheets, (stylesheet, name) => {
    let cssOptions = extend({}, options);
    cssOptions.prefixes = [options.filename, name];

    css += transformSpecificationIntoCSS(stylesheet, cssOptions);

    if (css.length) {
      css += '\n';
    }
  });

  if (css.length === 0) {
    return null;
  }

  const vp = options.vendorPrefixes;
github martinandert / babel-plugin-css-in-js / src / transformSpecificationIntoCSS.js View on Github external
function processParents(css, name, parents, level, options) {
  if (isEmpty(parents)) { return; }

  foreach(parents, (spec, key) => {
    processStyle(css, name, spec, level, key, options);
  });
}
github martinandert / react-inline / src / transformSpecificationIntoCSS.js View on Github external
function processRules(css, name, rules, level, options) {
  if (isEmpty(rules)) { return; }

  css.push(indent(level) + '.' + generateClassName(name, options) + ' {');

  foreach(rules, (value, key) => {
    css.push(indent(level + 1) + buildCSSRule(key, value, options));
  });

  css.push(indent(level) + '}');
}

foreach

foreach component + npm package

MIT
Latest version published 3 years ago

Package Health Score

65 / 100
Full package analysis

Popular foreach functions