New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

lutils

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lutils - npm Package Compare versions

Comparing version 1.2.5 to 2.1.5

26

CHANGELOG.md

@@ -0,1 +1,27 @@

### `2.1.1` May 12th 2017
**Breaking changes**:
- [x] No more seperate npm modules for each function, only `lutils`
- [x] `typeOf.Boolean` etc. are renamed to `isBoolean` and exported individually
- [x] `merge` api simplified to only `merge(subject, ...sources[])`
- [x] `clone` api simplified to only `clone(subject)`
**New features**:
- [x] Full rewrite in Typescript, providing intellisense
- [x] Performance increases:
- `typeOf` performance improved by **~220%**!!!
- `merge` performance improved by **~30%**!
- `clone` performance on par.
- [x] `typeOf` functions can act as type guards in typescript & Flow
- [x] `Merge` provides a constructor for configuration
- [x] `Clone` provides a constructor for configuration
- [x] `Merge` and `Clone` have added warnings:
- When default `depth` is hit
- When invalid parameters are supplied
-----------------------------
### `1.2.5` Jan 10th 2017
- Adding typings
### `1.2.0` August 7th 2016

@@ -2,0 +28,0 @@ - Version bumps

8

index.d.ts

@@ -1,5 +0,3 @@

import merge = require('lutils-merge')
import clone = require('lutils-clone')
import typeOf = require('lutils-typeof')
export { merge, clone, typeOf }
export * from "./merge/merge";
export * from "./clone/clone";
export * from "./typeOf/typeOf";

@@ -1,3 +0,9 @@

exports.typeOf = require('lutils-typeof')
exports.merge = require('lutils-merge')
exports.clone = require('lutils-clone')
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./merge/merge"));
__export(require("./clone/clone"));
__export(require("./typeOf/typeOf"));
//# sourceMappingURL=index.js.map
{
"name": "lutils",
"description": "A few reliable utils.",
"version": "1.2.5",
"author": {
"name": "nfour"
},
"repository": {
"type": "git",
"url": "https://github.com/nfour/lutils"
},
"main": "./index",
"files": [
"index.js",
"index.d.ts"
],
"typings": "index.d.ts",
"dependencies": {
"lutils-typeof": "~0.2.4",
"lutils-merge": "~0.2.6",
"lutils-clone": "~0.1.8"
},
"keywords": [
"merge",
"clone",
"type",
"recursive",
"assign",
"deep",
"immutable",
"mutate",
"typeof"
]
}
"name": "lutils",
"description": "A few reliable utils.",
"version": "2.1.5",
"author": {
"name": "nfour"
},
"repository": {
"type": "git",
"url": "https://github.com/nfour/lutils"
},
"main": "./index",
"files": [
"index.js",
"index.d.ts"
],
"typings": "index.d.ts",
"scripts": {
"build": "./scripts/build",
"test": "jest src/**/*.spec.ts",
"coverage": "jest src/**/*.spec.ts --coverage",
"lint": "tslint src/**/*.ts",
"lint:types": "tslint src/**/*.ts --type-check --project src",
"test:dist": "jest -c '{}' dist/**/*.spec.js",
"release": "cd dist && npm publish"
},
"keywords": [
"merge",
"extend",
"clone",
"type",
"recursive",
"assign",
"deep",
"immutable",
"mutate",
"typeof",
"type",
"guard"
],
"devDependencies": {
"@types/jest": "^19.2.3",
"jest": "^20.0.1",
"lutils-clone": "0",
"lutils-merge": "0",
"lutils-typeof": "0",
"ts-jest": "^20.0.3",
"tslint": "^5.2.0",
"tslint-config-standard": "^5.0.2",
"tslint-eslint-rules": "^4.0.0",
"typescript": "^2.3.2"
}
}

@@ -1,60 +0,150 @@

