@mathigon/core
Advanced tools
Comparing version 0.6.3 to 0.6.4
@@ -529,5 +529,116 @@ 'use strict'; | ||
// ============================================================================= | ||
// Core.ts | Iterable Array Functions | ||
// (c) Mathigon | ||
// ============================================================================= | ||
function first(set) { | ||
return set[Symbol.iterator]().next().value; | ||
} | ||
function every(set, callback) { | ||
for (const s of set) { | ||
if (!callback(s)) | ||
return false; | ||
} | ||
return true; | ||
} | ||
function some(set, callback) { | ||
for (const s of set) { | ||
if (callback(s)) | ||
return true; | ||
} | ||
return false; | ||
} | ||
class Itarray { | ||
constructor(...values) { | ||
this.values = values; | ||
} | ||
map(fn) { | ||
const values = this.values; | ||
return new Itarray((function* () { | ||
let i = 0; | ||
for (const row of values) { | ||
for (const v of row) { | ||
yield fn(v, i); | ||
i += 1; | ||
} | ||
} | ||
})()); | ||
} | ||
every(fn) { | ||
let i = 0; | ||
for (const row of this.values) { | ||
for (const v of row) { | ||
if (!fn(v, i)) | ||
return false; | ||
i += 1; | ||
} | ||
} | ||
return true; | ||
} | ||
some(fn) { | ||
let i = 0; | ||
for (const row of this.values) { | ||
for (const v of row) { | ||
if (fn(v, i)) | ||
return true; | ||
i += 1; | ||
} | ||
} | ||
return false; | ||
} | ||
slice(from, to) { | ||
const values = this.values; | ||
return new Itarray((function* () { | ||
let i = 0; | ||
for (const row of values) { | ||
for (const v of row) { | ||
if (i < from || (to !== undefined && i > from + to)) | ||
continue; | ||
yield v; | ||
i += 1; | ||
} | ||
} | ||
})()); | ||
} | ||
filter(fn) { | ||
const values = this.values; | ||
return new Itarray((function* () { | ||
let i = 0; | ||
for (const row of values) { | ||
for (const v of row) { | ||
if (fn(v, i)) | ||
yield v; | ||
i += 1; | ||
} | ||
} | ||
})()); | ||
} | ||
concat(newValues) { | ||
this.values.push(newValues); | ||
} | ||
[Symbol.iterator]() { | ||
const values = this.values; | ||
return (function* () { | ||
for (const row of values) { | ||
for (const v of row) { | ||
yield v; | ||
} | ||
} | ||
})(); | ||
} | ||
static make(fn, max) { | ||
return new Itarray((function* () { | ||
let i = 0; | ||
while (max === undefined || i < max) { | ||
yield fn(i); | ||
i += 1; | ||
} | ||
})()); | ||
} | ||
} | ||
exports.Cache = Cache; | ||
exports.Color = Color; | ||
exports.EventTarget = EventTarget; | ||
exports.Itarray = Itarray; | ||
exports.applyDefaults = applyDefaults; | ||
@@ -542,2 +653,4 @@ exports.autoCorrect = autoCorrect; | ||
exports.difference = difference; | ||
exports.every = every; | ||
exports.first = first; | ||
exports.flatten = flatten; | ||
@@ -556,2 +669,3 @@ exports.intersect = intersect; | ||
exports.safeToJSON = safeToJSON; | ||
exports.some = some; | ||
exports.sortBy = sortBy; | ||
@@ -558,0 +672,0 @@ exports.stringDistance = stringDistance; |
@@ -525,2 +525,112 @@ // ============================================================================= | ||
export { Cache, Color, EventTarget, applyDefaults, autoCorrect, cache, chunk, cumulative, deepExtend, defer, delay, difference, flatten, intersect, isOneOf, isPalindrome, join, last, list, loop, repeat, repeat2D, rotate, run, safeToJSON, sortBy, stringDistance, tabulate, tabulate2D, throttle, toCamelCase, toLinkedList, toTitleCase, total, uid, unique, wait, words }; | ||
// ============================================================================= | ||
// Core.ts | Iterable Array Functions | ||
// (c) Mathigon | ||
// ============================================================================= | ||
function first(set) { | ||
return set[Symbol.iterator]().next().value; | ||
} | ||
function every(set, callback) { | ||
for (const s of set) { | ||
if (!callback(s)) | ||
return false; | ||
} | ||
return true; | ||
} | ||
function some(set, callback) { | ||
for (const s of set) { | ||
if (callback(s)) | ||
return true; | ||
} | ||
return false; | ||
} | ||
class Itarray { | ||
constructor(...values) { | ||
this.values = values; | ||
} | ||
map(fn) { | ||
const values = this.values; | ||
return new Itarray((function* () { | ||
let i = 0; | ||
for (const row of values) { | ||
for (const v of row) { | ||
yield fn(v, i); | ||
i += 1; | ||
} | ||
} | ||
})()); | ||
} | ||
every(fn) { | ||
let i = 0; | ||
for (const row of this.values) { | ||
for (const v of row) { | ||
if (!fn(v, i)) | ||
return false; | ||
i += 1; | ||
} | ||
} | ||
return true; | ||
} | ||
some(fn) { | ||
let i = 0; | ||
for (const row of this.values) { | ||
for (const v of row) { | ||
if (fn(v, i)) | ||
return true; | ||
i += 1; | ||
} | ||
} | ||
return false; | ||
} | ||
slice(from, to) { | ||
const values = this.values; | ||
return new Itarray((function* () { | ||
let i = 0; | ||
for (const row of values) { | ||
for (const v of row) { | ||
if (i < from || (to !== undefined && i > from + to)) | ||
continue; | ||
yield v; | ||
i += 1; | ||
} | ||
} | ||
})()); | ||
} | ||
filter(fn) { | ||
const values = this.values; | ||
return new Itarray((function* () { | ||
let i = 0; | ||
for (const row of values) { | ||
for (const v of row) { | ||
if (fn(v, i)) | ||
yield v; | ||
i += 1; | ||
} | ||
} | ||
})()); | ||
} | ||
concat(newValues) { | ||
this.values.push(newValues); | ||
} | ||
[Symbol.iterator]() { | ||
const values = this.values; | ||
return (function* () { | ||
for (const row of values) { | ||
for (const v of row) { | ||
yield v; | ||
} | ||
} | ||
})(); | ||
} | ||
static make(fn, max) { | ||
return new Itarray((function* () { | ||
let i = 0; | ||
while (max === undefined || i < max) { | ||
yield fn(i); | ||
i += 1; | ||
} | ||
})()); | ||
} | ||
} | ||
export { Cache, Color, EventTarget, Itarray, applyDefaults, autoCorrect, cache, chunk, cumulative, deepExtend, defer, delay, difference, every, first, flatten, intersect, isOneOf, isPalindrome, join, last, list, loop, repeat, repeat2D, rotate, run, safeToJSON, some, sortBy, stringDistance, tabulate, tabulate2D, throttle, toCamelCase, toLinkedList, toTitleCase, total, uid, unique, wait, words }; |
@@ -13,1 +13,2 @@ // ============================================================================= | ||
export * from './src/cache'; | ||
export * from './src/iterable'; |
{ | ||
"name": "@mathigon/core", | ||
"version": "0.6.3", | ||
"version": "0.6.4", | ||
"description": "TypeScript utilities library containing function wrappers, string and array helper functions, event classes and color utilities.", | ||
@@ -30,15 +30,15 @@ "keywords": [ | ||
"devDependencies": { | ||
"@rollup/plugin-typescript": "8.0.0", | ||
"@rollup/plugin-typescript": "8.1.1", | ||
"@types/tape": "4.13.0", | ||
"@typescript-eslint/eslint-plugin": "4.9.0", | ||
"@typescript-eslint/parser": "4.9.0", | ||
"eslint": "7.14.0", | ||
"@typescript-eslint/eslint-plugin": "4.14.1", | ||
"@typescript-eslint/parser": "4.14.1", | ||
"eslint": "7.19.0", | ||
"eslint-config-google": "0.14.0", | ||
"eslint-plugin-import": "2.22.1", | ||
"rollup": "2.34.0", | ||
"tape": "5.0.1", | ||
"ts-node": "9.0.0", | ||
"tslib": "2.0.3", | ||
"typescript": "4.1.2" | ||
"rollup": "2.38.2", | ||
"tape": "5.1.1", | ||
"ts-node": "9.1.1", | ||
"tslib": "2.1.0", | ||
"typescript": "4.1.3" | ||
} | ||
} |
# Core.ts | ||
[![Build Status](https://travis-ci.org/mathigon/core.js.svg?branch=master)](https://travis-ci.org/mathigon/core.js) | ||
[![Build Status](https://github.com/mathigon/core.js/workflows/CI%20Tests/badge.svg)](https://github.com/mathigon/core.js/actions?query=workflow%3A%22CI+Tests%22) | ||
[![npm](https://img.shields.io/npm/v/@mathigon/core.svg)](https://www.npmjs.com/package/@mathigon/core) | ||
@@ -5,0 +5,0 @@ [![npm](https://img.shields.io/github/license/mathigon/core.js.svg)](https://github.com/mathigon/core.js/blob/master/LICENSE) |
@@ -8,3 +8,3 @@ // ============================================================================= | ||
import * as tape from 'tape'; | ||
import {Itarray} from '../src/itarray'; | ||
import {Itarray} from '../src/iterable'; | ||
@@ -11,0 +11,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72900
2112
2
1
2426