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

adam

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adam

Functions to create, process and test objects

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
decreased by-11.11%
Maintainers
1
Weekly downloads
 
Created
Source

adam

Functions to create, process and test objects.

NPM version Build Status Built with Grunt

Installation

Node

npm install adam

Component

component install gamtiq/adam

Jam

jam install adam

Bower

bower install adam

SPM

spm install adam

AMD, <script>

Use dist/adam.js or dist/adam.min.js (minified version).

Usage

Node, Component, SPM

var adam = require("adam");

Jam

require(["adam"], function(adam) {
    ...
});

AMD

define(["path/to/dist/adam.js"], function(adam) {
    ...
});

Bower, <script>


<!-- Use bower_components/adam/dist/adam.js if the library was installed by Bower -->

<script type="text/javascript" src="path/to/dist/adam.js"></script>
<script type="text/javascript">
    // adam is available via adam field of window object
    
    ...
</script>

Examples

var obj = {a: 1, b: 2, c: 3, d: 4, e: 5};

adam.getClass([8]);   // "Array"
adam.getType(null);   // "null"
adam.isKindOf(17, "integer");   // true
adam.isKindOf(NaN, "!number");   // true

adam.checkField(obj, "c", ["positive", "odd"]);   // true
adam.checkField(obj, "b", ["real", /^7/], {filterConnect: "or"});   // false

adam.getFreeField({a5: 5, a2: 2, a7: 7, a3: 3}, {prefix: "a", startNum: 2});   // "a4"

adam.getSize(obj);   // 5
adam.getSize(obj, {filter: "even"});   // 2
adam.isSizeMore(obj, 5);   // false
adam.isEmpty({});   // true

adam.getFields(obj);   // ["a", "b", "c", "d", "e"]
adam.getFields(obj, {filter: function(value) {return value > 3;}});   // ["d", "e"]
adam.getFields(adam, {filter: {field: /^is/}});   // ["isEmpty", "isKindOf", "isSizeMore"]

adam.getValues(obj);   // [1, 2, 3, 4, 5]
adam.getValues(obj, {filter: {field: /a|c/}});   // [1, 3]
adam.getValueKey(obj, 3);   // "c"

adam.fromArray([{id: "a", value: 11}, {id: "b", value: 7}, {id: "c", value: 10}], "id");   // {a: {id: "a", value: 11}, b: {id: "b", value: 7}, c: {id: "c", value: 10}}

adam.split(obj, ["a", "d"]);   // [{a: 1, d: 4}, {b: 2, c: 3, e: 5}]
adam.split(obj, null, {filter: "odd"});   // [{a: 1, c: 3, e: 5}, {b: 2, d: 4}]
adam.split(obj, null, {filter: ["even", /3/], filterConnect: "or"});   // [{b: 2, c: 3, d: 4}, {a: 1, e: 5}]

See test/adam.js for additional examples.

API

checkField(obj: Object, field: String, filter: Any, [settings: Object]): Boolean

Check whether the field of given object corresponds to specified condition(s) or filter(s).

fromArray(list: Array, [keyField: Function | String], [settings: Object]): Object

Create object (map) from list of objects.

getClass(value: Any): String

Return class of given value (namely value of internal property [[Class]]).

getFields(obj: Object, [settings: Object]): Array

Return list of all or filtered fields of specified object.

getFreeField(obj: Object, [settings: Object]): String

Return name of first free (absent) field of specified object, that conforms to the following pattern: <prefix><number>

getSize(obj: Object, [settings: Object]): Integer

Return number of all or filtered fields of specified object.

getType(value: Any): String

Return type of given value.

getValueKey(obj: Object, value, [all: Boolean]): Array | String | null

Return the name of field (or list of names) having the specified value in the given object.

getValues(obj: Object, [settings: Object]): Array

Return list of all or filtered field values of specified object.

isEmpty(value: Any): Boolean

Check whether given value is an empty value i.e. null, undefined, empty object, empty array or empty string.

isKindOf(value: Any, kind: String): Boolean

Check whether given value has (or does not have) specified kind (type or class).

isSizeMore(obj: Object, qty: Number, [settings: Object]): Boolean

Check whether number of all or filtered fields of specified object is more than the given value.

split(obj: Object, firstObjFields: Array | Object | null, [settings: Object]): Array

Divide given object into 2 parts: the first part includes specified fields, the second part includes all other fields.

See doc folder for details.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

License

Copyright (c) 2014 Denis Sikuler
Licensed under the MIT license.

Keywords

FAQs

Package last updated on 12 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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