Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps-dev): replace standard with neostandard #750

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CI](https://github.com/fastify/fast-json-stringify/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fast-json-stringify/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/fast-json-stringify.svg?style=flat)](https://www.npmjs.com/package/fast-json-stringify)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)
[![NPM downloads](https://img.shields.io/npm/dm/fast-json-stringify.svg?style=flat)](https://www.npmjs.com/package/fast-json-stringify)


Expand Down
1 change: 0 additions & 1 deletion benchmark/bench-cmp-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ const getRandomString = (length) => {
return result[0].toUpperCase() + result.slice(1)
}

// eslint-disable-next-line
for (let i = 0; i < STR_LEN; i++) {
largeArray[i] = {
firstName: getRandomString(8),
Expand Down
9 changes: 9 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'

module.exports = require('neostandard')({
ignores: [
...require('neostandard').resolveIgnoresFromGitignore(),
'lib/schema-validator.js'
],
ts: true
})
11 changes: 3 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"bench:cmp": "node ./benchmark/bench-cmp-branch.js",
"bench:cmp:ci": "node ./benchmark/bench-cmp-branch.js --ci",
"benchmark": "node ./benchmark/bench-cmp-lib.js",
"lint": "standard",
"lint:fix": "standard --fix",
"lint": "eslint",
"lint:fix": "eslint --fix",
"test:typescript": "tsd",
"test:unit": "c8 node --test",
"test": "npm run test:unit && npm run test:typescript"
Expand Down Expand Up @@ -45,8 +45,8 @@
"compile-json-stringify": "^0.1.2",
"fast-json-stringify": ".",
"is-my-json-valid": "^2.20.6",
"neostandard": "^0.11.9",
"simple-git": "^3.23.0",
"standard": "^17.1.0",
"tsd": "^0.31.0",
"webpack": "^5.90.3"
},
Expand All @@ -58,10 +58,5 @@
"json-schema-ref-resolver": "^2.0.0",
"rfdc": "^1.2.0"
},
"standard": {
"ignore": [
"schema-validator.js"
]
},
"runkitExampleFilename": "./examples/example.js"
}
50 changes: 25 additions & 25 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Ajv, { Options as AjvOptions } from "ajv"
import Ajv, { Options as AjvOptions } from 'ajv'

type Build = typeof build

Expand Down Expand Up @@ -70,36 +70,36 @@ declare namespace build {
}

export interface StringSchema extends BaseSchema {
type: "string";
type: 'string';
format?: string;
}

export interface IntegerSchema extends BaseSchema {
type: "integer";
type: 'integer';
}

export interface NumberSchema extends BaseSchema {
type: "number";
type: 'number';
}

export interface NullSchema extends BaseSchema {
type: "null";
type: 'null';
}

export interface BooleanSchema extends BaseSchema {
type: "boolean";
type: 'boolean';
}

export interface ArraySchema extends BaseSchema {
type: "array";
type: 'array';
/**
* The schema for the items in the array
*/
items: Schema | {}
}

export interface TupleSchema extends BaseSchema {
type: "array";
type: 'array';
/**
* The schemas for the items in the tuple
*/
Expand All @@ -115,7 +115,7 @@ declare namespace build {
}

export interface ObjectSchema extends BaseSchema {
type: "object";
type: 'object';
/**
* Describe the properties of the object
*/
Expand Down Expand Up @@ -145,7 +145,7 @@ declare namespace build {
| BooleanSchema
| ArraySchema
| TupleSchema
| ObjectSchema;
| ObjectSchema

export interface Options {
/**
Expand Down Expand Up @@ -208,24 +208,24 @@ interface StandaloneOption extends build.Options {
mode: 'standalone'
}

type StringCoercible = string | Date | RegExp;
type IntegerCoercible = number | BigInt;
type StringCoercible = string | Date | RegExp
type IntegerCoercible = number | BigInt

/**
* Build a stringify function using a schema of the documents that should be stringified
* @param schema The schema used to stringify values
* @param options The options to use (optional)
*/
declare function build(schema: build.AnySchema, options: DebugOption): { code: string, ajv: Ajv };
declare function build(schema: build.AnySchema, options: DeprecateDebugOption): { code: string, ajv: Ajv };
declare function build(schema: build.AnySchema, options: StandaloneOption): string;
declare function build(schema: build.AnySchema, options?: build.Options): <TDoc = any>(doc: TDoc) => any;
declare function build(schema: build.StringSchema, options?: build.Options): <TDoc extends StringCoercible = StringCoercible>(doc: TDoc) => string;
declare function build(schema: build.IntegerSchema | build.NumberSchema, options?: build.Options): <TDoc extends IntegerCoercible = IntegerCoercible>(doc: TDoc) => string;
declare function build(schema: build.NullSchema, options?: build.Options): <TDoc extends null = null>(doc: TDoc) => "null";
declare function build(schema: build.BooleanSchema, options?: build.Options): <TDoc extends boolean = boolean>(doc: TDoc) => string;
declare function build(schema: build.ArraySchema | build.TupleSchema, options?: build.Options): <TDoc extends any[]= any[]>(doc: TDoc) => string;
declare function build(schema: build.ObjectSchema, options?: build.Options): <TDoc extends object = object>(doc: TDoc) => string;
declare function build(schema: build.Schema, options?: build.Options): <TDoc = object | any[] | string | number | boolean | null> (doc: TDoc) => string;

export = build;
declare function build (schema: build.AnySchema, options: DebugOption): { code: string, ajv: Ajv }
declare function build (schema: build.AnySchema, options: DeprecateDebugOption): { code: string, ajv: Ajv }
declare function build (schema: build.AnySchema, options: StandaloneOption): string
declare function build (schema: build.AnySchema, options?: build.Options): <TDoc = any>(doc: TDoc) => any
declare function build (schema: build.StringSchema, options?: build.Options): <TDoc extends StringCoercible = StringCoercible>(doc: TDoc) => string
declare function build (schema: build.IntegerSchema | build.NumberSchema, options?: build.Options): <TDoc extends IntegerCoercible = IntegerCoercible>(doc: TDoc) => string
declare function build (schema: build.NullSchema, options?: build.Options): <TDoc extends null = null>(doc: TDoc) => 'null'
declare function build (schema: build.BooleanSchema, options?: build.Options): <TDoc extends boolean = boolean>(doc: TDoc) => string
declare function build (schema: build.ArraySchema | build.TupleSchema, options?: build.Options): <TDoc extends any[]= any[]>(doc: TDoc) => string
declare function build (schema: build.ObjectSchema, options?: build.Options): <TDoc extends object = object>(doc: TDoc) => string
declare function build (schema: build.Schema, options?: build.Options): <TDoc = object | any[] | string | number | boolean | null> (doc: TDoc) => string

export = build
147 changes: 74 additions & 73 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Test using this disabled, see https://github.com/fastify/fast-json-stringify/pull/683
import Ajv from 'ajv'
import build, { restore, Schema, validLargeArrayMechanisms } from '..'
import { expectError, expectType } from 'tsd'

// Number schemas
build({
type: 'number'
type: 'number'
})(25)
build({
type: 'integer'
type: 'integer'
})(-5)
build({
type: 'integer'
type: 'integer'
})(5n)

build({
type: 'number'
type: 'number'
}, { rounding: 'ceil' })
build({
type: 'number'
type: 'number'
}, { rounding: 'floor' })
build({
type: 'number'
type: 'number'
}, { rounding: 'round' })
build({
type: 'number'
type: 'number'
}, { rounding: 'trunc' })
expectError(build({
type: 'number'
type: 'number'
}, { rounding: 'invalid' }))

// String schema
Expand All @@ -36,55 +37,55 @@ build({

// Boolean schema
build({
type: 'boolean'
type: 'boolean'
})(true)

// Null schema
build({
type: 'null'
type: 'null'
})(null)

// Array schemas
build({
type: 'array',
items: { type: 'number' }
type: 'array',
items: { type: 'number' }
})([25])
build({
type: 'array',
items: [{ type: 'string'}, {type: 'integer'}]
type: 'array',
items: [{ type: 'string' }, { type: 'integer' }]
})(['hello', 42])

// Object schemas
build({
type: 'object'
type: 'object'
})({})
build({
type: 'object',
properties: {
foo: { type: 'string' },
bar: { type: 'integer' }
},
required: ['foo'],
patternProperties: {
'baz*': { type: 'null' }
},
additionalProperties: {
type: 'boolean'
}
type: 'object',
properties: {
foo: { type: 'string' },
bar: { type: 'integer' }
},
required: ['foo'],
patternProperties: {
'baz*': { type: 'null' }
},
additionalProperties: {
type: 'boolean'
}
})({ foo: 'bar' })
build({
type: 'object',
properties: {
foo: { type: 'string' },
bar: { type: 'integer' }
},
required: ['foo'],
patternProperties: {
'baz*': { type: 'null' }
},
additionalProperties: {
type: 'boolean'
}
type: 'object',
properties: {
foo: { type: 'string' },
bar: { type: 'integer' }
},
required: ['foo'],
patternProperties: {
'baz*': { type: 'null' }
},
additionalProperties: {
type: 'boolean'
}
}, { rounding: 'floor' })({ foo: 'bar' })

// Reference schemas
Expand Down Expand Up @@ -113,7 +114,7 @@ build({
}
},
patternProperties: {
'num': {
num: {
$ref: '#/definitions/num'
}
},
Expand Down Expand Up @@ -207,52 +208,52 @@ interface InferenceSchema {
}

const stringify3 = build({
type: "object",
properties: { a: { type: "string" } },
});
stringify3<InferenceSchema>({ id: "123" });
stringify3<InferenceSchema>({ a: 123, id: "123" });
expectError(stringify3<InferenceSchema>({ anotherOne: "bar" }));
expectError(stringify3<Schema>({ a: "bar" }));
type: 'object',
properties: { a: { type: 'string' } },
})
stringify3<InferenceSchema>({ id: '123' })
stringify3<InferenceSchema>({ a: 123, id: '123' })
expectError(stringify3<InferenceSchema>({ anotherOne: 'bar' }))
expectError(stringify3<Schema>({ a: 'bar' }))

// Without inference
const stringify4 = build({
type: "object",
properties: { a: { type: "string" } },
});
stringify4({ id: "123" });
stringify4({ a: 123, id: "123" });
stringify4({ anotherOne: "bar" });
stringify4({ a: "bar" });
type: 'object',
properties: { a: { type: 'string' } },
})
stringify4({ id: '123' })
stringify4({ a: 123, id: '123' })
stringify4({ anotherOne: 'bar' })
stringify4({ a: 'bar' })

// Without inference - string type
const stringify5 = build({
type: "string",
});
stringify5("foo");
expectError(stringify5({ id: "123" }));
type: 'string',
})
stringify5('foo')
expectError(stringify5({ id: '123' }))

// Without inference - null type
const stringify6 = build({
type: "null",
});
stringify6(null);
expectError(stringify6("a string"));
type: 'null',
})
stringify6(null)
expectError(stringify6('a string'))

// Without inference - boolean type
const stringify7 = build({
type: "boolean",
});
stringify7(true);
expectError(stringify7("a string"));
type: 'boolean',
})
stringify7(true)
expectError(stringify7('a string'))

// largeArrayMechanism

build({}, { largeArrayMechanism: 'json-stringify'} )
build({}, { largeArrayMechanism: 'default'} )
expectError(build({} as Schema, { largeArrayMechanism: 'invalid'} ))
build({}, { largeArrayMechanism: 'json-stringify' })
build({}, { largeArrayMechanism: 'default' })
expectError(build({} as Schema, { largeArrayMechanism: 'invalid' }))

build({}, { largeArraySize: 2000 } )
build({}, { largeArraySize: '2e4' } )
build({}, { largeArraySize: 2n } )
expectError(build({} as Schema, { largeArraySize: ['asdf']} ))
build({}, { largeArraySize: 2000 })
build({}, { largeArraySize: '2e4' })
build({}, { largeArraySize: 2n })
expectError(build({} as Schema, { largeArraySize: ['asdf'] }))
Loading