Skip to content

Commit

Permalink
Merge pull request #5 from Skelp/develop
Browse files Browse the repository at this point in the history
Version 0.2.0
  • Loading branch information
neocotic committed Mar 23, 2017
2 parents bee3432 + 54d7c8d commit 3496755
Show file tree
Hide file tree
Showing 11 changed files with 447 additions and 42 deletions.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Version 0.2.0, 2017.03.23

* Correct anchor links in `README.md` [#2](https://github.com/Skelp/scopy/issues/2)
* Add method to provide a wrapped Scopy API for specific options [#3](https://github.com/Skelp/scopy/issues/3)
* Alias `Scopy.forAll` to `Scopy.for.all` [#4](https://github.com/Skelp/scopy/issues/4)

## Version 0.1.0, 2017.03.22

* Initial release
53 changes: 41 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ install that way instead of using `npm`. While equals should be compatible with

If you want to simply download the file to be used in the browser you can find them below:

* [Development Version](https://cdn.rawgit.com/Skelp/scopy/master/dist/scopy.js) (19kb - [Source Map](https://cdn.rawgit.com/Skelp/scopy/master/dist/scopy.js.map))
* [Production Version](https://cdn.rawgit.com/Skelp/scopy/master/dist/scopy.min.js) (1.3kb - [Source Map](https://cdn.rawgit.com/Skelp/scopy/master/dist/scopy.min.js.map))
* [Development Version](https://cdn.rawgit.com/Skelp/scopy/master/dist/scopy.js) (23kb - [Source Map](https://cdn.rawgit.com/Skelp/scopy/master/dist/scopy.js.map))
* [Production Version](https://cdn.rawgit.com/Skelp/scopy/master/dist/scopy.min.js) (1.6kb - [Source Map](https://cdn.rawgit.com/Skelp/scopy/master/dist/scopy.min.js.map))

## API

Expand All @@ -65,7 +65,10 @@ All API methods accept the same optional `options` parameter:
| `symbol` | Whether to use ES2015's `Symbol`, where supported. | `true` |

When specifying `options` for any API method call, it is recommended to pass the same options to all other API method
calls within your application/library to ensure that the same type of scoped keys are returned.
calls within your application/library to ensure that the same type of scoped keys are returned. Alternatively, the
[Scopy.using](#scopyusingoptions) method can be used to create wrapped version of the Scopy API that will always use the
specified options for all methods called on the wrapped API, avoiding the need for duplicating the options throughout
your code base.

### `Scopy(name[, options])`

Expand Down Expand Up @@ -137,7 +140,7 @@ Returns a "global" key based on the specified `name` and using the `options` pro
If the `symbol` option is enabled (which it is by default), an ES2015 `Symbol` will be returned from the runtime-wide
symbol registry (where supported), otherwise this method will simply return `name` prefixed with an underscore.

Unlike [Scopy](#scopynameoptions), `Symbols` returned by this method will always be the same when called multiple times
Unlike [Scopy](#scopyname-options), `Symbols` returned by this method will always be the same when called multiple times
with the same `name`, just like string keys.

It is recommended that `name` be prefixed in order to avoid conflicts with other libraries that may also have a "global"
Expand Down Expand Up @@ -177,15 +180,17 @@ exports.login = function(output, user) {
}
```

### `Scopy.forAll(names[, options])`
### `Scopy.for.all(names[, options])`

**Alias:** `Scopy.forAll`

Returns "global" keys based on the specified `names` and using the `options` provided.

If the `symbol` option is enabled (which it is by default), this method will return `names` mapped to ES2015 `Symbols`
from the runtime-wide symbol registry (where supported), otherwise `names` will simply be mapped to themselves prefixed
with an underscore.

Unlike [Scopy.all](#scopyallnamesoptions), `Symbols` included in the mapping returned by this method will always be the
Unlike [Scopy.all](#scopyallnames-options), `Symbols` included in the mapping returned by this method will always be the
same when called multiple times with the same name, just like string keys.

It is recommended that each name within `names` be prefixed in order to avoid conflicts with other libraries that may
Expand All @@ -198,7 +203,7 @@ This method is ideal when defining keys for protected/internally scoped properti
var Scopy = require('scopy')
var uuid = require('node-uuid/v4')

var keys = Scopy.forAll([ 'example_user_id', 'example_user_lastUpdatedBy' ])
var keys = Scopy.for.all([ 'example_user_id', 'example_user_lastUpdatedBy' ])
var _name = Scopy('name')

function User(name) {
Expand All @@ -217,7 +222,7 @@ module.exports = User
var EOL = require('os').EOL
var Scopy = require('scopy')

var keys = Scopy.forAll([ 'example_user_id', 'example_user_lastUpdatedBy' ])
var keys = Scopy.for.all([ 'example_user_id', 'example_user_lastUpdatedBy' ])

exports.update = function(output, user) {
var id = user[keys['example.user.id']]
Expand Down Expand Up @@ -284,9 +289,9 @@ User.prototype.getName = function() {
}

Scopy.entries(new User('foo'))
//=> [ [ 'length', 3 ] ]
//=> [ [ "length", 3 ] ]
Scopy.entries(User.prototype)
//=> [ [ 'getName', function() { return this[_name] } ] ]
//=> [ [ "getName", function() { return this[_name] } ] ]
```

### `Scopy.keys(obj[, options])`
Expand Down Expand Up @@ -324,9 +329,9 @@ User.prototype.getName = function() {
}

Scopy.keys(new User('foo'))
//=> [ 'length' ]
//=> [ "length" ]
Scopy.keys(User.prototype)
//=> [ 'getName' ]
//=> [ "getName" ]
```

### `Scopy.values(obj[, options])`
Expand Down Expand Up @@ -369,6 +374,30 @@ Scopy.values(User.prototype)
//=> [ function() { return this[_name] } ]
```

### `Scopy.using([options])`

Returns a version of [Scopy](#scopyname-options) that is bound (along with *all* of its methods) to the specified
`options`.

Since it's recommended that consumers use the same options, when specified, this method can be really useful as it
allows consumers to only specify the options once. This is especially useful for those wishing to explictly disable the
`symbol` option.

Any options passed to the methods within the returned wrapped Scopy API will be ignored in favor of `options`.

``` javascript
var Scopy = require('scopy').using({ symbol: false })

Scopy('foo')
//=> "_foo"
Scopy.all([ 'foo', 'bar' ])
//=> { foo: "_foo", bar: "_bar" }
Scopy.is('_foo')
//=> true
Scopy.is(Symbol('foo'))
//=> false
```

## Bugs

If you have any problems with Scopy or would like to see changes currently in development you can do so
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scopy",
"version": "0.1.0",
"version": "0.2.0",
"description": "Property scoping done quick and dirty",
"homepage": "https://github.com/Skelp/scopy",
"authors": [
Expand Down
123 changes: 115 additions & 8 deletions dist/scopy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/scopy.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/scopy.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/scopy.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scopy",
"version": "0.1.0",
"version": "0.2.0",
"description": "Property scoping done quick and dirty",
"homepage": "https://github.com/Skelp/scopy",
"bugs": {
Expand Down

0 comments on commit 3496755

Please sign in to comment.