Socket
Socket
Sign inDemoInstall

amp-utils

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.0.3

2

package.json
{
"name": "amp-utils",
"version": "1.0.1",
"version": "1.0.3",
"description": "A collection of handy utilities.",

@@ -5,0 +5,0 @@ "main": "src/amp.js",

# amp
A collection of handy utilities.
## Installation

@@ -9,2 +10,3 @@ ```sh

## Usage

@@ -14,5 +16,6 @@ ```js

const slug = amp.string.slug('This string will be slugged.');
amp.string.slug('This string will be slugged.');
```
## Array Utilities

@@ -23,5 +26,5 @@ ### `amp.array.move(array, from, to)`

#### Configuration
`array`: The target array (`Array`)
`from`: The old index of the array item (`Integer`)
`to`: The new index of the array item (`Integer`)
- `array`: The target `Array`
- `from`: The old `Integer` index of the array item
- `to`: The new `Integer` index of the array item

@@ -36,4 +39,3 @@ #### Examples

amp.array.move(breakfast, 2, 0);
// Return: ['bacon', 'eggs', 'toast']
amp.array.move(breakfast, 2, 0); // ['bacon', 'eggs', 'toast']
```

@@ -45,10 +47,10 @@

#### Configuration
`array`: The target array (`Array`)
- `array`: The target `Array`
#### Examples
```js
amp.array.unique(['a', 'a', 'b', 'c', 'c']);
// Return: ['a', 'b', 'c']
amp.array.unique(['a', 'a', 'b', 'c', 'c']); // ['a', 'b', 'c']
```
## HTML Utilities

@@ -59,4 +61,4 @@ ### `amp.html.closest(start, selector)`

#### Configuration
`start`: The starting HTML element (`HTMLElement`)
`selector`: A valid CSS selector for matching parent elements (`String`)
- `start`: The starting `HTMLElement`
- `selector`: A valid CSS selector `String` for matching parent elements

@@ -66,3 +68,2 @@ #### Examples

amp.html.closest(document.getElementById('menu'), '.menu-container');
// Return: HTMLElement or null
```

@@ -74,4 +75,4 @@

#### Configuration
`el`: The HTML element for comparison (`HTMLElement`)
`selector`: A valid CSS selector for matching (`String`)
- `el`: The `HTMLElement` for comparison
- `selector`: A valid CSS selector `String` for matching

@@ -81,5 +82,5 @@ #### Examples

amp.html.matches(document.getElementById('menu'), '.menu');
// Return: Boolean
```
## Object Utilities

@@ -90,5 +91,5 @@ ### `amp.object.byPath(search, path, value)`

#### Configuration
`search`: The object that will be searched (`Object`)
`path`: The path to the target object or value in dot notation (for example, 'parent.child.grandchild') (`String`)
`value`: Set target object to this value instead of getting its value (`Mixed`)
- `search`: The `Object` that will be searched
- `path`: The `String` path to the target object or value in dot notation (for example, 'parent.child.grandchild')
- `value`: Set target object to this value instead of getting its value

@@ -112,10 +113,7 @@ #### Examples

amp.object.byPath(ride, 'type');
// Return: 'Truck'
amp.object.byPath(ride, 'type'); // 'Truck'
amp.object.byPath(ride, 'passengers.driver.name');
// Return: 'Edith'
amp.object.byPath(ride, 'passengers.driver.name'); // 'Edith'
amp.object.byPath(ride, 'passengers.shotgun.name', 'Joe');
// Return: { type: 'Truck', wheels: 4, ... } (passenger name 'Edmund' is now set to 'Joe')
amp.object.byPath(ride, 'passengers.shotgun.name', 'Joe'); // Object ('Edmund' is now 'Joe')
```

@@ -127,7 +125,7 @@

#### Configuration
`obj`: The object that will be cloned
- `obj`: The `Object` that will be cloned
#### Examples
```js
amp.object.clone({
const original = {
a: 'one',

@@ -137,20 +135,19 @@ b: {

},
});
// Return: Object (a deep clone of the original object)
};
const clone = amp.object.clone(original);
```
### `amp.object.equal(a, b)`
Compare two objects for equality. Returns `Boolean`.
Compare two `Objects` for equality. Returns `Boolean`.
#### Configuration
`a`: The first object for comparison
`b`: The second object for comparison
- `a`: The first `Object` for comparison
- `b`: The second `Object` for comparison
#### Examples
```js
amp.object.equal({ a: 'A'}, { a: 'A'});
// Return: true
amp.object.equal({ a: 'A'}, { a: 'A'}); // true
amp.object.equal({ a: 'A' }, { a: 'B' });
// Return: false
amp.object.equal({ a: 'A' }, { a: 'B' }); // false
```

@@ -162,11 +159,9 @@

#### Configuration
`obj`: The object or value in question (`Mixed`)
- `obj`: The `Object` in question
#### Examples
```js
amp.object.is({ a: 'A' });
// Return: true
amp.object.is({ a: 'A' }); // true
amp.object.is('A string!');
// Return: false
amp.object.is('A string!'); // false
```

@@ -178,12 +173,10 @@

#### Configuration
`target`: Properties will be copied into this object (`Object`)
`sources`: One or more objects to merge into the target (`Object`)
- `target`: Properties will be copied into this `Object`
- `sources`: One or more source `Objects` to merge into the target
#### Examples
```js
amp.object.merge({ a: 'A' }, { b: 'B' });
// Return: { a: 'A', b: 'B' }
amp.object.merge({ a: 'A' }, { b: 'B' }); // { a: 'A', b: 'B' }
amp.object.merge({ a: 'A' }, { a: 'B' });
// Return: { a: 'B' }
amp.object.merge({ a: 'A' }, { a: 'B' }); // { a: 'B' }
```

@@ -195,4 +188,4 @@

#### Configuration
`defaultConfig`: Default configuration options (`Object`)
`config`: Configuration options, will overwrite default options (`Object`)
- `defaultConfig`: Default configuration options `Object`
- `config`: Configuration options `Object`, will overwrite default options

@@ -209,12 +202,10 @@ #### Examples

getAnimal({ name: 'Mighty' });
// Return: { name: 'Mighty', type: 'dog' }
getAnimal({ name: 'Mighty' }); // { name: 'Mighty', type: 'dog' }
getAnimal({ name: 'Edith', type: 'cat' });
// Return: { name: 'Edith', type: 'cat' }
getAnimal({ name: 'Edith', type: 'cat' }); // { name: 'Edith', type: 'cat' }
getAnimal({ name: 'T-Bone', type: 'bird', age: 3 })
// Return: { name: 'T-Bone', type: 'bird', age: 3 }
getAnimal({ name: 'T-Bone', type: 'bird', age: 3 }); // { name: 'T-Bone', type: 'bird', age: 3 }
```
## Query String Utilities

@@ -225,4 +216,4 @@ ### `amp.queryString.get(uri, key)`

#### Configuration
`uri`: The URI or query string (`String`)
`key`: The query string parameter name (`String`)
- `uri`: The URI or query `String`
- `key`: The query string parameter name (`String`)

@@ -233,7 +224,4 @@ #### Examples

amp.queryString.get(url, 'name');
// Return: 'Edmund'
amp.queryString.get(url, 'type');
// Return: 'cat'
amp.queryString.get(url, 'name'); // 'Edmund'
amp.queryString.get(url, 'type'); // 'cat'
```

@@ -245,5 +233,5 @@

#### Configuration
`uri`: The URI or query string (`String`)
`key`: The query string parameter name (`String`)
`value`: The new parameter value (`String`)
- `uri`: The URI or query `String`
- `key`: The query string parameter name (`String`)
- `value`: The new parameter value

@@ -254,9 +242,7 @@ #### Examples

amp.queryString.set(url, 'name', 'Edith');
// Return: '?name=Edith&type=cat'
amp.queryString.set(url, 'age', '3');
// Return: '?name=Edmund&type=cat&age=3'
amp.queryString.set(url, 'name', 'Edith'); // '?name=Edith&type=cat'
amp.queryString.set(url, 'age', '3'); // '?name=Edmund&type=cat&age=3'
```
## String Utilities

@@ -267,8 +253,7 @@ ### `amp.string.slug(str)`

#### Configuration
`str`: The string to slugify (`String`)
- `str`: The `String` to slugify
#### Examples
```js
amp.string.slug('Pomp & Circumstance');
// Return: 'pomp-circumstance'
amp.string.slug('Pomp & Circumstance'); // 'pomp-circumstance'
```

@@ -280,8 +265,7 @@

#### Configuration
`str`: The string to transform (`String`)
- `str`: The `String` to transform
#### Examples
```js
amp.string.titleCase('eine kleine nachtmusik');
// Return: 'Eine Kleine Nachtmusik'
amp.string.titleCase('eine kleine nachtmusik'); // 'Eine Kleine Nachtmusik'
```

@@ -293,8 +277,7 @@

#### Configuration
`path`: The path or string that will be trimmed (`String`)
- `path`: The `String` that will be trimmed
#### Examples
```js
amp.string.trimSlashes('/dogs/moby/fetch/');
// Return: 'dogs/moby/fetch'
amp.string.trimSlashes('/dogs/moby/fetch/'); // 'dogs/moby/fetch'
```
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc