Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

a-toolbox

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

a-toolbox - npm Package Compare versions

Comparing version 1.2.2 to 1.2.3

198

_README.md

@@ -70,27 +70,3 @@ # a-toolbox

#### object merge
```js
var _merge = {a: 1, b: 2};
console.log('to merge', _merge);
tools.object.merge(_merge, {a: 4, c: { d: 8, e: 9}});
console.log('merged', _merge);
//>to merge { a: 1, b: 2 }
//>merged { a: 4, b: 2, c: { d: 8, e: 9 } }
```
#### object clone
```js
var _clone = {a: {7: 6, k: 'a'}, b: 2};
console.log('clone', tools.object.clone(_clone));
//>clone {a: {7: 6, k: 'a'}, b: 2}
```
#### random

@@ -113,174 +89,2 @@

```
#### string template
Replace marker in template string with provided object data
```js
var data = {
name: 'Alice',
year: 2014,
color: 'yellow'
};
var str = '<div>My name is {name} I was born in {year} and my favourite color is {color}</div>{nothing}';
console.log('template:', tools.string.template(str, data));
//> template: <div>My name is Alice I was born in 2014 and my favourite color is yellow</div>{nothing}
```
#### string trim
Trim string using custom chars
```js
var str = '({cut these silly brackets please)}';
console.log('trim:', tools.string.trim(str, ['{','}','(',')']));
//> trim: cut these silly brackets please
```
#### string replaceAll
```js
console.log(tools.string.replaceAll("no replace all in js native code that replace all the replace", ' ', '_'));
//> no_replace_all_in_js_native_code_that_replace_all_the_replace
```
#### array remove
```js
var _array = ['very', 'annoying', 'remove', 'elements', 'in', 'js', 'arrays'];
tools.array.remove(_array, 'very');
tools.array.remove(_array, 'annoying');
console.log(_array);
//>[ 'remove', 'elements', 'in', 'js', 'arrays' ]
```
#### array removeAt
```js
tools.array.removeAt(_array, 4);
console.log(_array);
//>[ 'remove', 'elements', 'in', 'arrays' ]
```
#### array first and last
```js
console.log('last element is', tools.array.last(_array));
//>last element is js
console.log('first element is', tools.array.first(_array));
//>first element is remove
```
#### array contains
```js
console.log('contains js?', tools.array.contains(_array, 'js'));
//>contains js? true
console.log('contains ruby?', tools.array.contains(_array, 'ruby'));
//>contains ruby? false
```
#### array insert
```js
tools.array.insert(_array, 0, 'something');
console.log('inserted something', _array);
//>inserted something [ 'something', 'remove', 'elements', 'in', 'js' ]
```
#### array get random element
```js
console.log('get random element:', tools.array.randomElement(_array));
//>get random element element: in
```
#### array concat
```js
console.log('concat more arrays', tools.array.concat(_array, [0,1,2,3], ['a','b','c']));
//>concat more arrays [ 'something',
//> 'remove',
//> 'elements',
//> 'in',
//> 'js',
//> 0,
//> 1,
//> 2,
//> 3,
//> 'a',
//> 'b',
//> 'c' ]
```
#### array empty
When you need to keep references
```js
tools.array.empty(_array);
console.log('empty it', _array);
//>empty it []
```
---
## License
The MIT License (MIT)
Copyright (c) 2015-2017, [braces lab](https://braceslab.com)
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.
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.
```

246

doc/API.md

@@ -1,49 +0,1 @@

### fs
#### fs.exists(path)
- _path_ \<string\> file path
- _return:_ Promise.\<boolean\> true if file exists - and it's a file
replace deprecated fs.exists
_Example_
````js
tools.fs.exists('/tmp/file')
// > true
````
#### fs.touch(path)
- _path_ \<string\> file path
- _return:_ Promise.\<void\>
create an empty file if not exists
_Example_
````js
tools.fs.touch('/tmp/touch-me')
````
#### fs.unlink(path, [safe=true])
- _path_ \<string\> file path
- _[safe=true]_ \<boolean\> if safe do not throw exception
- _return:_ Promise.\<void\>
delete file, optionally in safe mode
_Example_
````js
tools.fs.unlink('/tmp/file')
````
---
### array

@@ -201,2 +153,51 @@

