Skip to content

Commit

Permalink
Merge pull request openvinotoolkit#6 from vishniakov-nikolai/fix/add-…
Browse files Browse the repository at this point in the history
…es-lint

Add ESLint
  • Loading branch information
vishniakov-nikolai authored May 2, 2023
2 parents c79dc5e + 14c5fee commit 6395c6d
Show file tree
Hide file tree
Showing 16 changed files with 4,639 additions and 46 deletions.
14 changes: 14 additions & 0 deletions src/bindings/js/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
ignorePatterns: ['**/*.js', 'node_modules/', 'types/', 'dist/', 'bin/'],
root: true,
rules: {
'semi': ['error'],
'max-len': ['error'],
'eol-last': ['error'],
'indent': ['error', 2],
'camelcase': ['error'],
'comma-dangle': ['error', 'always-multiline'],
'no-multiple-empty-lines': ['error', { max: 1, maxBOF: 0, maxEOF: 0 }],
}
};
5 changes: 5 additions & 0 deletions src/bindings/js/common/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
extends: ['../.eslintrc.js'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
};
3 changes: 2 additions & 1 deletion src/bindings/js/common/lib/maps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { JSArrayType, PrecisionSupportedType } from './types';

export const jsTypeByPrecisionMap: { [Precision in PrecisionSupportedType]: JSArrayType } = {
export const jsTypeByPrecisionMap
: { [Precision in PrecisionSupportedType]: JSArrayType } = {
i8: Int8Array,
u8: Uint8Array,
// u8c: Uint8ClampedArray,
Expand Down
8 changes: 6 additions & 2 deletions src/bindings/js/common/lib/shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ export default class Shape implements IShape {
constructor(dimensionsArray: number[]);
constructor(...dimensionsArray: number[]);
constructor(...dimensionsArray: number[] | [number[]]) {
const dimensions: number[] = Array.isArray(dimensionsArray[0]) ? dimensionsArray[0] : dimensionsArray as number[];
const dimensions: number[] = Array.isArray(dimensionsArray[0])
? dimensionsArray[0]
: dimensionsArray as number[];

this.#dimensions = new Uint32Array(dimensions.length);

dimensions.map((dimension, index): void => { this.#dimensions[index] = dimension });
dimensions.map((dimension, index): void => {
this.#dimensions[index] = dimension;
});
}

get dim(): number {
Expand Down
6 changes: 5 additions & 1 deletion src/bindings/js/common/lib/tensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ export default class Tensor implements ITensor {
#data: TypedArray;
#shape: IShape;

constructor(precision: PrecisionSupportedType, data: number[] | TypedArray, shapeData: IShape | number[]) {
constructor(
precision: PrecisionSupportedType,
data: number[] | TypedArray,
shapeData: IShape | number[],
) {
this.#precision = precision;
this.#data = new jsTypeByPrecisionMap[this.#precision](data);

Expand Down
13 changes: 11 additions & 2 deletions src/bindings/js/common/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,23 @@ export interface IModel {
infer(tensorOrDataArray: ITensor | number[], shape: IShape): Promise<ITensor>,
}

export type LoadModelType = (xmlPath: string, binPath: string, shapeData: Shape | number[], layout: string) => Promise<IModel>;
export type LoadModelType = (
xmlPath: string,
binPath: string,
shapeData: Shape | number[],
layout: string
) => Promise<IModel>;

export interface IOpenVINOJSLibrary {
loadModel: LoadModelType,
getVersionString: () => Promise<string>,
getDescriptionString: () => Promise<string>,
Shape: new (...dimensionsArray: number[] | [number[]]) => Shape,
Tensor: new (precision: PrecisionSupportedType, data: number[] | TypedArray, shapeData: IShape | number[]) => Tensor,
Tensor: new (
precision: PrecisionSupportedType,
data: number[] | TypedArray,
shapeData: IShape | number[]
) => Tensor,
}

export type OpenVINOJSLibrary = Promise<IOpenVINOJSLibrary>;
Loading

0 comments on commit 6395c6d

Please sign in to comment.