@springernature/global-javascript
Advanced tools
Comparing version 2.4.0 to 3.0.0
@@ -7,17 +7,22 @@ import {getDataOptions} from '../../../src/helpers'; | ||
OPTION_2: 'data-mycomponent-option2', | ||
OPTION_3: 'data-mycomponent-option3' | ||
OPTION_3: 'data-mycomponent-option3', | ||
OPTION_4: 'data-mycomponent-option4', | ||
OPTION_5: 'data-mycomponent-option5' | ||
}; | ||
const element = {}; | ||
beforeEach(() => { | ||
document.body.innerHTML = ` | ||
<div data-mycomponent-option1="foo" data-mycomponent-option2="bar" data-mycomponent-option3="baz" data-notmycomponent="test">My Component</div> | ||
<div data-mycomponent-option1="foo" data-mycomponent-option2="bar" data-mycomponent-option3="baz" data-mycomponent-option4="true" data-mycomponent-option5="false" data-notmycomponent="test">My Component</div> | ||
`; | ||
element.COMPONENT = document.querySelector('div'); | ||
}); | ||
test('Should return an Object with the values for each key as the values of the data-attributes', () => { | ||
const component = document.querySelector('div'); | ||
const options = getDataOptions(component, DataOptions); | ||
const options = getDataOptions(element.COMPONENT, DataOptions); | ||
expect(options).toMatchObject({OPTION_1: 'foo', OPTION_2: 'bar', OPTION_3: 'baz'}); | ||
expect(options).toMatchObject({OPTION_1: 'foo', OPTION_2: 'bar', OPTION_3: 'baz', OPTION_4: true, OPTION_5: false}); | ||
}); | ||
}); |
# History | ||
## 3.0.0 (2020-11-13) | ||
* BREAKING: Convert "true" and "false" attributes to boolean | ||
## 2.4.0 (2020-08-24) | ||
@@ -4,0 +7,0 @@ * FEATURE: setCookie util |
{ | ||
"name": "@springernature/global-javascript", | ||
"version": "2.4.0", | ||
"version": "3.0.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Globally shared Javascript helpers", |
@@ -16,3 +16,5 @@ /** | ||
if (attributeValue) { | ||
dataOptions[key] = attributeValue; | ||
// 'true' and 'false' attribute values need to be converted to a boolean | ||
// Checking equality against 'true' will return a boolean of true or false. e.g. 'false' === 'true' returns false | ||
dataOptions[key] = (attributeValue === 'true' || attributeValue === 'false') ? attributeValue === 'true' : attributeValue; | ||
} | ||
@@ -19,0 +21,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24649
512