
Security News
Python Adopts Standard Lock File Format for Reproducible Installs
Python has adopted a standardized lock file format to improve reproducibility, security, and tool interoperability across the packaging ecosystem.
@noreajs/common
Advanced tools
The package include many functions that are used by the Norea.Js itself. Feel free to use them in your own applications or projects if you find them useful. This package does not have any dependencies.
The Obj.isObject method allows you to check if the given value is an object or not.
Method import
import { Obj } from "@noreajs/common";
Method definition
Obj.isObject(data: any): boolean;
Method parameters
Example
const value = Obj.isObject(undefined);
// false
const value = Obj.isObject(null);
// false
const value = Obj.isObject([]);
// false
const value = Obj.isObject({});
// true
The Obj.extend method allows you to extend an object by :
Method import
import { Obj } from "@noreajs/common";
Method definition
Obj.extend<T>(params: {
data: any;
filters?: {
[key: string]: ((value: any) => any)[];
} | undefined;
keyPrefix?: string | undefined;
keySuffix?: string | undefined;
omits?: (keyof T)[] | undefined;
additional?: {
[key: string]: any;
} | undefined;
}): any
Method parameters
Example
const data = {
first_name: "Arnold",
middle_name: "langouo",
last_name: "LAMBOU"
};
const extended = Obj.extend({
data: data,
keyPrefix: "person.",
filters: {
last_name: [
(value) => {
return `Mr ${value}`;
}
]
},
omits: ["middle_name"]
});
// {
// "person.first_name": "Arnold",
// "person.last_name": "Mr LAMBOU"
// }
The Obj.flatten method allows you to flatten an object.
Method import
import { Obj } from "@noreajs/common";
Method definition
Obj.flatten: (params: {
data: object;
prefix?: string;
suffix?: string;
omits?: string[];
}) => any
Method parameters
Example
const data = {
country: {
region: {
city: {
block: "Troy"
}
}
}
};
const flattened = Obj.flatten({
data: data,
prefix: "world."
});
// {
// "world.country.region.city.block": "Troy"
// }
The Obj.reverseFlatten method reverses the flattening process on an object.
Method import
import { Obj } from "@noreajs/common";
Method definition
Obj.reverseFlatten: (params: {
data: object;
prefix?: string;
suffix?: string;
omits?: string[];
separator?: string | RegExp
}) => any
Method parameters
.
Example
const flattened = {
"world.country.region.city.block": "Troy"
};
const reversed = Obj.reverseFlatten({
data: data,
prefix: "world."
});
// {
// country: { region: { city: { block: "Troy"}}}
// }
The Obj.assignNestedProperty method allows you to inject an attribute into an object no matter the level of nesting.
Method import
import { Obj } from "@noreajs/common";
Method definition
const assignNestedProperty: (
obj: any,
keyPath: Array<string>,
value: any
) => void;
Method parameters
Example
const user = {
name: "John",
email: "john-conor@sky.net",
};
Obj.assignNestedProperty(user, ["country", "city", "name"], "Newyork");
// New user value:
// {
// "name": "John",
// "email": "john-conor@sky.net",
// "country": {
// "city": {
// "name": "Newyork"
// }
// }
// }
The Obj.readNestedProperty method help you to read an attribute into an object no matter the level of nesting.
Method import
import { Obj } from "@noreajs/common";
Method definition
const readNestedProperty: (obj: any, keyPath: Array<string>) => any;
Method parameters
Example
const user = {
"name": "John",
"email": "john-conor@sky.net",
"country": {
"name": "U.S.A"
"city": {
"name": "Newyork"
}
}
}
const cityName = Obj.readNestedProperty(user, ["country", "city", "name"]);
// Newyork
The Obj.merge method merges two objects by prioritizing either the attributes of the object on the left or the attributes of the object on the right.
In strict mode, the target replace as soon as the key exists in the priority object.
Method import
import { Obj } from "@noreajs/common";
Method definition
// typescript
function merge(left: any, right: any, priority?: "left" | "right"): any
function mergeStrict(left: any, right: any, priority?: "left" | "right"): any
// javascript
function merge(left, right, priority);
function mergeStrict(left, right, priority);
Method parameters
Example
const obj = {
id: 10,
name: undefined,
username: "matrix"
};
const obj2 = {
name: "henry",
username: undefined
};
const merged = Obj.merge(obj, obj2);
// { id: 10, name: "henry", username: "matrix" }
const mergedStrict = Obj.mergeStrict(obj, obj2);
// { id: 10, username: "matrix" }
const mergedWithRightPriority = Obj.merge(obj, obj2, "right");
// { id: 10, name: "henry", username: "matrix" }
const mergedWithRightPriorityStrict = Obj.mergeStrict(obj, obj2, "right");
// { id: 10, name: "henry" }
The Obj.mergeNested method merges two objects with nested properties by prioritizing either the attributes of the object on the left or the attributes of the object on the right.
In strict mode, the target replace as soon as the key exists in the priority object.
Method import
import { Obj } from "@noreajs/common";
Method definition
// typescript
function mergeNested(params: {left: any, right: any, priority?: "left" | "right", separator?: string}): any
function mergeNestedStrict(params: {left: any, right: any, priority?: "left" | "right", separator?: string}): any
// javascript
function mergeNested({left, right, priority, separator});
function mergeNestedStrict({left, right, priority, separator});
Method parameters
----
.Example
const obj = {
id: 10,
name: undefined,
info: {
first_name: "john",
},
};
const obj2 = {
name: "henry",
info: {
first_name: undefined
last_name: "doe",
}
};
const merged = Obj.mergeNested(obj, obj2);
// { id: 10, name: "henry", info: { first_name: "john", last_name: "doe"} }
const mergedStrict = Obj.mergeNestedStrict(obj, obj2);
// { id: 10, info: { first_name: "john", last_name: "doe"} }
const mergedWithRightPriority = Obj.merge(obj, obj2, "right");
// { id: 10, name: "henry", info: { first_name: "john", last_name: "doe"} }
const mergedWithRightPriorityStrict = Obj.mergeStrict(obj, obj2, "right");
// { id: 10, name: "henry", info: { last_name: "doe"} }
The Obj.missingKeys method returns the attributes of the given array that have not been filled in and the target object.
Method import
import { Obj } from "@noreajs/common";
Method definition
// typescript
function missingKeys<T, K = keyof T>(keys: K[], target: T): K[]
// javascript
function missingKeys(attrs, target);
Method parameters
Example
const user = {
name: "Lambou",
nickname: "The Beast",
jobTitle: "Big Food personal coach",
};
const keys = Obj.missingKeys(["name", "nickname"], user);
// []
const keys = Obj.missingKeys(["birthdate", "birthplace", "name"], user);
// ["birthdate", "birthplace"]
The Obj.pluck method extract a list of property values.
Method import
import { Obj } from "@noreajs/common";
Method definition
// typescript
function pluck<T>(array: T[], key: keyof T): any[]
// javascript
function pluck(array, key);
Method parameters
Example
const users = [
{
id: 1,
name: "Lambou",
},
{
id: 2,
name: "Arnold"
}
];
const values = Obj.pluck(users, "id");
// [1, 2]
const values = Obj.pluck(users, "name");
// ["Lambou", "Arnold"]
The Obj.pluckNested method extract a list of property values.
Method import
import { Obj } from "@noreajs/common";
Method definition
// typescript
function pluckNested(array: any[], keyPath: string | string[]): any[]
// javascript
function pluckNested(array, keyPath);
Method parameters
Example
const users = [
{
id: 1,
name: "Lambou",
info: {
birth: "27-03-1995",
birthplace: "Bangangté"
}
},
{
id: 2,
name: "Arnold",
info: {
birth: "27-03-2000",
birthplace: "Monaco"
}
}
];
const values = Obj.pluckNested(users, "id");
// [1, 2]
const values = Obj.pluckNested(users, "name");
// ["Lambou", "Arnold"]
const values = Obj.pluckNested(users, "info.birth");
// ["27-03-1995", "27-03-2000"]
const values = Obj.pluckNested(users, ["info", "birthplace"]);
// ["Bangangté", "Monaco"]
The Obj.clean method remove null or undefined properties in an object.
Method import
import { Obj } from "@noreajs/common";
Method definition (Typescript)
function clean(obj: any, separator?: string | RegExp): any
Method definition (JavaScript)
function clean(obj, separator): any
Method parameters
Example
const data = {
id: 10,
name: "amina",
size: null,
};
const r = Obj.clean(data);
// { id: 10, name: "amina" }
const data = {
id: 10,
name: "amina",
size: null,
age: undefined,
};
const r = Obj.clean(data);
// { id: 10, name: "amina" }
The Obj.cleanWithEmpty method remove null, undefined or empty string properties in an object.
Method import
import { Obj } from "@noreajs/common";
Method definition (Typescript)
function cleanWithEmpty(obj: any, separator?: string | RegExp): any
Method definition (JavaScript)
function cleanWithEmpty(obj, separator): any
Method parameters
Example
const data = {
id: 10,
name: "amina",
size: null,
lambou: ""
};
const r = Obj.cleanWithEmpty(data);
// { id: 10, name: "amina" }
const data = {
id: 10,
name: "amina",
size: null,
age: undefined,
arnold: ''
};
const r = Obj.cleanWithEmpty(data);
// { id: 10, name: "amina" }
The Obj.cleanAll method remove null, undefined, empty string, empty array or false boolean properties in an object.
Method import
import { Obj } from "@noreajs/common";
Method definition (Typescript)
function cleanAll(obj: any, separator?: string | RegExp): any
Method definition (JavaScript)
function cleanAll(obj, separator): any
Method parameters
Example
const data = {
id: 10,
name: "amina",
size: null,
lambou: "",
work: true,
falsyValue: false,
emptyArr: [],
arr: ["hello"]
};
const r = Obj.cleanAll(data);
// { id: 10, name: "amina", work: true, arr: ["hello"] }
The Obj.undefinedToNull method turn all undefined properties of an object to null.
Method import
import { Obj } from "@noreajs/common";
Method definition (Typescript)
function undefinedToNull(obj: any, separator?: string | RegExp): any
Method definition (JavaScript)
function undefinedToNull(obj, separator): any
Method parameters
Example
const data = {
id: 10,
name: "amina",
};
const r = Obj.undefinedToNull(data);
// { id: 10, name: "amina" }
const data = {
size: null,
age: undefined,
};
const r = Obj.undefinedToNull(data);
// { size: null, age: null }
The Arr.apply method apply some filters to the given array.
Method import
import { Arr } from "@noreajs/common";
Method definition (Typescript)
function Arr.apply<T>(array: T[], filters: ((item: T) => any) | ((item: T) => any)[]): T[]
Method definition (JavaScript)
function Arr.apply(array, filters)
Method parameters
Examples
const r = Arr.apply(["10", "20"], (value) => Number(value));
// [10, 20]
const r = Arr.apply(["a", "b"], (value) => `(${value})`);
// ["(a)", "(b)"]
The Arr.includes method true
if the array includes the given value and false
otherwise.
Method import
import { Arr } from "@noreajs/common";
Method definition
function includes(array: (string | number)[], value: string | number): boolean;
Method parameters
Examples
const r = Arr.includes(["a", "b"], "c");
// false
const r = Arr.includes(["a", "b"], "a");
// true
The Arr.join method adds all the elements of an array separated by the specified glues string.
Method import
import { Arr } from "@noreajs/common";
Method definition (Typescript)
function Arr.apply<T = any>(array: T[], glue: string; lastGlue?: string): string
Method definition (JavaScript)
function Arr.apply(array, glue, lastGlue)
Method parameters
Examples
const str = Arr.join(["John", "Doe"], " ");
// John Doe
const str = Arr.join(["John", "Jane", "Paul"], ", ", " and ");
// John, Jane and Paul
The Arr.missing method returns items in array a missing in array b.
Method import
import { Arr } from "@noreajs/common";
Method definition
function missing(a: (string | number)[], b: (string | number)[]): (string | number)[];
Method parameters
Examples
const r = Arr.missing(["a", "b"], ["c", "a"]);
// ["b"]
const r = Arr.missing(["a", "b"], ["a", "b"]);
// []
const r = Arr.includes(["a", "b"], "c");
// false
const r = Arr.includes(["a", "b"], "a");
// true
The Arr.unique method test the uniqueness of values of an array
Method import
import { Arr } from "@noreajs/common";
Method definition (Typescript)
function unique<T = any>(arr: Array<T>, keys?: string | keyof T | (string | keyof T)[] | undefined, separator?: string | RegExp): boolean
Method definition (JavaScript)
function unique(arr, keys, separator): boolean
Method parameters
.
"Example
const data = [
{ name: "abena", id: 10, size: 24, info: { id: 1, profile: null } },
{ name: "abena", id: 10, size: 24, info: { id: 2, profile: null } },
{ name: "ateba", id: 10, size: 24, info: { id: 3, profile: null } },
{ name: "awana", id: 10, size: 24, info: { id: 4, profile: null } },
];
const r = Arr.unique(data);
// true
const data = [
{ name: "abena", id: 10, size: 24, info: { id: 1, profile: null } },
{ name: "ayoho", id: 10, size: 24, info: { id: 2, profile: null } },
{ name: "ateba", id: 10, size: 24, info: { id: 3, profile: null } },
{ name: "awana", id: 10, size: 24, info: { id: 4, profile: null } },
];
const r = Arr.unique(data, "name");
// true
const data = [
{ name: "abena", id: 10, size: 1, info: { id: 1, profile: null } },
{ name: "ayoho", id: 1, size: 2, info: { id: 1, profile: null } },
{ name: "ateba", id: 2, size: 3, info: { id: 1, profile: null } },
{ name: "awana", id: 10, size: 4, info: { id: 1, profile: null } },
];
const r = Arr.unique(data, ["name", "id", "size"]);
// false
The Arr.distinct method eliminates duplicates in a table.
Method import
import { Arr } from "@noreajs/common";
Method definition (Typescript)
function distinct<T = any>(arr: Array<T>, keys?: string | keyof T | (string | keyof T)[] | undefined, separator?: string | RegExp): T[]
Method definition (JavaScript)
function distinct(arr, keys, separator): any[]
Method parameters
.
"Examples
const data = [
{ name: "abena", id: 10, size: 24, info: { id: 1, profile: null } },
{ name: "ayoho", id: 10, size: 24, info: { id: 2, profile: null } },
{ name: "ateba", id: 10, size: 24, info: { id: 3, profile: null } },
{ name: "awana", id: 10, size: 24, info: { id: 4, profile: null } },
];
const r = Arr.distinct(data, "id");
// [
// { name: "abena", id: 10, size: 24, info: { id: 1, profile: null } },
// ]
const data = [
{ name: "abena", id: 10, size: 24, info: { id: 1, profile: null } },
{ name: "abena", id: 10, size: 24, info: { id: 2, profile: null } },
{ name: "ateba", id: 10, size: 24, info: { id: 3, profile: null } },
{ name: "awana", id: 10, size: 24, info: { id: 4, profile: null } },
];
const r = Arr.distinct(data);
// [
// { name: "abena", id: 10, size: 24, info: { id: 1, profile: null } },
// { name: "abena", id: 10, size: 24, info: { id: 2, profile: null } },
// { name: "ateba", id: 10, size: 24, info: { id: 3, profile: null } },
// { name: "awana", id: 10, size: 24, info: { id: 4, profile: null } },
// ]
const data = [
{ name: "abena", id: 10, size: 1, info: { id: 1, profile: null } },
{ name: "ayoho", id: 1, size: 2, info: { id: 1, profile: null } },
{ name: "ateba", id: 2, size: 3, info: { id: 1, profile: null } },
{ name: "awana", id: 10, size: 4, info: { id: 1, profile: null } },
];
const r = Arr.distinct(data, ["id", "info.id"]);
// [
// { name: "abena", id: 10, size: 1, info: { id: 1, profile: null } },
// { name: "ayoho", id: 1, size: 2, info: { id: 1, profile: null } },
// { name: "ateba", id: 2, size: 3, info: { id: 1, profile: null } },
// ]
The extractLanguageTag method help you to extract language tag in a locale string.
Method import
import { extractLanguageTag } from "@noreajs/common";
Method definition
const extractLanguageTag: (value: string | undefined) => string;
Method parameters
Examples
const tag = extractLanguageTag("en-US");
// en
const tag = extractLanguageTag("fr_FR");
// fr
const tag = extractLanguageTag("en");
// en
The forceNumber method returns the numeric value of the given object and zero if the given object is not a number
Method import
import { forceNumber } from "@noreajs/common";
Method definition
const forceNumber: (value: any) => number;
Method parameters
Examples
const num = forceNumber("100");
// 100
const num = forceNumber(150.2);
// 150.20
const num = forceNumber("en");
// 0
const num = forceNumber("454i");
// 0
The isFilled method return true the given value is null or undefined.
Method import
import { isFilled } from "@noreajs/common";
Method definition
const isFilled: (value: any) => boolean;
Method parameters
Examples
var a = null;
var b = undefined;
var c = 10;
var d = {
who: "Is it a question?",
ofCourseYes: "Oh.. Ok me",
};
isFilled(a);
// false
isFilled(b);
// false
isFilled(c);
// true
isFilled(d);
// true
The isLocaleValid method return true the given value is a valid locale string.
Method import
import { isLocaleValid } from "@noreajs/common";
Method definition
const isLocaleValid: (locale?: string | undefined) => boolean;
Method parameters
Examples
var a = null;
var b = undefined;
var c = "en";
var d = "fr-FR";
var e = "en_US";
isLocaleValid(a);
// false
isLocaleValid(b);
// false
isLocaleValid(c);
// true
isLocaleValid(d);
// true
isLocaleValid(e);
// true
The isQueryParamFilled method return true the given value is null or undefined and length > 0.
Method import
import { isQueryParamFilled } from "@noreajs/common";
Method definition
const isQueryParamFilled: (value: any) => boolean;
Method parameters
Examples
var a = null;
var b = undefined;
var c = 10;
var d = "";
isQueryParamFilled(a);
// false
isQueryParamFilled(b);
// false
isQueryParamFilled(c);
// true
isQueryParamFilled(d);
// false
The removeAllWhiteSpaces method remove all white spaces in string
Method import
import { removeAllWhiteSpaces } from "@noreajs/common";
Method definition
const removeAllWhiteSpaces: (
value: string,
replacement?: string | undefined
) => string;
Method parameters
Examples
const value = removeAllWhiteSpaces("100 50");
// 10050
const value = removeAllWhiteSpaces(" hello! world");
// hello!world
const value = removeAllWhiteSpaces("family member", " and ");
// family and member
The replaceAllMatch method replace all occurences of a searched string in another string.
Method import
import { replaceAllMatch } from "@noreajs/common";
Method definition
const replaceAllMatch: (
value: string,
search: RegExp,
replacement: string
) => string;
Method parameters
Examples
const num = replaceAllMatch("100", /0/g, "1");
// 111
const num = replaceAllMatch("Live in America", /i/g, "I");
// LIve In AmerIca
FAQs
Norea.Js Common tool library
The npm package @noreajs/common receives a total of 105 weekly downloads. As such, @noreajs/common popularity was classified as not popular.
We found that @noreajs/common demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Python has adopted a standardized lock file format to improve reproducibility, security, and tool interoperability across the packaging ecosystem.
Security News
OpenGrep has restored fingerprint and metavariable support in JSON and SARIF outputs, making static analysis more effective for CI/CD security automation.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.