How to use traverse - 10 common examples

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 zodern / meteor-up / src / plugins / meteor / index.js View on Github external
export function scrubConfig(config, utils) {
  if (config.meteor) {
    delete config.meteor;
  }

  if (config.app) {
    // eslint-disable-next-line
    config.app = traverse(config.app).map(function () {
      const path = this.path.join('.');

      switch (path) {
        case 'name':
          return this.update('my-app');
        case 'buildOptions.server':
          return this.update(utils.scrubUrl(this.node));

        case 'env.ROOT_URL':
          return this.update(utils.scrubUrl(this.node));

        case 'env.MONGO_URL':
          if (config.mongo) {
            const url = this.node.split('/');
            url.pop();
            url.push('my-app');
github fergiemcdowall / search-index / src / write.js View on Github external
const invertDoc = function (obj) {
    const invertedDoc = {}
    // take a plain old JSON object and parse out all of the leaf-nodes
    trav(obj).forEach(function (node) {
      if (typeof node === 'undefined') return
      const self = this
      let searchable = true
      this.path.forEach(item => {
        // denotes that a field is indexable
        if (item === '_id') searchable = false
        if (item.substring(0, 1) === '!') searchable = false
      })
      if (searchable && this.isLeaf) {
        invertedDoc[self.path.filter(item => {  // eslint-disable-line
          return isNaN(item)
        }).join('.')] = (self.node + '').split(' ')
      }
    })
    return invertedDoc
  }
github crcn / node-awsm / lib / base / loadableCollection.js View on Github external
this.load({}, outcome.e(next).s(function(models) {

      // doesn't work for regexp

      if (typeof query === "object") {
        query = traverse.clone(query);
        // query = JSON.parse(JSON.stringify(query));

      }


      var sifter = sift(query);


      next(null, models.filter(function (model) {
        return sifter.test(model.context());
      }));
    }));
  },
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 zodern / meteor-up / src / plugins / default / index.js View on Github external
export function scrubConfig(config) {
  if (config.servers) {
    // eslint-disable-next-line
    config.servers = traverse(config.servers).map(function() {
      if (this.path.length !== 2) {
        // eslint-disable-next-line
        return;
      }

      switch (this.key) {
        case 'host':
          return this.update('1.2.3.4');
        case 'password':
          return this.update('password');
        case 'pem':
          return this.update('~/.ssh/pem');

        // no default
      }
    });
github caolan / nodeunit / node_modules / tap / node_modules / difflet / index.js View on Github external
function stringifier (insertable, node, opts) {
        var indent = opts.indent;
        
        if (insertable) {
            var prevNode = traverse.get(prev, this.path || []);
        }
        var inserted = insertable && prevNode === undefined;
        
        var indentx;
        try {
            indentx = indent ? Array(
                ((this.path || []).length + 1) * indent + 1
            ).join(' ') : '';
        } catch (e) {
            // at times we get an invalid Array size here and need to prevent crashing
            indentx = '';
        }
        if (commaFirst) indentx = indentx.slice(indent);
        
        if (Array.isArray(node)) {
            var updated = (prevNode || traverse.has(prev, this.path))
github PlayFab / NodeSDK / PlayFabTesting / node_modules / nodeunit / node_modules / tap / node_modules / difflet / index.js View on Github external
function stringifier (insertable, node, opts) {
        var indent = opts.indent;
        
        if (insertable) {
            var prevNode = traverse.get(prev, this.path || []);
        }
        var inserted = insertable && prevNode === undefined;
        
        var indentx;
        try {
            indentx = indent ? Array(
                ((this.path || []).length + 1) * indent + 1
            ).join(' ') : '';
        } catch (e) {
            // at times we get an invalid Array size here and need to prevent crashing
            indentx = '';
        }
        if (commaFirst) indentx = indentx.slice(indent);
        
        if (Array.isArray(node)) {
            var updated = (prevNode || traverse.has(prev, this.path))
github jamesshore / lets_code_javascript / node_modules / nodeunit / node_modules / tap / node_modules / difflet / index.js View on Github external
function stringifier (insertable, node, opts) {
        var indent = opts.indent;
        
        if (insertable) {
            var prevNode = traverse.get(prev, this.path || []);
        }
        var inserted = insertable && prevNode === undefined;
        
        var indentx;
        try {
            indentx = indent ? Array(
                ((this.path || []).length + 1) * indent + 1
            ).join(' ') : '';
        } catch (e) {
            // at times we get an invalid Array size here and need to prevent crashing
            indentx = '';
        }
        if (commaFirst) indentx = indentx.slice(indent);
        
        if (Array.isArray(node)) {
            var updated = (prevNode || traverse.has(prev, this.path))
github jamesshore / lets_code_javascript / node_modules / nodeunit / node_modules / tap / node_modules / difflet / index.js View on Github external
}
        var inserted = insertable && prevNode === undefined;
        
        var indentx;
        try {
            indentx = indent ? Array(
                ((this.path || []).length + 1) * indent + 1
            ).join(' ') : '';
        } catch (e) {
            // at times we get an invalid Array size here and need to prevent crashing
            indentx = '';
        }
        if (commaFirst) indentx = indentx.slice(indent);
        
        if (Array.isArray(node)) {
            var updated = (prevNode || traverse.has(prev, this.path))
                && !Array.isArray(prevNode);
            if (updated) {
                set('updated');
            }
            
            if (opts.comment && !Array.isArray(prevNode)) {
                indent = 0;
            }
            
            this.before(function () {
                if (inserted) set('inserted');
                if (indent && commaFirst) {
                    if ((this.path || []).length === 0
                    || Array.isArray(this.parent.node)) {
                        write('[ ');
                    }
github PlayFab / NodeSDK / PlayFabTesting / node_modules / nodeunit / node_modules / tap / node_modules / difflet / index.js View on Github external
}
        var inserted = insertable && prevNode === undefined;
        
        var indentx;
        try {
            indentx = indent ? Array(
                ((this.path || []).length + 1) * indent + 1
            ).join(' ') : '';
        } catch (e) {
            // at times we get an invalid Array size here and need to prevent crashing
            indentx = '';
        }
        if (commaFirst) indentx = indentx.slice(indent);
        
        if (Array.isArray(node)) {
            var updated = (prevNode || traverse.has(prev, this.path))
                && !Array.isArray(prevNode);
            if (updated) {
                set('updated');
            }
            
            if (opts.comment && !Array.isArray(prevNode)) {
                indent = 0;
            }
            
            this.before(function () {
                if (inserted) set('inserted');
                if (indent && commaFirst) {
                    if ((this.path || []).length === 0
                    || Array.isArray(this.parent.node)) {
                        write('[ ');
                    }