How to use the traverse.map function in traverse

To help you get started, we’ve selected a few traverse 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 WordPress / gutenberg / packages / block-editor / src / utils / transform-styles / traverse.js View on Github external
function traverseCSS( css, callback ) {
	try {
		const parsed = parse( css );

		const updated = traverse.map( parsed, function( node ) {
			if ( ! node ) {
				return node;
			}
			const updatedNode = callback( node );
			return this.update( updatedNode );
		} );

		return stringify( updated );
	} catch ( err ) {
		// eslint-disable-next-line no-console
		console.warn( 'Error while traversing the CSS: ' + err );

		return null;
	}
}
github taskcluster / mozilla-taskcluster / src / jobs / retrigger.js View on Github external
export function recursiveUpdateTaskIds(tasks, map) {
  return traverse.map(tasks, function (value) {
    // Do not attempt to change old task Ids
    if (this.key === 'oldTaskId') return value;
    // Only operate on values that are strings;
    if (typeof value !== 'string') return value;
    // XXX: This is slow and somewhat terrible but reliable... The task ids may
    // appear anywhere in the graph (though it may not be super useful to do
    // so).
    Object.keys(map).forEach((oldTaskId) => {
      let newTaskId = map[oldTaskId];
      // .replace does not replace all matches so iterate through all matches.
      while (value.indexOf(oldTaskId) !== -1) {
        value = value.replace(oldTaskId, newTaskId);
      }
    });
    return value;
  });
github react-cosmos / react-cosmos / packages / react-cosmos-test / src / generic.js View on Github external
function decorateFixture(fixture: FixtureType<p>): FixtureType</p><p> {
  if (!inJestEnv() || !fixture.props) {
    return fixture;
  }

  return {
    ...fixture,
    props: traverse.map(fixture.props, addJestWrapper)
  };
}
</p>
github joola / joola / lib / dispatch / beacon.js View on Github external
var buildRowKey = function(obj) {
      var key;
      try {
        key = obj[_collection.time_field || 'timestamp'].toISOString();
      } catch (ex) {
        key = '';
      }
      traverse.map(obj, function(x) {
        if (x && typeof(x) === 'string') {
          key += x;
        }
      });
      key = joola.common.hash(key);
      return key;
    };