@jymfony/util
Advanced tools
Comparing version 0.1.0-alpha.18 to 0.1.0-alpha.19
@@ -37,2 +37,3 @@ require('./lib/Error/trigger_deprecated'); | ||
require('./lib/String/sprintf'); | ||
require('./lib/String/str_pad'); | ||
require('./lib/String/strcspn'); | ||
@@ -39,0 +40,0 @@ require('./lib/String/strip_tags'); |
@@ -86,3 +86,3 @@ const asyncHook = require('async_hooks'); | ||
* | ||
* @param {Jymfony.Component.HttpServer.Event.GetResponseEvent} event | ||
* @param {Jymfony.Contracts.HttpServer.Event.RequestEvent} event | ||
* | ||
@@ -102,3 +102,3 @@ * @private | ||
* | ||
* @param {Jymfony.Component.HttpServer.Event.FinishRequestEvent} event | ||
* @param {Jymfony.Contracts.HttpServer.Event.FinishRequestEvent} event | ||
* | ||
@@ -110,2 +110,3 @@ * @private | ||
const context = this._requestContexts.get(request); | ||
this._requestContexts.delete(request); | ||
@@ -112,0 +113,0 @@ if (this._activeContext === context) { |
@@ -24,3 +24,3 @@ 'use strict'; | ||
* | ||
* @param {[string, string]} arg | ||
* @param {[object, string]} arg | ||
* | ||
@@ -27,0 +27,0 @@ * @returns {BoundFunction} |
@@ -30,2 +30,19 @@ global.isArray = Array.isArray; | ||
*/ | ||
global.isNumeric = function isNumeric(value) { | ||
if (! isScalar(value)) { | ||
return false; | ||
} | ||
if (isNumber(value)) { | ||
return true; | ||
} | ||
return !! String(value).match(/^[+-]?((\d+|\.\d+|\d+\.\d+)(e[+-]?\d+)?|0x[0-9a-f_]+)$/i); | ||
}; | ||
/** | ||
* @param {*} value | ||
* | ||
* @returns {boolean} | ||
*/ | ||
global.isScalar = function isScalar(value) { | ||
@@ -65,3 +82,3 @@ if (undefined === value || null === value) { | ||
global.isPromise = function isPromise(value) { | ||
return isFunction(value.then); | ||
return 'object' === typeof value && isFunction(value.then); | ||
}; | ||
@@ -68,0 +85,0 @@ |
@@ -57,3 +57,7 @@ global.isGenerator = function isGenerator(value) { | ||
return 'AsyncFunction' === (constructor.name || constructor.displayName); | ||
if ('AsyncFunction' === (constructor.name || constructor.displayName)) { | ||
return true; | ||
} | ||
return '[object AsyncFunction]' === Object.prototype.toString.call(value); | ||
}; | ||
@@ -60,0 +64,0 @@ } else { |
@@ -27,2 +27,3 @@ const Mixins = require('./Mixins/Mixins'); | ||
getInterfaces: (Class) => Class[Mixins.appliedInterfacesSymbol] || [], | ||
getTraits: (Class) => Class[Mixins.appliedTraitsSymbol] || [], | ||
@@ -43,4 +44,10 @@ /** | ||
superclass = superclass || __jymfony.JObject || class {}; | ||
superclass = mixins.reduce((a, b) => b(a), superclass); | ||
superclass = mixins.reduce((a, b) => { | ||
if (! isFunction(b)) { | ||
throw new LogicException(__jymfony.sprintf('Cannot implement/use %s as interface/trait. You probably passed a broken reference to mix/implementationOf.', typeof b)); | ||
} | ||
return b(a); | ||
}, superclass); | ||
const interfaces = Array.from((function * () { | ||
@@ -64,2 +71,20 @@ for (const i of mixins) { | ||
const traits = Array.from((function * () { | ||
for (const i of mixins) { | ||
if (! Traits.isTrait(i)) { | ||
continue; | ||
} | ||
let definition = i.definition; | ||
while (definition) { | ||
const outer = Mixins.getMixin(definition); | ||
if (outer) { | ||
yield outer; | ||
} | ||
definition = Object.getPrototypeOf(definition); | ||
} | ||
} | ||
})()).concat(...(superclass[Mixins.appliedTraitsSymbol] || [])); | ||
const mixed = (s => { | ||
@@ -80,2 +105,7 @@ return class extends s {}; | ||
Object.defineProperty(mixed, Mixins.appliedTraitsSymbol, { | ||
value: [ ...traits ], | ||
enumerable: false, | ||
}); | ||
Object.defineProperty(mixed, Symbol.for('_jymfony_mixin'), { | ||
@@ -82,0 +112,0 @@ value: mixed, |
@@ -5,2 +5,3 @@ const FunctionProps = Object.getOwnPropertyNames(Function.prototype); | ||
const symAppliedInterfaces = Symbol('appliedInterfaces'); | ||
const symAppliedTraits = Symbol('appliedTraits'); | ||
const symClassType = Symbol('classType'); | ||
@@ -175,2 +176,3 @@ const symInitalizer = Symbol('Initializer'); | ||
Mixins.appliedInterfacesSymbol = symAppliedInterfaces; | ||
Mixins.appliedTraitsSymbol = symAppliedTraits; | ||
Mixins.classTypeSymbol = symClassType; | ||
@@ -177,0 +179,0 @@ Mixins.initializerSymbol = symInitalizer; |
@@ -14,2 +14,6 @@ 'use strict'; | ||
__jymfony.getEntries = function * getEntries(object) { | ||
if (object instanceof Set) { | ||
object = [ ...object.values() ]; | ||
} | ||
if (isArray(object)) { | ||
@@ -16,0 +20,0 @@ for (const k of object.keys()) { |
@@ -9,2 +9,3 @@ global.__jymfony = global.__jymfony || {}; | ||
let _privateFields = undefined; | ||
let _privateMethods = undefined; | ||
@@ -162,4 +163,29 @@ /** | ||
} | ||
/** | ||
* Checks if this node version has private instance methods support. | ||
* | ||
* @returns {boolean} | ||
*/ | ||
static hasPrivateMethodsSupport() { | ||
if (undefined === _privateMethods) { | ||
_privateMethods = false; | ||
try { | ||
let c; | ||
eval('c = class ev { #field() { return "foobar"; } get field() { return this.#field(); } }'); | ||
const i = new c(); | ||
return _privateMethods = 'foobar' === i.field; | ||
} catch (e) { | ||
if (!(e instanceof SyntaxError)) { | ||
throw e; | ||
} | ||
} | ||
} | ||
return _privateMethods; | ||
} | ||
} | ||
__jymfony.Platform = Platform; |
@@ -17,4 +17,4 @@ 'use strict'; | ||
const names = []; | ||
const sanitized = pattern.toString() | ||
.replace(/\(\?<(\w+)>/g, (_, name) => { | ||
const sanitized = String(pattern) | ||
.replace(/\(\?<(\w+)?>|\((?!\?[:!=<])/g, (_, name) => { | ||
names.push(name); | ||
@@ -70,3 +70,6 @@ return '('; | ||
for (let i = 1; i <= this._names.length; i++) { | ||
groups[this._names[i - 1]] = result[i]; | ||
const name = this._names[i - 1]; | ||
if (undefined !== name) { | ||
groups[name] = result[i]; | ||
} | ||
} | ||
@@ -73,0 +76,0 @@ |
@@ -1,2 +0,1 @@ | ||
// Replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') | ||
'use strict'; | ||
@@ -3,0 +2,0 @@ |
@@ -16,3 +16,3 @@ 'use strict'; | ||
* | ||
* @returns {boolean} | ||
* @returns {int|boolean} | ||
*/ | ||
@@ -27,4 +27,4 @@ __jymfony.version_compare = (version1, version2, operator = undefined) => { | ||
version1 = prepareVersion(version1); | ||
version2 = prepareVersion(version2); | ||
const v1 = prepareVersion(version1); | ||
const v2 = prepareVersion(version2); | ||
@@ -55,6 +55,6 @@ // Then it compares the parts starting from left to right. If a part contains special version | ||
let compare = 0; | ||
const maxI = Math.max(version1.length, version2.length); | ||
const maxI = Math.max(v1.length, v2.length); | ||
for (let i = 0; i < maxI; i++) { | ||
const chunk1 = numVer(version1[i]); | ||
const chunk2 = numVer(version2[i]); | ||
const chunk1 = numVer(v1[i]); | ||
const chunk2 = numVer(v2[i]); | ||
@@ -61,0 +61,0 @@ if (chunk1 === chunk2) { |
{ | ||
"name": "@jymfony/util", | ||
"version": "0.1.0-alpha.18", | ||
"version": "0.1.0-alpha.19", | ||
"description": "Jymfony util functions", | ||
@@ -20,3 +20,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"@jymfony/exceptions": "0.1.0-alpha.18" | ||
"@jymfony/exceptions": "0.1.0-alpha.19" | ||
}, | ||
@@ -23,0 +23,0 @@ "devDependencies": { |
@@ -52,3 +52,3 @@ /// <reference lib="esnext" /> | ||
*/ | ||
export function clone(object: Object): Object; | ||
export function clone<T extends object = any>(object: T): T; | ||
@@ -73,3 +73,3 @@ /** | ||
*/ | ||
export function getEntries<V>(object: V[]): IterableIterator<[number, V]>; | ||
export function getEntries<V>(object: V[]|Set<V>): IterableIterator<[number, V]>; | ||
export function getEntries<T, K extends keyof T>(object: T): IterableIterator<[K, T[K]]>; | ||
@@ -159,3 +159,12 @@ | ||
export const STR_PAD_RIGHT = 'STR_PAD_RIGHT'; | ||
export const STR_PAD_LEFT = 'STR_PAD_LEFT'; | ||
export const STR_PAD_BOTH = 'STR_PAD_BOTH'; | ||
/** | ||
* Pad a string to a certain length with another string. | ||
*/ | ||
export function str_pad(string: string, length?: number, pad?: string, padType?: 'STR_PAD_RIGHT' | 'STR_PAD_LEFT' | 'STR_PAD_BOTH') | ||
/** | ||
* The strcspn() function returns the number of characters (including whitespaces) | ||
@@ -214,3 +223,4 @@ * found in a string before any part of the specified characters are found. | ||
*/ | ||
export function version_compare(version1: string|number, version2: string|number, operator?: string|undefined): boolean|number; | ||
export function version_compare(version1: string|number, version2: string|number): number; | ||
export function version_compare(version1: string|number, version2: string|number, operator: '<'|'lt'|'<='|'le'|'>'|'gt'|'>='|'ge'|'=='|'='|'eq'|'!='|'<>'|'ne'): boolean; | ||
@@ -227,3 +237,3 @@ /** | ||
} | ||
declare type Constructor<T = any> = Function & { prototype: T }; | ||
declare type Constructor<T = any> = { prototype: T }; | ||
@@ -238,4 +248,40 @@ declare class MixinInterface { | ||
declare type AsyncFunction = (...args: any[]) => Promise<any>; | ||
declare type AsyncGeneratorFunction = (...args: any[]) => AsyncIterator<any>; | ||
interface AsyncGenerator<T = unknown, TReturn = any, TNext = unknown> extends AsyncIterator<T, TReturn, TNext> { | ||
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places. | ||
next(...args: [] | [TNext]): Promise<IteratorResult<T, TReturn>>; | ||
return(value: TReturn | PromiseLike<TReturn>): Promise<IteratorResult<T, TReturn>>; | ||
throw(e: any): Promise<IteratorResult<T, TReturn>>; | ||
[Symbol.asyncIterator](): AsyncGenerator<T, TReturn, TNext>; | ||
} | ||
interface AsyncGeneratorFunction { | ||
/** | ||
* Creates a new AsyncGenerator object. | ||
* @param args A list of arguments the function accepts. | ||
*/ | ||
new (...args: any[]): AsyncGenerator; | ||
/** | ||
* Creates a new AsyncGenerator object. | ||
* @param args A list of arguments the function accepts. | ||
*/ | ||
(...args: any[]): AsyncGenerator; | ||
/** | ||
* The length of the arguments. | ||
*/ | ||
readonly length: number; | ||
/** | ||
* Returns the name of the function. | ||
*/ | ||
readonly name: string; | ||
/** | ||
* A reference to the prototype. | ||
*/ | ||
readonly prototype: AsyncGenerator; | ||
} | ||
declare module NodeJS { | ||
@@ -253,2 +299,3 @@ interface Global { | ||
getInterfaces: <T extends Newable<any>>(Class: T) => MixinInterface[], | ||
getTraits: <T extends Newable<any>>(Class: T) => MixinInterface[], | ||
@@ -304,2 +351,3 @@ /** | ||
isNumber(value: any): value is number; | ||
isNumeric(value: any): boolean; | ||
isDate(value: any): value is Date; | ||
@@ -327,6 +375,10 @@ isRegExp(value: any): value is RegExp; | ||
isCallableArray(value: any): value is [string, string]; | ||
getCallableFromArray(value: [string, string]): Invokable<any>; | ||
getCallableFromArray(value: [object, string]): Invokable<any>; | ||
} | ||
} | ||
interface Function { | ||
(...args: any[]): any; | ||
} | ||
declare type Invokable<T = any> = (...args: any[]) => T | { | ||
@@ -384,2 +436,3 @@ __invoke<A extends any[]>(...args: A): (...args: A) => T; | ||
declare function isNumber(value: any): value is number; | ||
declare function isNumeric(value: any): boolean; | ||
declare function isDate(value: any): value is Date; | ||
@@ -406,3 +459,3 @@ declare function isRegExp(value: any): value is RegExp; | ||
declare function isCallableArray(value: any): value is [string, string]; | ||
declare function getCallableFromArray(value: [string, string]): Invokable<any>; | ||
declare function getCallableFromArray(value: [object, string]): Invokable<any>; | ||
@@ -409,0 +462,0 @@ declare class BoundFunction implements Function { |
declare namespace __jymfony { | ||
import ConsoleCommandEvent = Jymfony.Component.Console.Event.ConsoleCommandEvent; | ||
import GetResponseEvent = Jymfony.Component.HttpServer.Event.GetResponseEvent; | ||
import FinishRequestEvent = Jymfony.Component.HttpServer.Event.FinishRequestEvent; | ||
import ConsoleCommandEvent = Jymfony.Contracts.Console.Event.ConsoleCommandEvent; | ||
import FinishRequestEvent = Jymfony.Contracts.HttpServer.Event.FinishRequestEvent; | ||
import RequestEvent = Jymfony.Contracts.HttpServer.Event.RequestEvent; | ||
@@ -31,3 +31,3 @@ export class ClsTrait implements MixinInterface { | ||
*/ | ||
private _onHttpRequest(event: GetResponseEvent): void; | ||
private _onHttpRequest(event: RequestEvent): void; | ||
@@ -34,0 +34,0 @@ /** |
@@ -29,3 +29,3 @@ declare namespace __jymfony { | ||
*/ | ||
runExclusive<T = any>(callback: Invokable<T>): Promise<T>; | ||
runExclusive<T = any>(callback: Invokable<T | Promise<T>>): Promise<T>; | ||
@@ -32,0 +32,0 @@ /** |
@@ -27,3 +27,18 @@ declare namespace __jymfony { | ||
static hasModernRegex(): boolean; | ||
/** | ||
* Checks if this node version has public instance fields support. | ||
*/ | ||
static hasPublicFieldSupport(): boolean; | ||
/** | ||
* Checks if this node version has private instance fields support. | ||
*/ | ||
static hasPrivateFieldSupport(): boolean; | ||
/** | ||
* Checks if this node version has private instance fields support. | ||
*/ | ||
static hasPrivateMethodsSupport(): boolean; | ||
} | ||
} |
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
0
133631
63
3891
+ Added@jymfony/exceptions@0.1.0-alpha.19(transitive)
- Removed@jymfony/exceptions@0.1.0-alpha.18(transitive)