Skip to content

Commit

Permalink
es6 modules revamp
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcg committed Dec 16, 2024
1 parent 8676a1b commit ddc92ff
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 58 deletions.
3 changes: 2 additions & 1 deletion .nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"check-coverage": false,
"reporter": ["text-summary", "html", "json", "lcov"],
"exclude": [
"test"
"test",
"lib"
]
}
14 changes: 14 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import globals from "globals";

export default [
{
files: ["src/*.js", "test/*.js"],
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
globals: {
...globals.node
}
}
}
];
40 changes: 8 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{
"name": "language-tags",
"version": "1.0.9",
"implements": [
"CommonJS/Modules/1.0"
],
"description": "Work with IANA language tags.",
"main": "lib/index.js",
"type": "commonjs",
"type": "module",
"homepage": "https://github.com/mattcg/language-tags",
"author": "Matthew Caruana Galizia <[email protected]>",
"repository": {
Expand All @@ -21,8 +18,8 @@
"prepublishOnly": "npm run build",
"prebuild": "rimraf lib && mkdirp lib",
"build": "babel src -d lib",
"lint": "eslint --ext=js,mjs .",
"tests-only": "nyc mocha --recursive test",
"lint": "eslint ./src ./test",
"tests-only": "nyc mocha",
"pretest": "npm run lint",
"test": "npm run tests-only"
},
Expand All @@ -41,37 +38,16 @@
"@babel/cli": "^7.22.10",
"@babel/preset-env": "^7.22.10",
"coveralls": "^3.1.1",
"eslint": "^8.47.0",
"mkdirp": "^0.5.6",
"mocha": "^3.5.3",
"nyc": "^10.3.2",
"rimraf": "^2.7.1"
"eslint": "^9.17.0",
"mkdirp": "^3.0.1",
"mocha": "^11.0.1",
"nyc": "^17.1.0",
"rimraf": "^6.0.1"
},
"files": [
"/lib"
],
"engines": {
"node": ">=0.10"
},
"eslintConfig": {
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "script"
},
"env": {
"node": true
},
"ignorePatterns": [
"!.babelrc.js"
],
"overrides": [
{
"files": "test/**",
"globals": {
"suite": false,
"test": false
}
}
]
}
}
8 changes: 3 additions & 5 deletions src/Subtag.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

'use strict';

var index = require('language-subtag-registry/data/json/index.json');
var registry = require('language-subtag-registry/data/json/registry.json');
import index from 'language-subtag-registry/data/json/index.json' with { type: 'json' };
import registry from 'language-subtag-registry/data/json/registry.json' with { type: 'json' };

class Subtag {
export default class Subtag {
static ERR_NONEXISTENT = 1;
static ERR_TAG = 2;

Expand Down Expand Up @@ -119,5 +119,3 @@ class Subtag {
return this.format();
}
}

module.exports = Subtag;
10 changes: 4 additions & 6 deletions src/Tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

'use strict';

var index = require('language-subtag-registry/data/json/index.json');
var registry = require('language-subtag-registry/data/json/registry.json');
import index from 'language-subtag-registry/data/json/index.json' with { type: 'json' };
import registry from 'language-subtag-registry/data/json/registry.json' with { type: 'json' };

var Subtag = require('./Subtag.js');
import Subtag from './Subtag.js';

class Tag {
export default class Tag {
static ERR_DEPRECATED = 1;
static ERR_NO_LANGUAGE = 2;
static ERR_UNKNOWN = 3;
Expand Down Expand Up @@ -403,5 +403,3 @@ class Tag {
});
}
}

module.exports = Tag;
18 changes: 10 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@

'use strict';

var Tag = require('./Tag.js');
var Subtag = require('./Subtag.js');
import Tag from './Tag.js';
import Subtag from './Subtag.js';

var index = require('language-subtag-registry/data/json/index.json');
var registry = require('language-subtag-registry/data/json/registry.json');
import index from 'language-subtag-registry/data/json/index.json' with { type: 'json' };
import registry from 'language-subtag-registry/data/json/registry.json' with { type: 'json' };
import meta from 'language-subtag-registry/data/json/meta.json' with { type: 'json' };
import macrolanguages from 'language-subtag-registry/data/json/macrolanguage.json' with { type: 'json' };

var tags = function(tag) {
const tags = function(tag) {
return new Tag(tag);
};

module.exports = tags;
export default tags;

tags.check = function(tag) {
return new Tag(tag).valid();
Expand Down Expand Up @@ -103,7 +105,7 @@ tags.languages = function(macrolanguage) {
var i, l, record, results = [];

macrolanguage = macrolanguage.toLowerCase();
if (!require('language-subtag-registry/data/json/macrolanguage.json')[macrolanguage]) {
if (!macrolanguages[macrolanguage]) {
throw new Error('\'' + macrolanguage + '\' is not a macrolanguage.');
}

Expand Down Expand Up @@ -136,5 +138,5 @@ tags.type = function(subtag, type) {
};

tags.date = function() {
return require('language-subtag-registry/data/json/meta.json')['File-Date'];
return meta['File-Date'];
};
5 changes: 3 additions & 2 deletions test/lib/SubtagTest.js → test/src/SubtagTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

'use strict';

var assert = require('assert');
var Subtag = require('../../lib/Subtag');
import assert from 'assert';
import {describe, it} from 'mocha';
import Subtag from '../../src/Subtag.js';

describe('Subtag', function () {
it('subtag.type() returns type', function() {
Expand Down
5 changes: 3 additions & 2 deletions test/lib/TagTest.js → test/src/TagTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

'use strict';

var assert = require('assert');
var Tag = require('../../lib/Tag');
import assert from 'assert';
import {describe, it} from 'mocha';
import Tag from '../../src/Tag.js';

describe('Tag', function () {
it('tag.type() returns \'grandfathered\'', function() {
Expand Down
5 changes: 3 additions & 2 deletions test/lib/index-test.js → test/src/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

'use strict';

var assert = require('assert');
var tags = require('../../lib');
import assert from 'assert';
import {describe, it} from 'mocha';
import tags from '../../src/index.js';

describe('tags', function () {
it('date() returns file date', function() {
Expand Down

0 comments on commit ddc92ff

Please sign in to comment.