Skip to content

Commit

Permalink
Require Node.js 12 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 16, 2021
1 parent 6e43778 commit cc0c4e8
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 36 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ jobs:
node-version:
- 14
- 12
- 10
- 8
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
14 changes: 3 additions & 11 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
declare namespace stringifyAttributes {
interface Attributes {
[attributeName: string]: string | number | boolean | readonly string[];
}
}
export type HTMLAttributes = Record<string, string | number | boolean | readonly string[]>;

/**
Turn an object into a string of HTML attributes.
Expand All @@ -11,7 +7,7 @@ Note that the string is prepended with a space when there are attributes to simp
@example
```
import stringifyAttributes = require('stringify-attributes');
import stringifyAttributes from 'stringify-attributes';
stringifyAttributes({
unicorn: '🦄',
Expand All @@ -22,8 +18,4 @@ stringifyAttributes({
//=> ' unicorn="🦄" rainbow number="1" multiple="a b"'
```
*/
declare function stringifyAttributes(
attributes: stringifyAttributes.Attributes
): string;

export = stringifyAttributes;
export default function stringifyAttributes(attributes: HTMLAttributes): string;
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
const {htmlEscape} = require('escape-goat');
import {htmlEscape} from 'escape-goat';

module.exports = attributes => {
export default function stringifyAttributes(attributes) {
const handledAttributes = [];

for (let [key, value] of Object.entries(attributes)) {
Expand All @@ -23,4 +22,4 @@ module.exports = attributes => {
}

return handledAttributes.length > 0 ? ' ' + handledAttributes.join(' ') : '';
};
}
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import stringifyAttributes = require('.');
import stringifyAttributes from './index.js';

expectType<string>(stringifyAttributes({unicorn: '🦄'}));
expectType<string>(stringifyAttributes({rainbow: true}));
Expand Down
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
"description": "Turn an object into a string of HTML attributes",
"license": "MIT",
"repository": "sindresorhus/stringify-attributes",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": ">=12"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -31,11 +34,11 @@
"transform"
],
"dependencies": {
"escape-goat": "^2.0.0"
"escape-goat": "^3.0.0"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
}
10 changes: 1 addition & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

> Turn an object into a string of HTML attributes

## Install

```
$ npm install stringify-attributes
```


## Usage

```js
const stringifyAttributes = require('stringify-attributes');
import stringifyAttributes from 'stringify-attributes';

stringifyAttributes({
unicorn: '🦄',
Expand All @@ -29,12 +27,6 @@ stringifyAttributes({

Note that the string is prepended with a space when there are attributes to simplify using it in a HTML tag.


## Related

- [create-html-element](https://github.com/sindresorhus/create-html-element) - Create a HTML element string


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import stringifyAttributes from '.';
import stringifyAttributes from './index.js';

test('stringifies attributes', t => {
t.is(
Expand Down

0 comments on commit cc0c4e8

Please sign in to comment.