### fs
#### fs.exists(path)
- _path_ \<string\> file path
- _return:_ Promise.\<boolean\> true if file exists - and it's a file
replace deprecated fs.exists
_Example_
````js
tools.fs.exists('/tmp/file')
// > true
````
#### fs.touch(path, [mode=0o666])
- _path_ \<string\> file path
- _[mode=0o666]_ \<number\>
- _return:_ Promise.\<void\>
create an empty file if not exists
_Example_
````js
tools.fs.touch('/tmp/touch-me')
````
#### fs.unlink(path, [safe=true])
- _path_ \<string\> file path
- _[safe=true]_ \<boolean\> if safe do not throw exception
- _return:_ Promise.\<void\>
delete file, optionally in safe mode
_Example_
````js
tools.fs.unlink('/tmp/file')
````
---
### hash

@@ -221,2 +222,151 @@

### object
#### object.merge(obj1, obj2)
- _obj1_ \<Object\>
- _obj2_ \<Object\>
merge obj2 into obj1
_Example_
````js
let a = {a:1,b:'ciao'}
tools.object.merge(a, {a:4,c:{d:8,e:9}})
// > a = { a: 4, b: 'ciao', c: { d: 8, e: 9 } }
````
#### object.clone(obj)
- _obj_ \<Object|Array\> The array or the object to clone
- _return:_ Object|Array
Clone an array or an object in input
_Example_
````js
tools.object.clone({a: 1, b: 'ciao'})
// > {a: 1, b: 'ciao'}
````
#### object.getKeys(obj)
- _obj_ \<Object\>
- _return:_ Array
#### object.inherits()
#### object.empty()
empty object - need to keep references
_Example_
````js
let a = {a:0,b:1,c:2,d:[],e:{f:-1}}
tools.object.empty(a)
// > a = {}
````
#### _f.flat(obj)
- _obj_ \<Object\>
- _return:_ Object
flat keys in object
_Example_
````js
tools.object.flat({ a: { a1: 1, a2: 2 }, b: 3 })
// > { 'a.a1': 1, 'a.a2': 2, 'b': 3 }
````
#### object.flat(obj)
- _obj_ \<Object\>
- _return:_ Object
flat keys in object
_Example_
````js
tools.object.flat({ a: { a1: 1, a2: 2 }, b: 3 })
// > { 'a.a1': 1, 'a.a2': 2, 'b': 3 }
````
#### _f.raise(obj)
- _obj_ \<Object\>
- _return:_ Object
restore flat object
_Example_
````js
tools.object.raise({ 'a.a1': 1, 'a.a2': 2, 'b': 3 })
// > { a: { a1: 1, a2: 2 }, b: 3 }
````
#### object.raise(obj)
- _obj_ \<Object\>
- _return:_ Object
restore flat object
_Example_
````js
tools.object.raise({ 'a.a1': 1, 'a.a2': 2, 'b': 3 })
// > { a: { a1: 1, a2: 2 }, b: 3 }
````
#### object.getByFlatKey(obj, fkey)
- _obj_ \<Object\>
- _fkey_ \<string\>
- _return:_ Object
get value in object using a flat key
_Example_
````js
tools.object.getByFlatKey({ a: { b: {c: 1} } }, 'a.b.c')
// > 1
````
#### object.setByFlatKey(obj, fkey, val)
- _obj_ \<Object\>
- _fkey_ \<string\>
- _val_ \<*\>
set value in object using a flat key
_Example_
````js
let a = {}
tools.object.setByFlatKey(a, 'a.b.c', 1)
// > a = { a: { b: {c: 1} } }
````
---
### util

@@ -223,0 +373,0 @@

@@ -41,2 +41,3 @@ const nativeFs = require('fs')

* @param {string} path (filePath) file path
* @param {number} [mode=0o666]
* @return {Promise.<void>}

@@ -53,5 +54,5 @@ * @test.case '/tmp/touch-me'

