{"size": 3619, "ext": "js", "max_stars_repo_path": "lib/smap.js", "max_stars_repo_name": "ragents/ragents-server", "max_stars_repo_stars_event_min_datetime": "2015-03-22T22:51:53.000Z", "max_stars_repo_stars_event_max_datetime": "2016-08-25T15:31:14.000Z", "max_issues_repo_path": "lib/smap.js", "max_issues_repo_name": "ragents/ragents", "max_issues_repo_issues_event_min_datetime": "2015-03-22T23:08:57.000Z", "max_issues_repo_issues_event_max_datetime": "2015-04-15T16:06:47.000Z", "max_forks_repo_path": "lib/smap.js", "max_forks_repo_name": "ragents/ragents-server", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 4, "max_forks_count": null, "avg_line_length": 27.6259541985, "max_line_length": 80, "alphanum_fraction": 0.4244266372}
// Licensed under the Apache License. See footer for details.

//------------------------------------------------------------------------------
// simplified es6 map that only supports string keys and non-undefined vals
//------------------------------------------------------------------------------

var _ = require("underscore")

//------------------------------------------------------------------------------
module.exports = SMap

var PROP_PREFIX     = "#"
var PROP_PREFIX_LEN = PROP_PREFIX.length

//------------------------------------------------------------------------------
function SMap() {
  this.clear()

  var map = this

  Object.defineProperty(this, "size", {
    get: function() { return _.size(map._entries) }
  })
}

SMap.prototype.clear   = clear
SMap.prototype.delete  = delete_
SMap.prototype.entries = entries
SMap.prototype.forEach = forEach
SMap.prototype.get     = get
SMap.prototype.has     = has
SMap.prototype.keys    = keys
SMap.prototype.set     = set
SMap.prototype.values  = values

//------------------------------------------------------------------------------
function asProp(key) {
  return PROP_PREFIX + key
}

//------------------------------------------------------------------------------
function asKey(prop) {
  return prop.slice(PROP_PREFIX_LEN)
}

//------------------------------------------------------------------------------
function clear() {
  this._entries = {}
}

//------------------------------------------------------------------------------
function delete_(key) {
  delete this._entries[asProp(key)]
}

//------------------------------------------------------------------------------
function entries() {
  var result = []

  this.forEach(function(val, key) {
    result.push( [ key, val ] )
  })

  return result
}

//------------------------------------------------------------------------------
function forEach(cb, that) {
  // cb(val, key, map)

  if (!that) that = undefined

  var map = this

  _.each(this._entries, function(val, key) {
    cb.call(that, val, asKey(key), map)
  })
}

//------------------------------------------------------------------------------
function get(key) {
  return this._entries[asProp(key)]
}

//------------------------------------------------------------------------------
function has(key) {
  return this.get(key) !== undefined
}

//------------------------------------------------------------------------------
function keys() {
  var result = []

  this.forEach(function(val, key) {
    result.push( key )
  })

  return result
}

//------------------------------------------------------------------------------
function set(key, value) {
  this._entries[asProp(key)] = value
  return this
}

//------------------------------------------------------------------------------
function values() {
  var result = []

  this.forEach(function(val, key) {
    result.push( val )
  })

  return result
}

//------------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//------------------------------------------------------------------------------
