0.3.0 • Published 12 months ago

qing-shared-const v0.3.0

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
12 months ago

qing-shared-const

Build Status npm version Node.js Version

Generate JavaScript/Go constants from JSON.

Installation

npm i qing-shared-const

Usage

Go

import { go } from 'qing-shared-const';

go.convert(
  {
    str: 'hello world',
    intProp: 123,
    doubleProp: 12.3,
    __enums: {
      color: { values: ['red', 'blue'] },
      color2: { values: ['red', 'blue'] },
    },
  },
  { packageName: 'test', typeName: 'Test' },
);

Output:

package test

const Str = "hello world"
const IntProp = 123
const DoubleProp = 12.3

type Color int

const (
	ColorRed Color = iota
	ColorBlue
)

type Color2 int

const (
	Color2Red Color2 = iota
	Color2Blue
)

JavaScript

import { js } from 'qing-shared-const';

js.convert({
  intValue: -12,
  strValue: 'haha"\'',
  nullValue: null,
  arrayValue: [32, 'wow', null],
  __enums: {
    color: { values: ['red', 'blue'] },
    color2: { values: ['red', 'blue'] },
  },
});

Output:

export const intValue = -12;
export const strValue = 'haha"\'';
export const nullValue = null;
export const arrayValue = [32, 'wow', null];

export var Color;
(function (Color) {
  Color[(Color['red'] = 0)] = 'red';
  Color[(Color['blue'] = 0)] = 'blue';
})(Color || (Color = {}));

export var Color2;
(function (Color2) {
  Color2[(Color2['red'] = 0)] = 'red';
  Color2[(Color2['blue'] = 0)] = 'blue';
})(Color2 || (Color2 = {}));

TypeScript definition is also supported:

import { js } from 'qing-shared-const';

js.convert(
  {
    intValue: -12,
    strValue: 'haha"\'',
    nullValue: null,
    arrayValue: [32, 'wow', null],
    __enums: {
      color: { values: ['red', 'blue'] },
      color2: { values: ['red', 'blue'] },
    },
  },
  { dts: true },
);

Output:

export declare const intValue = -12;
export declare const strValue = 'haha"\'';
export declare const nullValue = null;
export declare const arrayValue: number[];

export declare enum Color {
  red = 1,
  blue = 2,
}

export declare enum Color2 {
  red = 1,
  blue = 2,
}
0.3.0

12 months ago

0.2.0

1 year ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago