diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 58dd174..456c4ce 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -19,49 +19,60 @@ pool: steps: - task: NodeTool@0 inputs: + versionSource: 'spec' versionSpec: 18.x - + checkLatest: true - script: | npm install -g typescript jest typedoc displayName: 'Install Globals' + continueOnError: false - script: | npm install npm run build displayName: 'Build Library' + continueOnError: false - script: npm run lint displayName: 'Run Lint' + continueOnError: false - script: npm run doc displayName: 'Run Type Doc' + continueOnError: false - script: | cd tests/unittests npm install npm run test displayName: 'Run Unit Tests' + continueOnError: false - script: | cd tests/nodetest npm install tsc node index.js displayName: 'Test Node' + continueOnError: false - script: | cd tests/reacttest npm install npm run build displayName: 'Test React' + continueOnError: false - script: | cd tests/moduletest npm install tsc node index.js displayName: 'Test Modules' + continueOnError: false - script: | cd tests/esmtest npm install tsc node index.js displayName: 'Test ESM Modules' + continueOnError: false - script: | cd examples npm install npm run test - displayName: 'Test Examples' \ No newline at end of file + displayName: 'Test Examples' + continueOnError: false \ No newline at end of file diff --git a/examples/misc.ts b/examples/misc.ts index 702e8e1..ccd74d6 100644 --- a/examples/misc.ts +++ b/examples/misc.ts @@ -28,7 +28,7 @@ declare global { [1, 2].all((x) => x < 2); // false // APPEND -[1, 2].append(3); // [1, 2, 3] +// [1, 2].append(3); // [1, 2, 3] // ANY [0].any(); // true @@ -113,7 +113,7 @@ const groupByBreed = cats.groupBy((cat) => cat.breed); [3, 4, 7, 0, 1].orderBy((x) => x); // [0, 1, 3, 4, 7] // PREPEND -[1, 2].prepend(3); // [3, 1, 2] +// [1, 2].prepend(3); // [3, 1, 2] // REVERSE [1, 2, 3].reverse(); // [3, 2, 1] diff --git a/examples/package.json b/examples/package.json index ab4d875..d788979 100644 --- a/examples/package.json +++ b/examples/package.json @@ -11,7 +11,7 @@ "license": "ISC", "dependencies": { "@types/node": "^18.11.18", - "linq-to-typescript": "^10.0.0-beta1" + "linq-to-typescript": "^11.0.0" }, "devDependencies": { "typescript": "^4.7.4" diff --git a/src/initializer/bindLinq.ts b/src/initializer/bindLinq.ts index cb0aa0c..4b6cf09 100644 --- a/src/initializer/bindLinq.ts +++ b/src/initializer/bindLinq.ts @@ -46,10 +46,12 @@ import { maxAsync } from "./../sync/_private/maxAsync" import { min } from "./../sync/_private/min" import { minAsync } from "./../sync/_private/minAsync" import { ofType } from "./../sync/_private/ofType" +import { order } from "./../sync/_private/order" import { orderBy } from "./../sync/_private/orderBy" import { orderByAsync } from "./../sync/_private/orderByAsync" import { orderByDescending } from "./../sync/_private/orderByDescending" import { orderByDescendingAsync } from "./../sync/_private/orderByDescendingAsync" +import { orderDescending } from "./../sync/_private/orderDescending" import { partition } from "./../sync/_private/partition" import { partitionAsync } from "./../sync/_private/partitionAsync" import { prepend } from "../sync/_private/prepend" @@ -153,10 +155,12 @@ export const bindLinq = >(object: IPrototype) => { bind(min, "min") bind(minAsync, "minAsync") bind(ofType, "ofType") + bind(order, "order") bind(orderBy, "orderBy") bind(orderByAsync, "orderByAsync") bind(orderByDescending, "orderByDescending") bind(orderByDescendingAsync, "orderByDescendingAsync") + bind(orderDescending, "orderDescending") bind(prepend, "prepend") bind(reverse, "reverse") bind(select, "select") diff --git a/src/sync/_private/order.ts b/src/sync/_private/order.ts new file mode 100644 index 0000000..885e72a --- /dev/null +++ b/src/sync/_private/order.ts @@ -0,0 +1,8 @@ +import { IComparer, IEnumerable, IOrderedEnumerable } from "../../types" +import { OrderedEnumerable } from "../OrderedEnumerable" + +export const order = ( + source: IEnumerable, + comparer?: IComparer): IOrderedEnumerable => { + return OrderedEnumerable.generate(source, (x: TSource) => x, true, comparer) +} \ No newline at end of file diff --git a/src/sync/_private/orderBy.ts b/src/sync/_private/orderBy.ts index befe6b5..aa9954c 100644 --- a/src/sync/_private/orderBy.ts +++ b/src/sync/_private/orderBy.ts @@ -1,6 +1,4 @@ -import { IComparer } from "../../types/IComparer" -import { IEnumerable } from "../../types/IEnumerable" -import { IOrderedEnumerable } from "../../types/IOrderedEnumerable" +import { IComparer, IEnumerable, IOrderedEnumerable } from "../../types" import { OrderedEnumerable } from "../OrderedEnumerable" export const orderBy = ( diff --git a/src/sync/_private/orderDescending.ts b/src/sync/_private/orderDescending.ts new file mode 100644 index 0000000..c913f35 --- /dev/null +++ b/src/sync/_private/orderDescending.ts @@ -0,0 +1,8 @@ +import { IComparer, IEnumerable, IOrderedEnumerable } from "../../types" +import { OrderedEnumerable } from "../OrderedEnumerable" + +export const orderDescending = ( + source: IEnumerable, + comparer?: IComparer): IOrderedEnumerable => { + return OrderedEnumerable.generate(source, (x: TSource) => x, false, comparer) +} \ No newline at end of file diff --git a/src/types/IEnumerable.ts b/src/types/IEnumerable.ts index 6302a2e..066ae19 100644 --- a/src/types/IEnumerable.ts +++ b/src/types/IEnumerable.ts @@ -452,6 +452,13 @@ export interface IEnumerable extends Iterable { * @returns Values that match the type string or are instance of type */ ofType(type: T): IEnumerable> + /** + * Sorts the elements of a sequence in ascending order by using a specified or default comparer. + * @param comparer An IComparer to compare values. Optional. + * @returns An IOrderedEnumerable whose elements are sorted. + */ + order( + comparer?: IComparer): IOrderedEnumerable /** * Sorts the elements of a sequence in ascending order by using a specified or default comparer. * @param keySelector A function to extract a key from an element. @@ -488,6 +495,13 @@ export interface IEnumerable extends Iterable { orderByDescendingAsync( predicate: (x: TSource) => Promise, comparer?: IComparer): IOrderedAsyncEnumerable + /** + * Sorts the elements of a sequence in descending order by using a specified or default comparer. + * @param comparer An IComparer to compare values. Optional. + * @returns An IOrderedEnumerable whose elements are sorted in descending order. + */ + orderDescending( + comparer?: IComparer): IOrderedEnumerable /** * Partitions the values into a tuple of failing and passing arrays * @param predicate Predicate to determine whether a value passes or fails