Skip to content

Commit

Permalink
build!: convert to ESM module
Browse files Browse the repository at this point in the history
  • Loading branch information
slavik-chapelskyi committed Nov 3, 2023
1 parent 91d930b commit 062ff94
Show file tree
Hide file tree
Showing 31 changed files with 78 additions and 145 deletions.
19 changes: 0 additions & 19 deletions babel.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import benny from 'benny';
import {orderBy as orderByOriginal} from 'natural-orderby';
import {orderBy as orderByOptimized} from './lib';
import {orderBy as orderByOptimized} from './lib/index.js';

const inputArray = [
{
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
"email": "[email protected]",
"url": "https://shelf.io"
},
"main": "lib",
"type": "module",
"sideEffects": false,
"exports": "./lib/index.js",
"module": "./lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib"
],
"scripts": {
"benchmark": "yarn build && babel benchmark.ts | node",
"build": "rm -rf lib/ && yarn build:types && yarn build:webpack",
"build:types": "tsc -p tsconfig.types.json",
"build:webpack": "NODE_ENV=production webpack",
"benchmark": "yarn build && tsc benchmark.ts | node",
"build": "rm -rf lib/ && tsc",
"coverage": "yarn test --coverage",
"lint": "yarn lint:ci --fix",
"lint:ci": "eslint . --ext .js,.ts,.json",
Expand Down
6 changes: 3 additions & 3 deletions src/compare/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import baseCompare from '../utils/baseCompare';
import getOptions from '../utils/getOptions';
import type {CompareFn, CompareOptions} from '../types';
import baseCompare from '../utils/baseCompare.js';
import getOptions from '../utils/getOptions.js';
import type {CompareFn, CompareOptions} from '../types.js';

/**
* Creates a compare function that defines the natural sort order considering
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// https://github.com/yobacca/natural-sort-order
// released under MIT License
import orderBy from './orderBy';
import compare from './compare';
import orderBy from './orderBy/index.js';
import compare from './compare/index.js';

export {orderBy, compare};
8 changes: 4 additions & 4 deletions src/orderBy/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import baseOrderBy from '../utils/baseOrderBy';
import getIdentifiers from '../utils/getIdentifiers';
import getOrders from '../utils/getOrders';
import type {Identifier, Order} from '../types';
import baseOrderBy from '../utils/baseOrderBy.js';
import getIdentifiers from '../utils/getIdentifiers.js';
import getOrders from '../utils/getOrders.js';
import type {Identifier, Order} from '../types.js';

/**
* Creates an array of elements, natural sorted by specified identifiers and
Expand Down
6 changes: 3 additions & 3 deletions src/utils/baseCompare.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import getMappedValueRecord from './getMappedValueRecord';
import compareValues from './compareValues';
import type {BaseCompareOptions} from '../types';
import getMappedValueRecord from './getMappedValueRecord.js';
import compareValues from './compareValues.js';
import type {BaseCompareOptions} from '../types.js';

function baseCompare(options: BaseCompareOptions) {
return (valueA: unknown, valueB: unknown): number => {
Expand Down
12 changes: 6 additions & 6 deletions src/utils/baseOrderBy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable multiline-ternary */
import compareMultiple from './compareMultiple';
import createIdentifierFn from './createIdentifierFn';
import getMappedValueRecord from './getMappedValueRecord';
import getValueByIdentifier from './getValueByIdentifier';
import getElementByIndex from './getElementByIndex';
import type {Identifier, IdentifierFn, MappedCollection, Order} from '../types';
import compareMultiple from './compareMultiple.js';
import createIdentifierFn from './createIdentifierFn.js';
import getMappedValueRecord from './getMappedValueRecord.js';
import getValueByIdentifier from './getValueByIdentifier.js';
import getElementByIndex from './getElementByIndex.js';
import type {Identifier, IdentifierFn, MappedCollection, Order} from '../types.js';

const baseOrderBy = <T>(
collection: ReadonlyArray<T>,
Expand Down
10 changes: 5 additions & 5 deletions src/utils/compareChunks.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type {ChunkMaps} from '../types';
import {RE_UNICODE_CHARACTERS} from './regex';
import compareNumbers from './compareNumbers';
import compareUnicode from './compareUnicode';
import stringCompare from './stringCompare';
import type {ChunkMaps} from '../types.js';
import {RE_UNICODE_CHARACTERS} from './regex.js';
import compareNumbers from './compareNumbers.js';
import compareUnicode from './compareUnicode.js';
import stringCompare from './stringCompare.js';

const compareChunks = (chunksA: ChunkMaps, chunksB: ChunkMaps): number => {
const lengthA = chunksA.length;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/compareMultiple.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {MappedRecord, Order} from '../types';
import compareValues from './compareValues';
import type {MappedRecord, Order} from '../types.js';
import compareValues from './compareValues.js';

const compareMultiple = (
recordA: MappedRecord,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/compareOtherTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {MappedValueRecord} from '../types';
import type {MappedValueRecord} from '../types.js';

const compareOtherTypes = (valueA: MappedValueRecord, valueB: MappedValueRecord): number => {
if (!valueA.chunks ? valueB.chunks : !valueB.chunks) {
Expand Down
8 changes: 4 additions & 4 deletions src/utils/compareValues.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {MappedValueRecord} from '../types';
import compareNumbers from './compareNumbers';
import compareChunks from './compareChunks';
import compareOtherTypes from './compareOtherTypes';
import type {MappedValueRecord} from '../types.js';
import compareNumbers from './compareNumbers.js';
import compareChunks from './compareChunks.js';
import compareOtherTypes from './compareOtherTypes.js';

const compareValues = (valueA: MappedValueRecord, valueB: MappedValueRecord): number => {
if (valueA.value === valueB.value) {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/createChunkMap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {Chunk, ChunkMap, Chunks} from '../types';
import normalizeAlphaChunk from './normalizeAlphaChunk';
import normalizeNumericChunk from './normalizeNumericChunk';
import type {Chunk, ChunkMap, Chunks} from '../types.js';
import normalizeAlphaChunk from './normalizeAlphaChunk.js';
import normalizeNumericChunk from './normalizeNumericChunk.js';

const createChunkMap = (chunk: Chunk, index: number, chunks: Chunks): ChunkMap => {
return {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/createChunkMaps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {ChunkMaps} from '../types';
import createChunks from './createChunks';
import createChunkMap from './createChunkMap';
import type {ChunkMaps} from '../types.js';
import createChunks from './createChunks.js';
import createChunkMap from './createChunkMap.js';

function createChunkMaps(value: string): ChunkMaps {
return createChunks(value).map(createChunkMap);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/createChunks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {RE_NUMBERS} from './regex';
import {RE_NUMBERS} from './regex.js';

const createChunks = (value: string): Array<string> =>
value.replace(RE_NUMBERS, '\0$1\0').replace(/\0$/, '').replace(/^\0/, '').split('\0');
Expand Down
2 changes: 1 addition & 1 deletion src/utils/createIdentifierFn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Identifier, IdentifierFn} from '../types';
import type {Identifier, IdentifierFn} from '../types.js';

const createIdentifierFn = <T>(identifier: Identifier<T>): IdentifierFn<T> => {
if (typeof identifier === 'function') {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getIdentifiers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Identifier} from '../types';
import type {Identifier} from '../types.js';

const getIdentifiers = <T>(
identifiers?:
Expand Down
20 changes: 10 additions & 10 deletions src/utils/getMappedValueRecord.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type {MappedValueRecord} from '../types';
import stringify from './stringify';
import numberify from './numberify';
import createChunkMaps from './createChunkMaps';
import isFunction from './isFunction';
import isNaN from './isNaN';
import isNull from './isNull';
import isObject from './isObject';
import isSymbol from './isSymbol';
import isUndefined from './isUndefined';
import type {MappedValueRecord} from '../types.js';
import stringify from './stringify.js';
import numberify from './numberify.js';
import createChunkMaps from './createChunkMaps.js';
import isFunction from './isFunction.js';
import isNaN from './isNaN.js';
import isNull from './isNull.js';
import isObject from './isObject.js';
import isSymbol from './isSymbol.js';
import isUndefined from './isUndefined.js';

const getMappedValueRecord = (value: unknown): MappedValueRecord => {
if (
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {BaseCompareOptions, CompareOptions, OrderEnum} from '../types';
import type {BaseCompareOptions, CompareOptions, OrderEnum} from '../types.js';

const isValidOrder = (value: unknown | null | undefined): boolean =>
typeof value === 'string' && (value === 'asc' || value === 'desc');
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getOrders.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Order} from '../types';
import type {Order} from '../types.js';

const getOrders = (
orders?: (ReadonlyArray<Order> | null | undefined) | (Order | null | undefined)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getValueByIdentifier.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {IdentifierFn} from '../types';
import type {IdentifierFn} from '../types.js';

const getValueByIdentifier = <T>(value: T, getValue: IdentifierFn<T>): unknown | T =>
getValue(value);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/normalizeAlphaChunk.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {Chunk} from '../types';
import {RE_LEADING_OR_TRAILING_WHITESPACES, RE_WHITESPACES} from './regex';
import type {Chunk} from '../types.js';
import {RE_LEADING_OR_TRAILING_WHITESPACES, RE_WHITESPACES} from './regex.js';

const normalizeAlphaChunk = (chunk: Chunk): string =>
chunk.replace(RE_WHITESPACES, ' ').replace(RE_LEADING_OR_TRAILING_WHITESPACES, '');
Expand Down
6 changes: 3 additions & 3 deletions src/utils/normalizeNumericChunk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {Chunk, Chunks} from '../types';
import {RE_INT_OR_FLOAT, RE_LEADING_ZERO} from './regex';
import parseNumber from './parseNumber';
import type {Chunk, Chunks} from '../types.js';
import {RE_INT_OR_FLOAT, RE_LEADING_ZERO} from './regex.js';
import parseNumber from './parseNumber.js';

const normalizeNumericChunk = (chunk: Chunk, index: number, chunks: Chunks): number | undefined => {
if (RE_INT_OR_FLOAT.test(chunk)) {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/numberify.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import parseNumber from './parseNumber';
import parseDate from './parseDate';
import type {ParsedNumber} from '../types';
import parseNumber from './parseNumber.js';
import parseDate from './parseDate.js';
import type {ParsedNumber} from '../types.js';

const numberify = (value: string): ParsedNumber | undefined => {
const parsedNumber = parseNumber(value);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/parseDate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {ParsedNumber} from '../types';
import {RE_DATE} from './regex';
import type {ParsedNumber} from '../types.js';
import {RE_DATE} from './regex.js';

const parseDate = (value: string): ParsedNumber | undefined => {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/parseNumber.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {ParsedNumber} from '../types';
import type {ParsedNumber} from '../types.js';

const parseNumber = (value: string): ParsedNumber | undefined => {
if (value.length !== 0) {
Expand Down
6 changes: 2 additions & 4 deletions src/utils/stringify.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {RE_LEADING_OR_TRAILING_WHITESPACES} from './regex';
import {RE_LEADING_OR_TRAILING_WHITESPACES} from './regex.js';

const stringify = (
value: string | number | boolean | boolean | number | string | Date | any
): string => {
const stringify = (value: string | number | boolean | Date | any): string => {
if (typeof value === 'boolean' || value instanceof Boolean) {
return Number(value).toString();
}
Expand Down
8 changes: 6 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"extends": "@shelf/tsconfig/backend",
"compilerOptions": {
"strict": true
"declaration": true,
"moduleResolution": "node16",
"module": "node16",
"target": "ESNext",
"outDir": "lib"
},
"exclude": ["node_modules"],
"include": ["src"]
"include": ["src/index.ts"]
}
17 changes: 0 additions & 17 deletions tsconfig.types.json

This file was deleted.

File renamed without changes.
34 changes: 0 additions & 34 deletions webpack.config.js

This file was deleted.

0 comments on commit 062ff94

Please sign in to comment.