Skip to content

Commit eb611ea

Browse files
committed
[FIX] Added a new API
1 parent 71cd843 commit eb611ea

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,19 @@ Then require it in your module ...
2929

3030

3131
```javascript
32-
var getClassNames = require('dynamic-class-list').getClassNames;
32+
var getClassNames = require('dynamic-class-list').getClassNames; // deprecated
33+
var classList = require('dynamic-class-list').classList;
3334
```
3435

3536
## OR using ES6 imports
3637

3738

3839
```javascript
39-
import { getClassNames } from 'dynamic-class-list';
40+
import { getClassNames, classList } from 'dynamic-class-list';
4041
```
4142

43+
Note that `getClassNames` is deprecated and will be removed in next major release. You should use `classList` moving forward.
44+
4245
## API
4346

4447
### Arguments as strings
@@ -47,6 +50,8 @@ import { getClassNames } from 'dynamic-class-list';
4750

4851
// As Arguments
4952
getClassNames('class1', 'class2');
53+
// OR
54+
classList('class1', 'class2');
5055

5156
// Output : "class1 class2"
5257
```
@@ -57,11 +62,11 @@ getClassNames('class1', 'class2');
5762
```javascript
5863

5964
// As an Array
60-
getClassNames(['class1', 'class2']);
65+
classList(['class1', 'class2']);
6166

6267
// Output : "class1 class2"
6368

64-
getClassNames([null, undefined, 3, 'class1', 'class2']);
69+
classList([null, undefined, 3, 'class1', 'class2']);
6570

6671
// Output : "3 class1 class2"
6772
```
@@ -73,11 +78,11 @@ getClassNames([null, undefined, 3, 'class1', 'class2']);
7378
```javascript
7479

7580
// As an Object
76-
getClassNames({class1: true, class2 : false});
81+
classList({class1: true, class2 : false});
7782

7883
// Output : "class1"
7984

80-
getClassNames({class1: undefined, class2 : null, class3: true, class4: false});
85+
classList({class1: undefined, class2 : null, class3: true, class4: false});
8186

8287
// Output : "class3"
8388
```
@@ -87,7 +92,7 @@ getClassNames({class1: undefined, class2 : null, class3: true, class4: false});
8792
```javascript
8893

8994
// Value as a function As an Object
90-
getClassNames({
95+
classList({
9196
class1: function() { return false; },
9297
class2 : function() { return true; }
9398
});
@@ -100,7 +105,7 @@ getClassNames({
100105
```javascript
101106

102107
// using all type of data
103-
getClassNames('class1', 'class2', 2, null, undefined, ['class3', null, undefined, 4, 'class4'], {
108+
classList('class1', 'class2', 2, null, undefined, ['class3', null, undefined, 4, 'class4'], {
104109
class5 : function() { return false; },
105110
class6 : function() { return true; },
106111
class7: undefined,

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
var getClassNames = require('./lib/get-class-names').getClassNames;
1+
const { getClassNames } = require('./lib/get-class-names');
22

33
module.exports = {
4-
getClassNames: getClassNames
4+
getClassNames,
5+
classList: getClassNames,
56
};

lib/get-class-names.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/get-class-names.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
getClassNames,
3+
classList: getClassNames,
34
};
45

56
function handleObject(objArg, classList) {

tests/getClassname.test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
/* eslint-disable no-undef */
2-
const getClassnames = require('../index').getClassNames;
2+
const { classList } = require('../index');
33

44
test('Print Numbers', () => {
5-
expect(getClassnames(1, 2)).toBe('1 2');
5+
expect(classList(1, 2)).toBe('1 2');
66
});
77

88
test('Print Strings', () => {
9-
expect(getClassnames('class', 'another')).toBe('class another');
9+
expect(classList('class', 'another')).toBe('class another');
1010
});
1111

1212
test('Print Array', () => {
13-
expect(getClassnames(['as', 'asdd'])).toBe('as asdd');
13+
expect(classList(['as', 'asdd'])).toBe('as asdd');
1414
});
1515

1616
test('Print Object', () => {
17-
expect(getClassnames({ abc: true, cde: false })).toBe('abc');
17+
expect(classList({ abc: true, cde: false })).toBe('abc');
1818
});
1919

2020
test('Print Functions', () => {
21-
expect(getClassnames({ abc: () => false, cde: () => true })).toBe('cde');
21+
expect(classList({ abc: () => false, cde: () => true })).toBe('cde');
2222
});
2323

2424
test('Print Bad Values', () => {
25-
expect(getClassnames(null, undefined)).toBe('');
25+
expect(classList(null, undefined)).toBe('');
2626
});
2727

2828
test('Print Bad Values in Object', () => {
2929
expect(
30-
getClassnames({
30+
classList({
3131
abs: undefined,
3232
cdb: null,
3333
abd: 2,
@@ -38,16 +38,16 @@ test('Print Bad Values in Object', () => {
3838
});
3939

4040
test('Print Bad Values in Functions', () => {
41-
expect(getClassnames({ abc: () => undefined, cde: () => null, add: () => {} })).toBe('');
41+
expect(classList({ abc: () => undefined, cde: () => null, add: () => {} })).toBe('');
4242
});
4343

4444
test('Print Bad Values in Array', () => {
45-
expect(getClassnames([null, undefined, 1, 'asd', {}])).toBe('1 asd');
45+
expect(classList([null, undefined, 1, 'asd', {}])).toBe('1 asd');
4646
});
4747

4848
test('Print hybrid', () => {
4949
expect(
50-
getClassnames(
50+
classList(
5151
1,
5252
2,
5353
'class',

0 commit comments

Comments
 (0)