atma-utils
Advanced tools
Comparing version 0.2.53 to 0.2.56
@@ -16,2 +16,3 @@ // Generated by dts-bundle v0.7.3 | ||
export * from 'atma-utils/error'; | ||
export * from 'atma-utils/promisify'; | ||
export * from 'atma-utils/class/Dfr'; | ||
@@ -30,5 +31,5 @@ export * from 'atma-utils/class/EventEmitter'; | ||
export const _Array_indexOf: (searchElement: any, fromIndex?: number) => number; | ||
export const _Object_hasOwnProp: (v: string | number | symbol) => boolean; | ||
export const _Object_getOwnProp: (o: any, p: string | number | symbol) => PropertyDescriptor; | ||
export const _Object_defineProperty: (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType<any>) => any; | ||
export const _Object_hasOwnProp: (v: PropertyKey) => boolean; | ||
export const _Object_getOwnProp: (o: any, p: PropertyKey) => PropertyDescriptor; | ||
export const _Object_defineProperty: <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T; | ||
export let _global: any; | ||
@@ -169,2 +170,9 @@ export let _document: any; | ||
declare module 'atma-utils/promisify' { | ||
import { type class_EventEmitter } from 'atma-utils/class/EventEmitter'; | ||
export namespace promisify { | ||
function fromEvent<TEvents extends Record<keyof TEvents, (...args: any) => any> = any>(ctx: class_EventEmitter<TEvents>, event: keyof TEvents, handlerFn?: () => any | Promise<any>): Promise<unknown>; | ||
} | ||
} | ||
declare module 'atma-utils/class/Dfr' { | ||
@@ -210,3 +218,6 @@ export class class_Dfr<T = any> implements PromiseLike<T> { | ||
once<TKey extends keyof TEvents>(event: TKey, fn: TEvents[TKey]): this; | ||
pipe<TKey extends keyof TEvents>(event: TKey): () => void; | ||
/** | ||
* Returns a function, which when called - triggers the event with the arguments passed to that function | ||
*/ | ||
pipe<TKey extends keyof TEvents>(event: TKey): (...args: Parameters<TEvents[TKey]>) => void; | ||
emit<TKey extends keyof TEvents>(event: TKey, ...args: Parameters<TEvents[TKey]>): this; | ||
@@ -213,0 +224,0 @@ trigger<TKey extends keyof TEvents>(event: TKey, ...args: Parameters<TEvents[TKey]>): this; |
@@ -788,2 +788,73 @@ var _Array_slice, | ||
}()); | ||
var promisify; | ||
(function(){ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
; | ||
(function (promisify) { | ||
function fromEvent(ctx, event, handlerFn) { | ||
return new Promise(function (resolve, reject) { | ||
var _this = this; | ||
var cb = handlerFn == null | ||
? resolve | ||
: function () { return __awaiter(_this, void 0, void 0, function () { | ||
var r, error_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, handlerFn()]; | ||
case 1: | ||
r = _a.sent(); | ||
resolve(r); | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
error_1 = _a.sent(); | ||
reject(error_1); | ||
return [3 /*break*/, 3]; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
ctx.once(event, cb); | ||
}); | ||
} | ||
promisify.fromEvent = fromEvent; | ||
})(promisify || (promisify = {})); | ||
}()); | ||
var class_Dfr; | ||
@@ -1020,8 +1091,10 @@ (function(){ | ||
(function(){ | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
@@ -1045,8 +1118,13 @@ class_EventEmitter = /** @class */ (function () { | ||
}; | ||
/** | ||
* Returns a function, which when called - triggers the event with the arguments passed to that function | ||
*/ | ||
class_EventEmitter.prototype.pipe = function (event) { | ||
var that = this, args; | ||
var _this = this; | ||
return function () { | ||
args = _Array_slice.call(arguments); | ||
args.unshift(event); | ||
fn_apply(that.trigger, that, args); | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
_this.emit.apply(_this, __spreadArray([event], args, false)); | ||
}; | ||
@@ -1083,3 +1161,3 @@ }; | ||
} | ||
return this.emit.apply(this, __spreadArrays([event], args)); | ||
return this.emit.apply(this, __spreadArray([event], args, false)); | ||
}; | ||
@@ -1378,3 +1456,3 @@ class_EventEmitter.prototype.off = function (event, fn) { | ||
} | ||
return start !== 0 && end !== length - 1 | ||
return start !== 0 && end !== this.length - 1 | ||
? this.substring(start, end + 1) | ||
@@ -1381,0 +1459,0 @@ : this; |
106
lib/utils.js
@@ -25,5 +25,2 @@ (function(factory){ | ||
_Object_getOwnProp, | ||
_Object_defineProperty, | ||
_Array_slice, | ||
_Object_getOwnProp, | ||
_Object_defineProperty; | ||
@@ -1213,8 +1210,10 @@ var is_Function, | ||
(function(){ | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
@@ -1238,8 +1237,13 @@ class_EventEmitter = /** @class */ (function () { | ||
}; | ||
/** | ||
* Returns a function, which when called - triggers the event with the arguments passed to that function | ||
*/ | ||
class_EventEmitter.prototype.pipe = function (event) { | ||
var that = this, args; | ||
var _this = this; | ||
return function () { | ||
args = _Array_slice.call(arguments); | ||
args.unshift(event); | ||
fn_apply(that.trigger, that, args); | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
_this.emit.apply(_this, __spreadArray([event], args, false)); | ||
}; | ||
@@ -1276,3 +1280,3 @@ }; | ||
} | ||
return this.emit.apply(this, __spreadArrays([event], args)); | ||
return this.emit.apply(this, __spreadArray([event], args, false)); | ||
}; | ||
@@ -1578,2 +1582,73 @@ class_EventEmitter.prototype.off = function (event, fn) { | ||
}()); | ||
var promisify; | ||
(function(){ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
; | ||
(function (promisify) { | ||
function fromEvent(ctx, event, handlerFn) { | ||
return new Promise(function (resolve, reject) { | ||
var _this = this; | ||
var cb = handlerFn == null | ||
? resolve | ||
: function () { return __awaiter(_this, void 0, void 0, function () { | ||
var r, error_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, handlerFn()]; | ||
case 1: | ||
r = _a.sent(); | ||
resolve(r); | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
error_1 = _a.sent(); | ||
reject(error_1); | ||
return [3 /*break*/, 3]; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
ctx.once(event, cb); | ||
}); | ||
} | ||
promisify.fromEvent = fromEvent; | ||
})(promisify || (promisify = {})); | ||
}()); | ||
var Lib = { | ||
@@ -1616,3 +1691,4 @@ class_Dfr: class_Dfr, | ||
str_dedent: str_dedent, | ||
mixin: mixin | ||
mixin: mixin, | ||
promisify: promisify | ||
}; | ||
@@ -1619,0 +1695,0 @@ |
{ | ||
"name": "atma-utils", | ||
"description": "Helpers", | ||
"version": "0.2.53", | ||
"author": "Alexander Kit <alex.kit@atmajs.com>", | ||
"version": "0.2.56", | ||
"author": "Alex Kit <alex.kit@atmajs.com>", | ||
"repository": { | ||
@@ -19,2 +19,3 @@ "type": "git", | ||
"devDependencies": { | ||
"@types/node": "^17.0.8", | ||
"app-bundler": "^0.0.94", | ||
@@ -24,3 +25,3 @@ "atma": "^0.12.28", | ||
"atma-loader-babel": ">0.0.0", | ||
"atma-loader-ts": "^1.1.12", | ||
"atma-loader-ts": "^1.1.16", | ||
"dts-bundle": "^0.7.3" | ||
@@ -27,0 +28,0 @@ }, |
Util Functions | ||
---- | ||
[![Build Status](https://travis-ci.org/atmajs/utils.png?branch=master)](https://travis-ci.org/atmajs/utils) | ||
[![Build Status](https://app.travis-ci.com/atmajs/utils.svg?branch=master)](https://app.travis-ci.com/github/atmajs/utils) | ||
#### Embeddable | ||
- `lib/utils.embed.js` All functions are in the top-level scope. | ||
#### Module | ||
- All functions are wrapped to an object, e.g. `require('atma-utils').obj_getProperty` | ||
- All functions are wrapped to an object, e.g. `require('atma-utils').obj_getProperty` or `import { obj_getProperty } from 'atma-utils'` | ||
## Functions | ||
- Object | ||
- `obj_getProperty(obj, path)` | ||
- `obj_setProperty(obj, path, val)` | ||
- `obj_extend(a, b)` | ||
- `obj_extendMany(a, [ ...args])` | ||
- `obj_create(obj)` | ||
- `obj_getProperty(obj, path)` | ||
- `obj_setProperty(obj, path, val)` | ||
- `obj_extend(a, b)` | ||
- `obj_extendMany(a, [ ...args])` | ||
- `obj_create(obj)` | ||
- Array | ||
- `arr_remove` | ||
- `arr_remove` | ||
- Function | ||
- `fn_proxy(fn, ctx)` | ||
- `fn_doNothing` | ||
- `fn_proxy(fn, ctx)` | ||
- `fn_doNothing` | ||
- is | ||
- `is_Function(x)` | ||
- `is_String(x)` | ||
- `is_notEmptyString(x)` | ||
- `is_Array(x)` | ||
- `is_ArrayLike(x)` | ||
- `is_Object(x)` | ||
- `is_rawObject(x)` | ||
- `is_Function(x)` | ||
- `is_String(x)` | ||
- `is_notEmptyString(x)` | ||
- `is_Array(x)` | ||
- `is_ArrayLike(x)` | ||
- `is_Object(x)` | ||
- `is_rawObject(x)` | ||
- class | ||
- `class_create([...Base:Function|Object], Proto:Object)` | ||
- `class_create([...Base:Function|Object], Proto:Object)` | ||
```javascript | ||
Proto := Object { | ||
constructor: Function, | ||
... | ||
} | ||
``` | ||
```javascript | ||
Proto := Object { | ||
constructor: Function, | ||
... | ||
} | ||
``` | ||
- `class_createEx` | ||
- `class_createEx` | ||
Similar to `class_create` but also handles the property accessors. The `class_create` is in this way much more simple and has better performance. | ||
Similar to `class_create` but also handles the property accessors. The `class_create` is in this way much more simple and has better performance. | ||
- `class_Dfr` | ||
- `class_Dfr` | ||
Promise | ||
Promise | ||
- `class_EventEmitter` | ||
- `class_EventEmitter` | ||
Event Emitter | ||
Event Emitter | ||
- error | ||
- `error_createClass(name:String, Proto:Object):Function` | ||
- `error_formatSource(source:String, index:Number, ?filename:String):String` | ||
- `error_cursor(source:String, index:Number):Array<lines, lineNum, rowNum>` | ||
- `error_formatCursor(lines:Array, lineNum: Number, rowNum: Number):String` | ||
- `error_createClass(name:String, Proto:Object):Function` | ||
- `error_formatSource(source:String, index:Number, ?filename:String):String` | ||
- `error_cursor(source:String, index:Number):Array<lines, lineNum, rowNum>` | ||
- `error_formatCursor(lines:Array, lineNum: Number, rowNum: Number):String` | ||
- Prototype fn references | ||
- `_Array_slice` | ||
- `_Array_splice` | ||
- `_Array_indexOf` | ||
- `_Obj_hasOwnProp_` | ||
- `_Array_slice` | ||
- `_Array_splice` | ||
- `_Array_indexOf` | ||
- `_Obj_hasOwnProp_` | ||
@@ -84,4 +85,4 @@ | ||
- Push/Pulblish: | ||
- to `git` | ||
- to `npm` | ||
- to `git` | ||
- to `npm` | ||
@@ -93,3 +94,3 @@ ```bash | ||
# Test | ||
# Test | ||
@@ -105,2 +106,2 @@ ```bash | ||
:copyright: 2015 - MIT - Atma.js | ||
:copyright: 2021 - MIT - Atma.js |
{ | ||
"files": [ | ||
"src/export-all.ts" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
], | ||
"compilerOptions": { | ||
"outDir": "ts-temp", | ||
"typeRoots": [ | ||
"./node_modules/@types", | ||
"./typings/" | ||
], | ||
"types": [ | ||
"node" | ||
], | ||
"declaration": true, | ||
"target":"es5", | ||
"module": "commonjs", | ||
"sourceMap": false, | ||
"experimentalDecorators": true | ||
} | ||
"src/export-all.ts" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
], | ||
"compilerOptions": { | ||
"outDir": "ts-temp", | ||
"typeRoots": [ | ||
"./node_modules/@types", | ||
"./typings/" | ||
], | ||
"types": [ | ||
"node" | ||
], | ||
"declaration": true, | ||
"target":"es5", | ||
"lib": ["ES2015"], | ||
"module": "commonjs", | ||
"sourceMap": false, | ||
"experimentalDecorators": true | ||
} | ||
} |
{ | ||
"compilerOptions": { | ||
"target":"es5", | ||
"lib": ["ES2015"], | ||
"module": "amd" | ||
} | ||
} |
213660
6500
105
7