@ldapjs/attribute
Advanced tools
Comparing version 1.0.0-rc.4 to 1.0.0-rc.5
31
index.js
@@ -31,3 +31,3 @@ 'use strict' | ||
} | ||
this.#type = options.type || '' | ||
this.type = options.type || '' | ||
@@ -266,2 +266,31 @@ const values = options.values || options.vals || [] | ||
/** | ||
* Given an object of attribute types mapping to attribute values, construct | ||
* a set of Attributes. | ||
* | ||
* @param {object} obj Each key is an attribute type, and each value is an | ||
* attribute value or set of values. | ||
* | ||
* @returns {Attribute[]} | ||
* | ||
* @throws If an attribute cannot be constructed correctly. | ||
*/ | ||
static fromObject (obj) { | ||
const attributes = [] | ||
for (const [key, value] of Object.entries(obj)) { | ||
if (Array.isArray(value) === true) { | ||
attributes.push(new Attribute({ | ||
type: key, | ||
values: value | ||
})) | ||
} else { | ||
attributes.push(new Attribute({ | ||
type: key, | ||
values: [value] | ||
})) | ||
} | ||
} | ||
return attributes | ||
} | ||
/** | ||
* Determine if an object represents an {@link Attribute}. | ||
@@ -268,0 +297,0 @@ * |
@@ -304,2 +304,17 @@ 'use strict' | ||
tap.test('#fromObject', t => { | ||
t.test('handles basic object', async t => { | ||
const attrs = Attribute.fromObject({ | ||
foo: ['foo'], | ||
bar: 'bar', | ||
'baz;binary': Buffer.from([0x00]) | ||
}) | ||
for (const attr of attrs) { | ||
t.equal(Object.prototype.toString.call(attr), '[object LdapAttribute]') | ||
} | ||
}) | ||
t.end() | ||
}) | ||
tap.test('#isAttribute', t => { | ||
@@ -306,0 +321,0 @@ t.test('rejects non-object', async t => { |
@@ -10,3 +10,3 @@ { | ||
"description": "API for handling LDAP entry attributes", | ||
"version": "1.0.0-rc.4", | ||
"version": "1.0.0-rc.5", | ||
"license": "MIT", | ||
@@ -13,0 +13,0 @@ "repository": { |
21955
656