Skip to content

Commit

Permalink
Support types (#191)
Browse files Browse the repository at this point in the history
* Delete browser directory tracking

* Update eslint config

* Update README.md & docs

* Update package.json

* Update package.json & LICENSE

* Add index.d.ts
  • Loading branch information
petamoriken authored Apr 20, 2020
1 parent d6f1f15 commit 14d8ec9
Show file tree
Hide file tree
Showing 27 changed files with 1,526 additions and 2,455 deletions.
31 changes: 0 additions & 31 deletions .eslintrc.js

This file was deleted.

60 changes: 60 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"env": {
"browser": true,
"node": true,
"es6": true,
"mocha": true
},
"extends": [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings"
],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": ["import"],
"rules": {
"arrow-body-style": ["error", "always"],
"arrow-parens": ["error", "always"],
"comma-dangle": ["error", "always-multiline"],
"curly": ["error", "all"],
"eol-last": ["error", "always"],
"getter-return": "off",
"no-debugger": "warn",
"no-undef": "error",
"object-curly-newline": [
"error",
{
"ObjectExpression": { "multiline": true },
"ObjectPattern": { "multiline": true },
"ImportDeclaration": "never",
"ExportDeclaration": { "multiline": true, "minProperties": 3 }
}
],
"object-curly-spacing": ["error", "always"],
"quotes": ["error", "double", "avoid-escape"],
"semi": ["error", "always"],
"sort-imports": [
"error",
{
"ignoreDeclarationSort": true
}
],
"space-before-function-paren": [
"error",
{
"anonymous": "always",
"named": "never"
}
],
"import/no-unresolved": "off",
"import/order": ["error", {
"newlines-between": "never",
"alphabetize": {
"order": "asc"
}
}]
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

node_modules

/browser
/lib
/test_report
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"files.autoSave": "off",
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
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) 2017-2018 Kenta Moriuchi
Copyright (c) 2017-2020 Kenta Moriuchi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
23 changes: 10 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ see [ES Discuss Float16Array topic](https://esdiscuss.org/topic/float16array)
[![dependencies Status](https://david-dm.org/petamoriken/float16/status.svg?style=flat-square)](https://david-dm.org/petamoriken/float16)
[![devDependencies Status](https://david-dm.org/petamoriken/float16/dev-status.svg?style=flat-square)](https://david-dm.org/petamoriken/float16?type=dev)


[![Sauce Labs browser matrix](https://saucelabs.com/browser-matrix/petamoriken.svg)](https://saucelabs.com/u/petamoriken)



## Supports (at least)

This library's `Float16Array` uses `Proxy` object, so IE11 is never supported.
Expand All @@ -28,7 +25,7 @@ This library's `Float16Array` uses `Proxy` object, so IE11 is never supported.
* Safari: last 2 versions
* Node.js: latest version

When you build by yourself using webpack or rollup.js, please transpile JavaScript files in `src/` directory.
When you build by yourself using webpack or rollup.js for old browsers support, please transpile JavaScript files in `src/` directory.

## Install

Expand All @@ -44,10 +41,10 @@ npm install @petamoriken/float16 --save

## Require

### npm, yarn package
### Node.js or Bundler (webpack, rollup.js)

```js
// ES6 Modules
// ES Modules
import { Float16Array, getFloat16, setFloat16, hfround } from "@petamoriken/float16";
```

Expand All @@ -60,7 +57,7 @@ const { Float16Array, getFloat16, setFloat16, hfround } = require("@petamoriken/

### Browser

Copy [the build file for browsers](https://github.com/petamoriken/float16/blob/master/browser/float16.js) to your project directory.
Copy `browser/float16.js` file to your project directory.

```html
<script src="DEST/TO/float16.js"></script>
Expand All @@ -84,8 +81,8 @@ Copy [the build file for browsers](https://github.com/petamoriken/float16/blob/m
float16.reduce((prev, current) => prev + current); // 3.298828125
```

* `getFloat16(view: DataView, byteOffset: number [, littleEndian: boolean])`
* `setFloat16(view: DataView, byteOffset: number, value: number [, littleEndian: boolean])`
* `getFloat16(view: DataView, byteOffset: number, littleEndian?: boolean): number`
* `setFloat16(view: DataView, byteOffset: number, value: number, littleEndian?: boolean): void`

These APIs are similar to `DataView` methods such as `DataView#getFloat32` and `DataView#setFloat32`.

Expand All @@ -96,7 +93,7 @@ Copy [the build file for browsers](https://github.com/petamoriken/float16/blob/m
view.setUint16(0, 0x1234);
getFloat16(view, 0); // 0.0007572174072265625
// You can append to DataView instance
// You can append methods to DataView instance
view.getFloat16 = (...args) => getFloat16(view, ...args);
view.setFloat16 = (...args) => setFloat16(view, ...args);
Expand All @@ -106,7 +103,7 @@ Copy [the build file for browsers](https://github.com/petamoriken/float16/blob/m
view.getFloat16(0, true); // 3.140625
```

* `hfround(x: number)`
* `hfround(x: number): number`

This API is similar to `Math.fround` ([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)).
This function returns nearest half precision float representation of a number.
Expand All @@ -124,13 +121,13 @@ First, download devDependencies.
yarn
```

Build lib, browser files.
Build `lib/`, `browser/` files.

```console
yarn run build
```

Build docs files (for browser test).
Build `docs/` files (for browser test).

```console
yarn run docs
Expand Down
Loading

0 comments on commit 14d8ec9

Please sign in to comment.