# Lutils `lutils`
A few reliable utils. Browser-friendly.
# `lutils`
```js
_TypesSript documented utilities_
- [merge](#merge) for deep merging of objects
- [clone](#clone) for deep cloning of objects & arrays
- [typeOf](#typeof) for consistant type checking
```ts
import { typeOf, merge, clone } from 'lutils'
let { typeOf, merge, clone } = require('lutils')
```
typeOf = require('lutils-typeof')
merge = require('lutils-merge')
clone = require('lutils-clone')
- See: [**CHANGELOG.md**](./CHANGELOG.md)
--------------------------------
## merge
Merge objects together, traversing objects & arrays recursively
- `merge(subject, ...sources[])` => `subject`
- Default **depth**: `10`
```ts
import { merge } from 'lutils'
merge({ aa: { cc: 1 }, }, { aa: { cc: 2 } }, { bb: 3 })
=== { aa: { cc: 2 }, bb: 3 }
```
## API
### `merge`
Recursively merge objects.
See [lutils-merge](https://github.com/nfour/lutils-merge)
--------------------------------
### `clone`
Recursively clone objects.
See [lutils-clone](https://github.com/nfour/lutils-clone)
Construct & configure your own `Merge` instance
### `typeOf`
Type check for primitives reliably.
See [lutils-typeof](https://github.com/nfour/lutils-typeof)
- `new Merge(config).merge`
- See: [**config**](./src/merge/merge.ts#L31)
```ts
import { Merge } from 'lutils'
## 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.
const merge = new Merge({ depth: Infinity }).merge
## Example
Below, a config file, `development.js`, can be composed of multiple files.
merge(megaDeep, ultraDeep)
```
```js
import { merge, clone } from 'lutils'
--------------------------------
export default merge(
clone( require('./default') ),
{
database: "development",
server: { port: 1337 }
}
clone( require('./local') )
)
/*
{
name: "My App",
database: "development",
server: {
host: "0.0.0.0",
port: 1337,
},
ssh: { privateKey: "~/.ssh/myLocalPrivateKey.pem" }
}
*/
Merge, but with two common behaviours, whitelisting and blacklisting
- `merge.white(subject, ...sources[])` => `subject`
- `merge.black(subject, ...sources[])` => `subject`
```ts
import { merge } from 'lutils'
merge.white({ aa: { bb: 1, cc: 1 } }, { aa: { xx: 2, cc: 2 } })
=== { aa: { bb: 1, cc: 2 } }
merge.black({ aa: { bb: 1, cc: 1 } }, { aa: { xx: 2, cc: 2 } })
=== { aa: { bb: 1, cc: 1, xx: 2 } }
```
The above config would first inherit the default config, overwriting `database` and `server.port`.
`./local`, a git untracked file, would then overwrite aspects specific to the developers machine, such as the `ssh.privateKey`.
Because each config is cloned when required, the file `./default` will not be mutated, even though it is the base.
--------------------------------
## clone
Clones objects & arrays recursively
- `clone(subject)` => `clonedSubject`
- Default **depth**: `10`
```ts
import { clone } from 'lutils'
const cloned = clone({ my: { little: { foo: 'bar' } } })
```
- `new Clone(config).clone`
- See: [**config**](./src/clone/clone.ts#L12)
```ts
import { Clone } from 'lutils'
const clone = new Clone({ depth: Infinity }).clone
const cloned = clone({ my: { little: { foo: 'bar' } } })
```
--------------------------------
## typeOf
Gets the type of a value as a lowercase string. \
Like the built-in `typeof`, but works for all primitives.
- `typeOf(value)` => `string`
```ts
import { typeOf } from 'lutils'
typeOf(null)
=== 'null'
typeOf(NaN)
=== 'nan'
typeOf([])
=== 'array'
```
--------------------------------
Specific type checkers are also exported and attached to `typeOf` \
These checkers also supply typescript with type information, meaning
they can act a **type guards**.
- `isBoolean(value)` => `boolean`
- `is<type>(value)` => `boolean`
- See: [**ITypeOf**](./src/typeOf/typeOf.ts#L3)
```ts
import { typeOf, isBoolean, isString } from 'lutils'
typeOf.isNull(null)
=== true
isString(undefined)
=== false
typeOf.isString('')
=== true
isBoolean(false)
=== true
// Type guarding...
function blah (aa: number|string) {
if (isString(aa)) {
// string
aa += '!!!!'
} else {
// number
++aa
}
return aa
}
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc