Skip to content

Commit

Permalink
Change build type and target
Browse files Browse the repository at this point in the history
  • Loading branch information
scriptex committed Dec 28, 2020
1 parent 1b6ab3f commit 466e830
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ Schema:
}
```

## Usage in browser

You can use the module directly in the browser (without any module bundler such as Webpack or Parcel) but you will need to include `requirejs`.

The usage is not so straight-forward, so please refer to the [demo](https://github.com/scriptex/typed-usa-states/blob/master/demo/index.html)

## Typings

The package exports several types which can be used in TypeScript environment.
Expand Down
36 changes: 26 additions & 10 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Typed USA States</title>

<!-- Include the Require JS library from CDNJS -->
<script
src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"
integrity="sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg=="
Expand All @@ -13,19 +15,33 @@
<body>
<div id="result"></div>
<script>
require(['../dist/index.js'], function (lib) {
// This is the most important part
var exports = {};

// Require the needed files
require([
'../dist/cities.js',
'../dist/states-full.js',
'../dist/states-with-area.js',
'../dist/states-with-counties.js',
'../dist/states-with-population.js',
'../dist/states-with-zipcodes.js',
'../dist/states.js'
], function () {
var html = '';

console.log(lib.usaCities);
console.log(lib.usaStates);
console.log(lib.usaStatesFull);
console.log(lib.usaStatesWithArea);
console.log(lib.usaStatesWithCounties);
console.log(lib.usaStatesWithPopuation);
console.log(lib.usaStatesWithZipCodes);
// The exports object from above gets populated

console.log(exports.usaCities);
console.log(exports.usaStates);
console.log(exports.usaStatesFull);
console.log(exports.usaStatesWithArea);
console.log(exports.usaStatesWithCounties);
console.log(exports.usaStatesWithPopulation);
console.log(exports.usaStatesWithZipCodes);

Object.keys(lib).forEach(function (key) {
html += key + ': ' + lib[key].length + ' items<br>';
Object.keys(exports).forEach(function (key) {
html += key + ': ' + exports[key].length + ' items<br>';
});

document.getElementById('result').innerHTML = html;
Expand Down
4 changes: 2 additions & 2 deletions demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {
usaStatesFull,
usaStatesWithArea,
usaStatesWithCounties,
usaStatesWithPopuation,
usaStatesWithPopulation,
usaStatesWithZipCodes
} = require('../dist');

Expand All @@ -14,6 +14,6 @@ console.log({
usaStatesFull,
usaStatesWithArea,
usaStatesWithCounties,
usaStatesWithPopuation,
usaStatesWithPopulation,
usaStatesWithZipCodes
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typed-usa-states",
"version": "2.0.0",
"version": "2.0.1",
"description": "An array of geographical data for all USA states with full TypeScript support",
"scripts": {
"generate": "ts-node ./build/index.ts",
Expand Down
9 changes: 5 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"baseUrl": "./",
"alwaysStrict": true,
"alwaysStrict": false,
"allowSyntheticDefaultImports": true,
"allowJs": false,
"checkJs": false,
Expand All @@ -11,16 +11,17 @@
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"noEmitHelpers": true,
"lib": ["esNext"],
"target": "esNext",
"module": "umd",
"lib": ["esNext", "dom"],
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"noEmit": false,
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitUseStrict": true,
"noStrictGenericChecks": false,
"outDir": "dist",
"strict": true,
Expand Down

0 comments on commit 466e830

Please sign in to comment.