*/
fs.touch = function (path) {
fs.touch = function (path, mode = 0o666) {
return new Promise(function (resolve, reject) {
nativeFs.open(path, 'a', (err, fd) => {
nativeFs.open(path, 'a', mode, (err, fd) => {
if (err) {

@@ -58,0 +59,0 @@ reject(err)

@@ -42,2 +42,5 @@ /**

* @return {Object|Array}
* @test.case {a: 1, b: 'ciao'} > {a: 1, b: 'ciao'}
* @test.case {a: 4, c: { d: 8, e: 9}} > {a: 4, c: { d: 8, e: 9}}
* @test.case {a: 4, b: 'ciao', c: { d: 8, e: 9 }} > {a: 4, b: 'ciao', c: { d: 8, e: 9 }}
*/

@@ -44,0 +47,0 @@ clone: function (obj) {

{
"name": "a-toolbox",
"version": "1.2.2",
"version": "1.2.3",
"description": "javascript lightweight basic tools, isomorphic",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -65,59 +65,15 @@ # a-toolbox

- [hash](#hash)
- [object](#object)
- [util](#util)
- [object](#object)
- [random](#random)
todo
- [string](#string)
todo
- [sys](#sys)
todo
- [task](#task)
todo
- [time](#time)
todo
### fs
note: not available on browser
#### fs.exists(path)
- _path_ \<string\> file path
- _return:_ Promise.\<boolean\> true if file exists - and it's a file
replace deprecated fs.exists
_Example_
````js
tools.fs.exists('/tmp/file')
// > true
````
#### fs.touch(path)
- _path_ \<string\> file path
- _return:_ Promise.\<void\>
create an empty file if not exists
_Example_
````js
tools.fs.touch('/tmp/touch-me')
````
#### fs.unlink(path, [safe=true])
- _path_ \<string\> file path
- _[safe=true]_ \<boolean\> if safe do not throw exception
- _return:_ Promise.\<void\>
delete file, optionally in safe mode
_Example_
````js
tools.fs.unlink('/tmp/file')
````
---
### array

@@ -275,2 +231,51 @@

### fs
#### fs.exists(path)
- _path_ \<string\> file path
- _return:_ Promise.\<boolean\> true if file exists - and it's a file
replace deprecated fs.exists
_Example_
````js
tools.fs.exists('/tmp/file')
// > true
````
#### fs.touch(path, [mode=0o666])
- _path_ \<string\> file path
- _[mode=0o666]_ \<number\>
- _return:_ Promise.\<void\>
create an empty file if not exists
_Example_
````js
tools.fs.touch('/tmp/touch-me')
````
#### fs.unlink(path, [safe=true])
- _path_ \<string\> file path
- _[safe=true]_ \<boolean\> if safe do not throw exception
- _return:_ Promise.\<void\>
delete file, optionally in safe mode
_Example_
````js
tools.fs.unlink('/tmp/file')
````
---
### hash

@@ -295,2 +300,151 @@

### object
#### object.merge(obj1, obj2)
- _obj1_ \<Object\>
- _obj2_ \<Object\>
merge obj2 into obj1
_Example_
````js
let a = {a:1,b:'ciao'}
tools.object.merge(a, {a:4,c:{d:8,e:9}})
// > a = { a: 4, b: 'ciao', c: { d: 8, e: 9 } }
````
#### object.clone(obj)
- _obj_ \<Object|Array\> The array or the object to clone
- _return:_ Object|Array
Clone an array or an object in input
_Example_
````js
tools.object.clone({a: 1, b: 'ciao'})
// > {a: 1, b: 'ciao'}
````
#### object.getKeys(obj)
- _obj_ \<Object\>
- _return:_ Array
#### object.inherits()
#### object.empty()
empty object - need to keep references
_Example_
````js
let a = {a:0,b:1,c:2,d:[],e:{f:-1}}
tools.object.empty(a)
// > a = {}
````
#### _f.flat(obj)
- _obj_ \<Object\>
- _return:_ Object
flat keys in object
_Example_
````js
tools.object.flat({ a: { a1: 1, a2: 2 }, b: 3 })
// > { 'a.a1': 1, 'a.a2': 2, 'b': 3 }
````
#### object.flat(obj)
- _obj_ \<Object\>
- _return:_ Object
flat keys in object
_Example_
````js
tools.object.flat({ a: { a1: 1, a2: 2 }, b: 3 })
// > { 'a.a1': 1, 'a.a2': 2, 'b': 3 }
````
#### _f.raise(obj)
- _obj_ \<Object\>
- _return:_ Object
restore flat object
_Example_
````js
tools.object.raise({ 'a.a1': 1, 'a.a2': 2, 'b': 3 })
// > { a: { a1: 1, a2: 2 }, b: 3 }
````
#### object.raise(obj)
- _obj_ \<Object\>
- _return:_ Object
restore flat object
_Example_
````js
tools.object.raise({ 'a.a1': 1, 'a.a2': 2, 'b': 3 })
// > { a: { a1: 1, a2: 2 }, b: 3 }
````
#### object.getByFlatKey(obj, fkey)
- _obj_ \<Object\>
- _fkey_ \<string\>
- _return:_ Object
get value in object using a flat key
_Example_
````js
tools.object.getByFlatKey({ a: { b: {c: 1} } }, 'a.b.c')
// > 1
````
#### object.setByFlatKey(obj, fkey, val)
- _obj_ \<Object\>
- _fkey_ \<string\>
- _val_ \<*\>
set value in object using a flat key
_Example_
````js
let a = {}
tools.object.setByFlatKey(a, 'a.b.c', 1)
// > a = { a: { b: {c: 1} } }
````
---
### util

@@ -311,2 +465,3 @@

---

@@ -313,0 +468,0 @@

Sorry, the diff of this file is not supported yet

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