prime-util
Advanced tools
Comparing version 0.3.2 to 0.4.0
"use strict"; | ||
var contains = require('./contains') | ||
var contains = require('mout/array/contains') | ||
@@ -5,0 +5,0 @@ function include(array, item){ |
"use strict"; | ||
var hasOwn = require('prime/object/hasOwn') | ||
var get = require('mout/object/get') | ||
var kindOf = require('mout/lang/kindOf') | ||
function fromPath(source, parts){ | ||
if (typeof parts == 'string') parts = parts.split('.') | ||
for (var i = 0, l = parts.length; i < l; i++){ | ||
if (hasOwn(source, parts[i])) source = source[parts[i]] | ||
else return null | ||
} | ||
return source | ||
function fromPath(source, parts) { | ||
var result | ||
if (kindOf(parts) == 'Array') { | ||
parts = parts.join('.') | ||
} | ||
result = get(source, parts) | ||
return result == undefined ? null : result | ||
} | ||
module.exports = fromPath |
{ | ||
"name": "prime-util", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"description": "Extra Utilities using Prime", | ||
@@ -16,3 +16,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"prime": "0.3" | ||
"prime": "~0.4.0", | ||
"mout": "~0.9.0" | ||
}, | ||
@@ -19,0 +20,0 @@ "devDependencies": { |
@@ -7,3 +7,3 @@ "use strict"; | ||
var prime = require("prime") | ||
var bind = require("prime/function/bind") | ||
var bind = require("mout/function/bind") | ||
@@ -10,0 +10,0 @@ var bound = prime({ |
"use strict"; | ||
var prime = require('prime') | ||
var object = require('../shell/object') | ||
var prime = require("prime") | ||
var merge = require("mout/object/merge") | ||
@@ -11,3 +11,3 @@ var Options = prime({ | ||
args.push.apply(args, arguments) | ||
this.options = object.merge.apply(null, args) | ||
this.options = merge.apply(null, args) | ||
return this | ||
@@ -14,0 +14,0 @@ } |
"use strict"; | ||
var prime = require('prime') | ||
var slice = require('prime/array/slice') | ||
var prime = require("prime") | ||
var slice = require("mout/array/slice") | ||
@@ -6,0 +6,0 @@ module.exports = prime({ |
127
README.md
@@ -14,11 +14,2 @@ Prime-Util | ||
### prime/mixin | ||
Mixin other primes into another prime | ||
```js | ||
var mixin = require('prime-util/prime/mixin') | ||
mixin(MyPrime, Options, Events) | ||
``` | ||
### prime/bound | ||
@@ -32,5 +23,5 @@ | ||
var bound = require("prime-util/prime/bound") | ||
var mixin = require("prime-util/prime/mixin") | ||
var MyPrime = prime({ | ||
mixin: [bound], | ||
constructor: function(){ | ||
@@ -47,3 +38,2 @@ this.results = [] | ||
}) | ||
mixin(MyPrime, bound) | ||
``` | ||
@@ -58,4 +48,5 @@ | ||
var array = require('prime/array') | ||
var mixin = require('prime-util/prime/mixin') | ||
var A = prime({ | ||
mixin: [parentize], | ||
a: function(){ | ||
@@ -66,2 +57,3 @@ return array.join(arguments) | ||
var B = prime({ | ||
mixin: [parentize], | ||
inherits: A, | ||
@@ -74,3 +66,3 @@ a: function(){ | ||
}) | ||
mixin(B, parentize) | ||
var b = new B | ||
@@ -89,2 +81,3 @@ console.log(b) // logs "b,c,d" | ||
var A = prime({ | ||
mixin: [Options], | ||
@@ -106,4 +99,2 @@ options: { | ||
mixin(A, Options) | ||
var a = new A({'b': 'B', 'c': {'e': 'E'}}) | ||
@@ -113,35 +104,4 @@ console.log(a.options); // {'a': 'aaa', 'b': 'B', 'c': {'d': 'ddd', 'e': 'E'}} | ||
### shell/array | ||
### array/associate | ||
Familiar MooTools Array functions. This module puts the array functions listed | ||
below in the prime array shell. | ||
```js | ||
var array = require('prime-util/shell/array') | ||
array.contains([1, 2, 3], 2) // true | ||
``` | ||
#### array/clean | ||
Create a new array with all elements that are not null or undefined. | ||
```js | ||
var clean = require('prime-util/array/clean') | ||
clean([null, 2, "foo", undefined]) // [2, "foo"] | ||
``` | ||
#### array/invoke | ||
Return an array with the named method applied on the array's content. | ||
```js | ||
invoke([ | ||
{a: function(arg){ console.log("first", arg)}}, | ||
{a: function(arg){ console.log("second", arg)}} | ||
], 'a', "thing") // logs "first thing" "second thing" | ||
``` | ||
#### array/associate | ||
Creates an object with key-value pairs based on the array of keywords passed in | ||
@@ -157,16 +117,4 @@ and the current content of the array. | ||
#### array/contains | ||
### array/last | ||
Returns true if a value is in the array, otherwise it returns false. | ||
#### array/append | ||
Appends the passed array to the end of the current array. | ||
```js | ||
append([1, 2, 3], [4, 5, [6]]) // [1, 2, 3, 4, 5, [6]] | ||
``` | ||
#### array/last | ||
Returns the last value of the array. | ||
@@ -178,8 +126,4 @@ | ||
#### array/random | ||
### array/include | ||
Returns a random item from the array. | ||
#### array/include | ||
Pushes the passed element into the array if it's not already present (case and | ||
@@ -192,14 +136,5 @@ type sensitive). | ||
``` | ||
#### array/combine | ||
Combines an array with all the items of another. Does not allow duplicates and | ||
is case and type sensitive. | ||
### array/empty | ||
```js | ||
var animals = ['Cow', 'Pig', 'Dog'] | ||
combine(animals, ['Cat', 'Dog']; //animals = ['Cow', 'Pig', 'Dog', 'Cat'] | ||
``` | ||
#### array/empty | ||
Empties an array. | ||
@@ -212,3 +147,3 @@ | ||
#### array/pick | ||
### array/pick | ||
@@ -222,23 +157,4 @@ Returns the first defined value of the array passed in, or null. | ||
#### array/find | ||
### object/merge | ||
Returns the first item in the array for which the function returns true. | ||
```js | ||
find([1, 2, 3, 4, 5], function(number){ | ||
return number == 2 | ||
}) // returns 2 | ||
``` | ||
### shell/object | ||
Add the object functions to the prime object shell | ||
```js | ||
var object = require('prime-util/shell/object') | ||
object.fromPath({a: {b: 1}}, 'a.b') | ||
``` | ||
#### object/merge | ||
Merges different objects into one object. | ||
@@ -250,10 +166,13 @@ | ||
``` | ||
#### object/fromPath | ||
Returns the value at a given path | ||
```js | ||
var fromPath = require('prime-util/object/fromPath') | ||
var demo = {'a': {'b': {'c': 'prime!'}}}; | ||
fromPath(demo, 'a.b.c') // prime! | ||
``` | ||
## Removed Modules | ||
The following modules have been removed: | ||
* prime/mixin | ||
* array/clean - use (mout/array/compact) | ||
* array/invoke - use (mout/array/invoke) | ||
* array/contains - use (mout/array/contains) | ||
* array/append - use (mout/array/append) | ||
* array/random - use (mout/random/choice) | ||
* array/combine - use (mout/array/combine) | ||
* array/find - use (mout/array/find) | ||
* object/merge - use (mout/array/merge) |
@@ -6,5 +6,5 @@ "use strict"; | ||
var bound = require("../../prime/bound") | ||
var mixin = require("../../prime/mixin") | ||
var MyClass = prime({ | ||
mixin: [bound], | ||
@@ -25,4 +25,2 @@ constructor: function(){ | ||
mixin(MyClass, bound) | ||
describe("bound", function(){ | ||
@@ -29,0 +27,0 @@ |
@@ -5,6 +5,6 @@ "use strict"; | ||
var prime = require('prime') | ||
var mixin = require('../../prime/mixin') | ||
var Options = require('../../prime/options') | ||
var A = prime({ | ||
mixin: [Options], | ||
@@ -27,2 +27,3 @@ options: { | ||
var B = prime({ | ||
mixin: [Options], | ||
@@ -44,5 +45,2 @@ options: { | ||
mixin(A, Options) | ||
mixin(B, Options) | ||
describe('Options', function(){ | ||
@@ -49,0 +47,0 @@ |
@@ -5,3 +5,2 @@ "use strict"; | ||
var prime = require('prime') | ||
var mixin = require('../../prime/mixin') | ||
var parentize = require('../../prime/parentize') | ||
@@ -16,6 +15,9 @@ | ||
}) | ||
var B = prime({inherits: A, a: function(){ | ||
return this.parent('a', 'c') + 'b' | ||
}}) | ||
mixin(B, parentize) | ||
var B = prime({ | ||
mixin: [parentize], | ||
inherits: A, | ||
a: function() { | ||
return this.parent('a', 'c') + 'b' | ||
} | ||
}) | ||
var b = new B() | ||
@@ -40,2 +42,3 @@ var res | ||
var D = prime({ | ||
mixin: [parentize], | ||
inherits: C, | ||
@@ -49,3 +52,2 @@ a: function(){ | ||
}) | ||
mixin(D, parentize) | ||
var d = new D() | ||
@@ -52,0 +54,0 @@ expect(d.a()).to.be('ab') |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
13210
2
24
293
163
1
+ Addedmout@~0.9.0
+ Addedmout@0.9.1(transitive)
+ Addedprime@0.4.2(transitive)
- Removedprime@0.3.2(transitive)
Updatedprime@~0.4.0