Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

breakpoint-changes-rx

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

breakpoint-changes-rx - npm Package Compare versions

Comparing version 3.0.3 to 3.1.0

70

dist/breakpoints.d.ts
import { Observable, BehaviorSubject } from 'rxjs';
export interface BreakpointDefinition {
[key: string]: string | number | undefined;
min?: string | number;

@@ -8,7 +7,2 @@ max?: string | number;

export type BreakpointDefinitions = Record<string, BreakpointDefinition>;
export interface BreakpointState {
curr: string[];
prev: string[];
}
type BreakpointMinMaxDetector = (val: string) => boolean;
export interface BreakpointParseConfig {

@@ -18,20 +12,50 @@ regex?: RegExp;

groupMinMax?: number;
isMin?: BreakpointMinMaxDetector;
isMin: (val: string) => boolean;
}
type GetCurrentBreakpointsFnc = () => string[];
type IncludesBreakpointsFnc = (bps: string[]) => boolean;
type IncludesBreakpointFnc = (bp: string) => boolean;
type BreakpointsChangeFnc = (bp: string) => Observable<boolean>;
type BreakpointsInRangeFnc = (range: string[]) => Observable<boolean>;
interface BreakpointFncs {
breakpointsChanges$: Observable<BreakpointState>;
breakpointsChangesBehavior$: BehaviorSubject<BreakpointState>;
getCurrentBreakpoints: GetCurrentBreakpointsFnc;
includesBreakpoints: IncludesBreakpointsFnc;
includesBreakpoint: IncludesBreakpointFnc;
breakpointsChange: BreakpointsChangeFnc;
breakpointsInRange: BreakpointsInRangeFnc;
}
export declare const parseBreakpoints: (object: Record<string, unknown>, config?: BreakpointParseConfig) => BreakpointDefinitions;
declare const breakpoints: (breakpointDefinitions: BreakpointDefinitions) => BreakpointFncs;
export declare const parseBreakpoints: (object: Record<string, unknown>, config?: Partial<BreakpointParseConfig>) => BreakpointDefinitions;
declare const breakpoints: <T extends BreakpointDefinitions, K extends keyof T>(breakpointDefinitions: T) => {
breakpointsChanges$: Observable<{
curr: K[];
prev: K[];
}>;
breakpointsChangesBehavior$: BehaviorSubject<{
curr: K[];
prev: K[];
}>;
/**
* Returns the current breakpoint names.
*
* @returns the current breakpoint names
*/
getCurrentBreakpoints: () => K[];
/**
* Returns true if the current breakpoints contain breakpoints which are part of the given array.
*
* @param bps an array of breakpoint names
*/
includesBreakpoints: (bps: K[]) => boolean;
/**
* Returns `true` if the given breakpoint is part of the current active breakpoints.
*
* @param bp the breakpoint
* @returns `true` if the breakpoint is included in current breakpoints
*/
includesBreakpoint: (bp: K) => boolean;
/**
* Create an observable emitting values for entering or leaving a breakpoint.
*
* @param bp the breakpoint name
*
* @returns an Observerable containing entering/leaving the breakpoint
*/
breakpointsChange: (bp: K) => Observable<boolean>;
/**
* Create an observable emitting values for entering or leaving a breakpoint range
*
* @param range an array containing a range of breakpoints
*
* @returns an Oberservable containing entering/leaving the breakpoint range
*/
breakpointsInRange(range: K[]): Observable<boolean>;
};
export default breakpoints;

@@ -17,3 +17,2 @@ import { Observable, merge, BehaviorSubject, } from 'rxjs';

const name = breakpointMatch[parseConfig.groupName];
const minMax = parseConfig.isMin(breakpointMatch[parseConfig.groupMinMax]);
let breakpoint = obj[name];

@@ -24,3 +23,5 @@ if (!breakpoint) {

}
breakpoint[minMax ? nameMin : nameMax] = value;
breakpoint[parseConfig.isMin(breakpointMatch[parseConfig.groupMinMax])
? nameMin
: nameMax] = value;
}

@@ -38,4 +39,5 @@ return obj;

.filter(([, val]) => val)
// eslint-disable-next-line sonarjs/no-nested-template-literals
.map(([str, val]) => `(${str}-width: ${typeof val === 'string' ? val : `${String(val)}px`})`)
.map(([str, val]) => `(${str}-width: ${typeof val === 'string'
? val
: `${String(val)}px`})`)
.join(' and '));

@@ -84,11 +86,4 @@ // set the current breakpoints

const breakpointListContainsBreakpoint = (bpl, bp) => bpl.includes(bp);
const breakpointListContainsBreakpoints = (bpl, bps) => bps.some((bp) => bpl
.includes(bp));
const breakpointListContainsBreakpoints = (bpl, bps) => bps.some((bp) => bpl.includes(bp));
const includesBreakpoints = (bps) => breakpointListContainsBreakpoints(getCurrentBreakpoints(), bps);
const includesBreakpoint = (bp) => includesBreakpoints([bp]);
const breakpointsChange = (bp) => breakpointsChanges$.pipe(filter(({ curr, prev }) => [curr, prev].some((b) => breakpointListContainsBreakpoint(b, bp))), filter(({ curr, prev }) => curr.includes(bp) !== prev.includes(bp)), map(({ curr }) => curr.includes(bp)));
const breakpointsInRange = (range) => {
const isInRange = (bpl) => breakpointListContainsBreakpoints(bpl, range);
return breakpointsChanges$.pipe(map(({ curr, prev }) => ({ curr: isInRange(curr), prev: isInRange(prev) })), filter(({ curr, prev }) => curr !== prev), map(({ curr }) => curr));
};
return {

@@ -108,3 +103,3 @@ breakpointsChanges$,

*/
includesBreakpoints,
includesBreakpoints: (bps) => breakpointListContainsBreakpoints(getCurrentBreakpoints(), bps),
/**

@@ -116,3 +111,3 @@ * Returns `true` if the given breakpoint is part of the current active breakpoints.

*/
includesBreakpoint,
includesBreakpoint: (bp) => includesBreakpoints([bp]),
/**

@@ -125,3 +120,3 @@ * Create an observable emitting values for entering or leaving a breakpoint.

*/
breakpointsChange,
breakpointsChange: (bp) => breakpointsChanges$.pipe(filter(({ curr, prev }) => [curr, prev].some((b) => breakpointListContainsBreakpoint(b, bp))), filter(({ curr, prev }) => curr.includes(bp) !== prev.includes(bp)), map(({ curr }) => curr.includes(bp))),
/**

@@ -134,5 +129,8 @@ * Create an observable emitting values for entering or leaving a breakpoint range

*/
breakpointsInRange,
breakpointsInRange(range) {
const isInRange = (bpl) => breakpointListContainsBreakpoints(bpl, range);
return breakpointsChanges$.pipe(map(({ curr, prev }) => ({ curr: isInRange(curr), prev: isInRange(prev) })), filter(({ curr, prev }) => curr !== prev), map(({ curr }) => curr));
},
};
};
export default breakpoints;
{
"name": "breakpoint-changes-rx",
"version": "3.0.3",
"version": "3.1.0",
"repository": {

@@ -5,0 +5,0 @@ "type": "git",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc