[Pkg-javascript-commits] [node-prr] 01/02: Imported Upstream version 1.0.0

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Sun Jun 29 19:01:52 UTC 2014


This is an automated email from the git hooks/post-receive script.

andrewrk-guest pushed a commit to branch master
in repository node-prr.

commit 220b210379c18f401e2da499fc982165cb2252b1
Author: Andrew Kelley <superjoe30 at gmail.com>
Date:   Sun Jun 29 18:56:51 2014 +0000

    Imported Upstream version 1.0.0
---
 .gitignore   |   1 +
 .jshintrc    |  61 +++++++++++++++++++++
 .travis.yml  |  10 ++++
 LICENSE      |  39 ++++++++++++++
 README.md    |  47 +++++++++++++++++
 package.json |  26 +++++++++
 prr.js       |  63 ++++++++++++++++++++++
 test.js      | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 416 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b512c09
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
\ No newline at end of file
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..6a7a956
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,61 @@
+{
+    "predef": [ ]
+  , "bitwise": false
+  , "camelcase": false
+  , "curly": false
+  , "eqeqeq": false
+  , "forin": false
+  , "immed": false
+  , "latedef": false
+  , "newcap": true
+  , "noarg": true
+  , "noempty": true
+  , "nonew": true
+  , "plusplus": false
+  , "quotmark": true
+  , "regexp": false
+  , "undef": true
+  , "unused": true
+  , "strict": false
+  , "trailing": true
+  , "maxlen": 120
+  , "asi": true
+  , "boss": true
+  , "debug": true
+  , "eqnull": true
+  , "es5": true
+  , "esnext": true
+  , "evil": true
+  , "expr": true
+  , "funcscope": false
+  , "globalstrict": false
+  , "iterator": false
+  , "lastsemic": true
+  , "laxbreak": true
+  , "laxcomma": true
+  , "loopfunc": true
+  , "multistr": false
+  , "onecase": false
+  , "proto": false
+  , "regexdash": false
+  , "scripturl": true
+  , "smarttabs": false
+  , "shadow": false
+  , "sub": true
+  , "supernew": false
+  , "validthis": true
+  , "browser": true
+  , "couch": false
+  , "devel": false
+  , "dojo": false
+  , "mootools": false
+  , "node": true
+  , "nonstandard": true
+  , "prototypejs": false
+  , "rhino": false
+  , "worker": true
+  , "wsh": false
+  , "nomen": false
+  , "onevar": true
+  , "passfail": false
+}
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..33dcbc3
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,10 @@
+language: node_js
+node_js:
+  - 0.8
+  - "0.10"
+branches:
+  only:
+    - master
+notifications:
+  email:
+    - rod at vagg.org
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..f6a0029
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,39 @@
+Copyright 2013, Rod Vagg (the "Original Author")
+All rights reserved.
+
+MIT +no-false-attribs License
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+Distributions of all or part of the Software intended to be used
+by the recipients as they would use the unmodified Software,
+containing modifications that substantially alter, remove, or
+disable functionality of the Software, outside of the documented
+configuration mechanisms provided by the Software, shall be
+modified such that the Original Author's bug reporting email
+addresses and urls are either replaced with the contact information
+of the parties responsible for the changes, or removed entirely.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+
+Except where noted, this license applies to any and all software
+programs and associated documentation files created by the
+Original Author, when distributed with the Software.
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..17baa95
--- /dev/null
+++ b/README.md
@@ -0,0 +1,47 @@
+# prr [![Build Status](https://secure.travis-ci.org/rvagg/prr.png)](http://travis-ci.org/rvagg/prr)
+
+An sensible alternative to `Object.defineProperty()`. Available in npm and Ender as **prr**.
+
+## Usage
+
+Set the property `'foo'` (`obj.foo`) to have the value `'bar'` with default options (`'enumerable'`, `'configurable'` and `'writable'` are all `false`):
+
+```js
+prr(obj, 'foo', 'bar')
+```
+
+Adjust the default options:
+
+```js
+prr(obj, 'foo', 'bar', { enumerable: true, writable: true })
+```
+
+Do the same operation for multiple properties:
+
+```js
+prr(obj, { one: 'one', two: 'two' })
+// or with options:
+prr(obj, { one: 'one', two: 'two' }, { enumerable: true, writable: true })
+```
+
+### Simplify!
+
+But obviously, having to write out the full options object makes it nearly as bad as the original `Object.defineProperty()` so we can simplify.
+
+As an alternative method we can use an options string where each character represents a option: `'e'=='enumerable'`, `'c'=='configurable'` and `'w'=='writable'`:
+
+```js
+prr(obj, 'foo', 'bar', 'ew') // enumerable and writable but not configurable
+// muliple properties:
+prr(obj, { one: 'one', two: 'two' }, 'ewc') // configurable too
+```
+
+## Where can I use it?
+
+Anywhere! For pre-ES5 environments *prr* will simply fall-back to an `object[property] = value` so you can get close to what you want.
+
+*prr* is Ender-compatible so you can include it in your Ender build and `$.prr(...)` or `var prr = require('prr'); prr(...)`.
+
+## Licence
+
+prr is Copyright (c) 2013 Rod Vagg [@rvagg](https://twitter.com/rvagg) and licensed under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.
\ No newline at end of file
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..539a7d3
--- /dev/null
+++ b/package.json
@@ -0,0 +1,26 @@
+{
+  "name": "prr",
+  "description": "A better Object.defineProperty()",
+  "version": "1.0.0",
+  "homepage": "https://github.com/rvagg/prr",
+  "author": "Rod Vagg <rod at vagg.org> (https://github.com/rvagg)",
+  "keywords": [
+    "property",
+    "properties",
+    "defineProperty",
+    "ender"
+  ],
+  "main": "./prr.js",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/rvagg/prr.git"
+  },
+  "dependencies": {},
+  "devDependencies": {
+    "tap": "*"
+  },
+  "scripts": {
+    "test": "node ./test.js"
+  },
+  "license": "MIT"
+}
diff --git a/prr.js b/prr.js
new file mode 100644
index 0000000..94f5862
--- /dev/null
+++ b/prr.js
@@ -0,0 +1,63 @@
+/*!
+  * prr
+  * (c) 2013 Rod Vagg <rod at vagg.org>
+  * https://github.com/rvagg/prr
+  * License: MIT
+  */
+
+(function (name, context, definition) {
+  if (typeof module != 'undefined' && module.exports)
+    module.exports = definition()
+  else
+    context[name] = definition()
+})('prr', this, function() {
+
+  var setProperty = typeof Object.defineProperty == 'function'
+      ? function (obj, key, options) {
+          Object.defineProperty(obj, key, options)
+          return obj
+        }
+      : function (obj, key, options) { // < es5
+          obj[key] = options.value
+          return obj
+        }
+
+    , makeOptions = function (value, options) {
+        var oo = typeof options == 'object'
+          , os = !oo && typeof options == 'string'
+          , op = function (p) {
+              return oo
+                ? !!options[p]
+                : os
+                  ? options.indexOf(p[0]) > -1
+                  : false
+            }
+
+        return {
+            enumerable   : op('enumerable')
+          , configurable : op('configurable')
+          , writable     : op('writable')
+          , value        : value
+        }
+      }
+
+    , prr = function (obj, key, value, options) {
+        var k
+
+        options = makeOptions(value, options)
+
+        if (typeof key == 'object') {
+          for (k in key) {
+            if (Object.hasOwnProperty.call(key, k)) {
+              options.value = key[k]
+              setProperty(obj, k, options)
+            }
+          }
+          return obj
+        }
+
+        return setProperty(obj, key, options)
+      }
+
+  return prr
+})
\ No newline at end of file
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..5222e30
--- /dev/null
+++ b/test.js
@@ -0,0 +1,169 @@
+const test = require('tap').test
+    , prr  = require('./')
+
+test('test prr(o, key, value) form', function (t) {
+  t.plan(2)
+
+  var o = {}
+  prr(o, 'foo', 'bar')
+  t.equal(o.foo, 'bar', 'correct value')
+  t.deepEqual(
+      Object.getOwnPropertyDescriptor(o, 'foo')
+    , {
+          enumerable   : false
+        , configurable : false
+        , writable     : false
+        , value        : 'bar'
+      }
+    , 'correct property descriptor'
+  )
+  t.end()
+})
+
+test('test prr(o, { key: value }) form', function (t) {
+  t.plan(2)
+
+  var o = {}
+  prr(o, { foo: 'bar' })
+
+  t.equal(o.foo, 'bar', 'correct value')
+  t.deepEqual(
+      Object.getOwnPropertyDescriptor(o, 'foo')
+    , {
+          enumerable   : false
+        , configurable : false
+        , writable     : false
+        , value        : 'bar'
+      }
+    , 'correct property descriptor'
+  )
+  t.end()
+})
+
+test('test multiple key:value pairs', function (t) {
+  var o = { foo: 'bar' }
+
+  prr(o, { one: 'ONE', two: 'TWO', obj: { o: 'o' }})
+
+  t.deepEqual(o, { foo: 'bar' }, 'properties are not enumerable')
+  t.equal(o.one, 'ONE', 'correctly set property')
+  t.equal(o.two, 'TWO', 'correctly set property')
+  t.deepEqual(o.obj, { o: 'o' }, 'correctly set property')
+
+  ;[ 'one', 'two', 'obj' ].forEach(function (p) {
+    t.deepEqual(
+        Object.getOwnPropertyDescriptor(o, p)
+      , {
+            enumerable   : false
+          , configurable : false
+          , writable     : false
+          , value        : p == 'obj' ? { o: 'o' } : p.toUpperCase()
+        }
+      , 'correct property descriptor'
+    )
+  })
+
+  t.end()
+})
+
+test('test descriptor options', function (t) {
+  var o = {}
+
+  prr(o, 'foo', 'bar', {
+      enumerable   : true
+    , configurable : false
+  })
+  t.equal(o.foo, 'bar', 'correct value')
+  t.deepEqual(
+      Object.getOwnPropertyDescriptor(o, 'foo')
+    , {
+          enumerable   : true
+        , configurable : false
+        , writable     : false
+        , value        : 'bar'
+      }
+    , 'correct property descriptor'
+  )
+
+  prr(o, 'foo2', 'bar2', {
+      enumerable   : true
+    , configurable : true
+    , writable     : false
+  })
+  t.equal(o.foo2, 'bar2', 'correct value')
+  t.deepEqual(
+      Object.getOwnPropertyDescriptor(o, 'foo2')
+    , {
+          enumerable   : true
+        , configurable : true
+        , writable     : false
+        , value        : 'bar2'
+      }
+    , 'correct property descriptor'
+  )
+
+  prr(o, 'foo3', 'bar3', {
+      enumerable   : true
+    , configurable : true
+    , writable     : true
+  })
+  t.equal(o.foo3, 'bar3', 'correct value')
+  t.deepEqual(
+      Object.getOwnPropertyDescriptor(o, 'foo3')
+    , {
+          enumerable   : true
+        , configurable : true
+        , writable     : true
+        , value        : 'bar3'
+      }
+    , 'correct property descriptor'
+  )
+
+  t.end()
+})
+
+
+test('test descriptor options, string form', function (t) {
+  var o = {}
+
+  prr(o, 'foo', 'bar', 'e')
+  t.equal(o.foo, 'bar', 'correct value')
+  t.deepEqual(
+      Object.getOwnPropertyDescriptor(o, 'foo')
+    , {
+          enumerable   : true
+        , configurable : false
+        , writable     : false
+        , value        : 'bar'
+      }
+    , 'correct property descriptor'
+  )
+
+  prr(o, 'foo2', 'bar2', 'ec')
+  t.equal(o.foo2, 'bar2', 'correct value')
+  t.deepEqual(
+      Object.getOwnPropertyDescriptor(o, 'foo2')
+    , {
+          enumerable   : true
+        , configurable : true
+        , writable     : false
+        , value        : 'bar2'
+      }
+    , 'correct property descriptor'
+  )
+
+  prr(o, 'foo3', 'bar3', 'ecw')
+  t.equal(o.foo3, 'bar3', 'correct value')
+  t.deepEqual(
+      Object.getOwnPropertyDescriptor(o, 'foo3')
+    , {
+          enumerable   : true
+        , configurable : true
+        , writable     : true
+        , value        : 'bar3'
+      }
+    , 'correct property descriptor'
+  )
+
+  t.end()
+})

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-prr.git



More information about the Pkg-javascript-commits mailing list