Comparing version 0.2.11 to 1.0.0
@@ -1,5 +0,23 @@ | ||
## 0.2.10 | ||
### `1.0.0` | ||
- Rebuilt lutils, splitting each function off | ||
- `lutils-typeof` | ||
- `lutils-merge` | ||
- `lutils-clone` | ||
- `lutils` simply exposes all three | ||
- Converted to ES5 from CoffeeScript | ||
- Refactored API to be more flexible and consitant with similar utilities, such as underscore | ||
- `merge`, `merge.whtie`, `merge.black` | ||
- `merge(obj1, obj2, obj3, ...)` | ||
- `merge(obj1, obj2, obj3, ..., function() {})` | ||
- `merge([obj1, obj2, obj3, ...], options)` | ||
- `merge` now supports test functions for custom merging | ||
- `clone` | ||
- `clone(obj, options)` | ||
- `typeOf` reamins the same | ||
- See each modules readme for precise api | ||
### `0.2.10` | ||
- Fixed `depth` being compared one unit too low. | ||
## 0.2.7 | ||
- Fixed an `{}.__proto__` mutation bug. `clone` is now significantly faster. | ||
### `0.2.7` | ||
- Fixed an `{}.__proto__` mutation bug. `clone` is now significantly faster. |
14
index.js
@@ -1,9 +0,5 @@ | ||
// Generated by CoffeeScript 1.9.2 | ||
(function() { | ||
module.exports = { | ||
clone: require('./clone'), | ||
merge: require('./merge'), | ||
typeOf: require('./typeOf') | ||
}; | ||
}).call(this); | ||
module.exports = { | ||
typeOf : require('lutils-typeof'), | ||
merge : require('lutils-merge'), | ||
clone : require('lutils-clone'), | ||
} |
{ | ||
"name" : "lutils" | ||
, "description" : "A small set of browser-friendly utilities" | ||
, "version" : "0.2.11" | ||
, "author" : { "name": "nfour" } | ||
"name" : "lutils", | ||
"description" : "A few reliable utils.", | ||
"version" : "1.0.0", | ||
"author" : { "name": "nfour" }, | ||
"repository" : { | ||
"type" : "git", | ||
"url" : "https://github.com/nfour/lutils" | ||
}, | ||
, "devDependencies": { | ||
"nodeunit": "^0.9.0" | ||
} | ||
, "scripts": { | ||
"build" : "cake build" | ||
, "test" : "npm run build && nodeunit ./test" | ||
, "publicate" : "npm run build && npm publish" | ||
} | ||
"main": "./index", | ||
, "main": "./index" | ||
"dependencies": { | ||
"lutils-typeof": "latest", | ||
"lutils-merge" : "latest", | ||
"lutils-clone" : "latest" | ||
}, | ||
"devDependencies": { | ||
"nodeunit" : "^0.9.0" | ||
} | ||
} |
117
readme.md
@@ -1,104 +0,29 @@ | ||
# LUtils | ||
A few very robust utilities. | ||
# Lutils `lutils` | ||
A few reliable utils. Browser-friendly. | ||
- **merge** Merges two objects together deeply | ||
- **merge.white** Merge two objects together, but only properties that exist | ||
- **merge.black** Merge two objects together, but only properties that do not exist | ||
- **typeOf** Consistantly gets the type of a value as a string | ||
- **typeOf[type]** Shortcut function which returns a bool | ||
- **clone** *Reliably* deep clones an object or array, recursively | ||
```js | ||
import { typeOf, merge, clone } from 'lutils' | ||
const { typeOf, merge, clone } = require('lutils') | ||
Include all or be selective. | ||
```coffee | ||
{ clone, merge, typeOf } = require 'lutils' | ||
typeOf = require 'lutils/typeOf' | ||
const typeOf = require('lutils-typeof') | ||
const merge = require('lutils-merge') | ||
const clone = require('lutils-clone') | ||
``` | ||
## API | ||
### `merge` | ||
Recursively merge objects. | ||
See [lutils-merge](https://github.com/nfour/lutils-merge) | ||
#### clone( value, ?depth = 8?, ?types = [ 'object', 'array' ]? ) | ||
Clones an object or array as deep as depth. | ||
### `clone` | ||
Recursively clone objects. | ||
See [lutils-clone](https://github.com/nfour/lutils-clone) | ||
Values which will still remain as references: | ||
- Functions | ||
- Object's `__proto__` (such as `class` instances) | ||
- Any property after `depth` is reached | ||
### `typeOf` | ||
Type check for primitives reliably. | ||
See [lutils-typeof](https://github.com/nfour/lutils-typeof) | ||
To clone a function you should explicitly: | ||
```coffee | ||
fn = oldFn.bind() | ||
# or | ||
fn = -> oldFn.apply this, arguments | ||
merge fn, oldFn # Merge in any own properties of the function | ||
``` | ||
#### merge( object1, object2, ?depth = 8?, ?types = [ 'object' ]? ) | ||
Merge the second object into the first recursively until depth is reached for each property, replacing object1's values with those in object2. | ||
`types` is an array of types that, when matched on a value, will be iterated over and merged in. This means you can merge a function's properties or an array's properties recursively, thus preserving pointer references to the first object's instance. | ||
```coffee | ||
fn1 = -> return 'fn1' + fn1.prop.b | ||
fn1.prop = { a: 1 } | ||
fn2 = -> return 'fn2' + fn2.prop.a | ||
fn2.prop = { b: 2 } | ||
obj1 = { a: { b: { fn: fn1 } } } | ||
obj2 = { a: { b: { fn: fn2 } } } | ||
merge obj1, obj2 | ||
# >> { a: { b: { fn: [Function] } } } | ||
obj1.a.b.fn.prop | ||
# >> { a: 1, b: 2 } | ||
obj1.a.b.fn() | ||
# 'fn1!2' | ||
``` | ||
#### merge.white( object1, object2, depth = 8, iterators = [ 'object' ] ) | ||
Whitelisted merge. | ||
Merges properties into object1 from object only if the property exists in object1 | ||
#### merge.black( object1, object2, depth = 8, iterators = [ 'object' ] ) | ||
Blacklisted merge. | ||
Merges properties into object1 from object only if the property *doesnt* exist in object1 | ||
#### typeOf( value ) | ||
Returns the primitive type of a value as a lowercase string, very reliable. | ||
To be used in combination with `instanceof` and `object.constructor.name` when necessary. | ||
```coffee | ||
typeOf 'a string' # >> 'object' | ||
typeOf { an: { object: null } } # >> 'object' | ||
typeOf null # >> 'null' | ||
typeOf 0 # >> 'number' | ||
``` | ||
Also has helper properties which return a boolean. | ||
#### typeOf[type]( value ) | ||
```coffee | ||
typeOf.RegExp 'not regex' # false | ||
typeOf.Object null # false | ||
typeOf.Array [] # true | ||
### | ||
Avaliable properties (Also avaliable in lowercase): | ||
typeOf.Undefined | ||
typeOf.Boolean | ||
typeOf.String | ||
typeOf.Function | ||
typeOf.Array | ||
typeOf.Object | ||
typeOf.Null | ||
typeOf.Number | ||
typeOf.Date | ||
typeOf.RegExp | ||
typeOf.NaN | ||
### | ||
``` | ||
## Why? | ||
Javascript doesn't need a lot on top of it now that we have ES6/ES7. | ||
Some things are still too hard to do, which is exactly what these utils try to fix. |
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
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
0
3796
3
6
5
30
2
+ Addedlutils-clone@latest
+ Addedlutils-merge@latest
+ Addedlutils-typeof@latest
+ Addedlutils-clone@0.1.8(transitive)
+ Addedlutils-merge@0.2.6(transitive)
+ Addedlutils-typeof@0.2.5(transitive)