<commit_before>var schema = require('protobuf-schema')
var compile = require('./compile')

module.exports = function(proto, opts) {
  if (!opts) opts = {}
  if (!proto) throw new Error('Pass in a .proto string or a protobuf-schema parsed object')

  var sch = (typeof proto === 'object' && !Buffer.isBuffer(proto)) ? proto : schema.parse(proto)
  var that = {}

  compile(sch, opts.encodings || {}).forEach(function(m) {
    that[m.name] = m.values || m
  })

  that.toString = function() {
    return schema.stringify(sch)
  }

  that.toJSON = function() {
    return sch
  }

  return that
}<commit_msg>make toJSON,toString non-enumarable<commit_after>var schema = require('protobuf-schema')
var compile = require('./compile')


module.exports = function(proto, opts) {
  if (!opts) opts = {}
  if (!proto) throw new Error('Pass in a .proto string or a protobuf-schema parsed object')

  var sch = (typeof proto === 'object' && !Buffer.isBuffer(proto)) ? proto : schema.parse(proto)

  // to not make toString,toJSON enumarable we make a fire-and-forget prototype
  var Messages = function() {
    var self = this

    compile(sch, opts.encodings || {}).forEach(function(m) {
      self[m.name] = m.values || m
    })
  }

  Messages.prototype.toString = function() {
    return schema.stringify(sch)
  }

  Messages.prototype.toJSON = function() {
    return sch
  }

  return new Messages()
}
{'fraction_non_alphanumeric': 0.1489971346704871, 'fraction_numerical': 0.0, 'mean_word_length': 3.565359477124183, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1574959', 'n_tokens_mistral': 446, 'n_tokens_neox': 431, 'n_words': 121}