u3s v0.0.21
u3s.js

javascript micro-library of small λunctions written with typescript
Problem❓
no problem just wanting to practice
Solution❓
no problem, just having fun with programming functions which i will use into my personal projects as d2k.js.
⚠️ Disclaimer
I am not a developer, I am just a normal guy who really appreciates the programming wanting to improve his knowledge. I'm not a baws of typescript, let me know if you have some advices.
🛠️ Features
- convert - contains functions for collection conversions.
- deletion - contains functions to delete property or value from an object or array.
- flatten - flats an array of matrix.
- frozen - freezes an object deeply.
- identity - returns the first argument of a function.
- is - contains flag functions (is.array, is.object, is.empty, etc.).
- iteration - contains iteration functions as
forEachwhich loops on an array and executes the function passed as arguments. - merge - merges source objects into a target object.
- oftype - returns the real type of an object (like
typeofbut more precise). - pipe - executes functions and executes them in a
reduce, making the input parameter of the function that is called the result of the previous function. - ratio169 - returns the perfect ratio of a screen to apply a
16:9dimension. - reducer - a small personalized
reducerthat a sensei taught me during my learning path. - report - contains functions for error handling.
- strings - contains functions for string conversion.
- ua - contains functions for the detection of browsers, tablets and mobiles.
- uniqid - creates an uuid
📦 Install dependencies
Command line
npm i u3sOR
yarn add u3sDownload
You can also download this repo, to recover the file located in build/u3s.js and then go and place it in your application in the place provided for this purpose.
🚀 Start project
import u3s from 'u3s'; // globalOR
import { convert } from 'u3s'; // specific📖 API
well it's cool but how does it work?
u3s.convertcontains functions for conversion of collections.
.makeKeysIntoArray( payload )converts the keys of an object into an array containing the keys of the object.
params
payload{ Object }: collection.returns{ Array }: an arraynkeys.example
u3s.convert.makeKeysIntoArray( { trap: 'skurt skurt', stars: 1000000000 } ); // output: [ 'trap', 'stars' ]
u3s.deletioncontains functions to delete property or value from an object or array.
.makeRemoveProperty( payload, query )converts the keys of an object into an array containing the keys of the object.
params
payload{ Object }: collection.query{ Object }: a search query.returns{ void }: undefined.example
u3s.convert.makeRemoveProperty( { artist: 'takeoff', genre: 'trap', stars: 1000000000, title: '24/7', url: 'https://www.youtube.com/watch?v=ThotL18UkJo' }, [ 'genre', 'stars' ] ); // output: { artist: 'takeoff', title: '24/7', url: 'https://www.youtube.com/watch?v=ThotL18UkJo' }.makeRemoveValues( payload, query )converts the keys of an object into an array containing the keys of the object.
params
payload{ Object }: collection.query{ Object }: a search query.returns{ void }: undefined.example
u3s.convert.makeRemoveValues( [ 'takeoff', 'trap', 1000000000, '24/7', 'https://www.youtube.com/watch?v=ThotL18UkJo' ], 'https://www.youtube.com/watch?v=ThotL18UkJo' ); // output: [ 'takeoff', 'trap', 1000000000, '24/7' ].makeReset( payload )converts the keys of an object into an array containing the keys of the object.
params
payload{ Object }: collection.query{ Object }: a search query.returns{ void }: undefined.example
u3s.convert.makeReset( [ 'takeoff', 'trap', 1000000000, '24/7', 'https://www.youtube.com/watch?v=ThotL18UkJo' ] ); // output: []
u3s.flattenflats an array of matrix.
params
payload{ Array|Object }: collection.returns{ Array|Object }: an object frozen deep.example
const data = [ 1, 2, [ 3, 4 ], [ 5, [ 6, 7, [ 8, 9 ] ] ] ]; u3s.flatten( data ); // output: [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]u3s.frozen( payload )freezes an object at all levels.
params
payload{ Array | Object }: collection.returns{ Array | Object }: an object frozen deep.example
const data = { a: 'a', b: 'b', c: { c2: 'c2', c3: { c4: 'c4' } } }; u3s.frozen( data ); Object.isFrozen( data.c.c2 ); // output: true Object.isFrozen( data.c.c2.c3.c4 ); // output: trueu3s.identityreturns the first argument of a function.
params
payload{ * }: any.returns{ * }: the first argument.example
u3s.identity( { artist: 'rich the kid', title: 'easy' } ); // output: { artist: 'rich the kid', title: 'easy' }u3s.isit contains flagger functions.
.array( payload )check if the payload is an array.
params
payload{ * }: a value.returns{ Boolean }:true/false, as appropriate.example
u3s.is.array( [] ); // true.bool( payload )check if the payload is a boolean.
params
payload{ * }: a value.returns{ Boolean }:true/false, as appropriate.example
u3s.is.bool( true ); // true.contain( payload )check if the payload contains a value.
params
payload{ * }: anyreturns{ Boolean }:true/false, as appropriate.example
u3s.is.contain( { a: 'a' } ); // output: true u3s.is.contain( [ 'yo', 'snoop' ] ); // output: true.date( payload )check if the payload contains a value.
params
payload{ * }: anyreturns{ Boolean }:true/false, as appropriate.example
u3s.is.date( { a: 'a' } ); // output: false u3s.is.date( [ 'yo', 'snoop' ] ); // output: true.empty( payload )check if the payload do not contains a value.
params
payload{ * }: any.returns{ Boolean }:true/false, as appropriate.example
u3s.is.empty( null ); u3s.is.empty( undefined ); u3s.is.empty( [] ); u3s.is.empty( {} ); u3s.is.empty( true ); u3s.is.empty( () => {} ); // output: true u3s.is.empty( { a: 'a' } ); u3s.is.empty( [ 'yo', 'snoop' ] ); // output: false.error( payload )it checks if payload is an error.
params
payload{ * }: a value.returns{ Boolean }:true/false, as appropriate.example
u3s.is.error( null ); // output: false u3s.is.error( new Error() ); // output: true.include( payload, query )it checks if payload is a valid parameters then it checks if the query is includes also then it returns a boolean value.
params
payload{ Array | Object }: collection.query{ String }: the value to search for.returns{ Boolean }:true/false, as appropriate.example
u3s.is.include( [ 'travis', 'kendrick', 'chainz' ], '' ); // output: false u3s.is.include( [ 'travis', 'kendrick', 'chainz' ], 'travis' ); // output: true.method( payload, query )it checks if payload is a valid parameters then it checks if the query is includes also then it returns a boolean value.
params
payload{ Array|Object }: collection.query{ String }: the value to search for.returns{ Boolean }:true/false, as appropriate.example
u3s.is.method( {} ); // output: false u3s.is.method( () => {} ); // output: true.number( payload )it checks if payload is a valid parameters then it checks if the query is includes also then it returns a boolean value.
params
payload{ * }: a value.returns{ Boolean }:true/false, as appropriate.example
u3s.is.number( {} ); // output: false u3s.is.number( 1e-4 ); // output: true.regex( payload )it checks if payload is a valid parameters then it checks if the query is includes also then it returns a boolean value.
params
payload{ Array|Object }: a value.returns{ Boolean }:true/false, as appropriate.example
u3s.is.regex( {} ); // output: false u3s.is.regex( /W/g ); // output: true.string( payload )it checks if payload is a valid parameters then it checks if the query is includes also then it returns a boolean value.
params
payload{ Array|Object }: a value.returns{ Boolean }:true/false, as appropriate.example
u3s.is.string( {} ); // output: false u3s.is.string( 'bedroom galaxy' ); // output: true.object( payload )it checks if payload is a valid parameters then it checks if the query is includes also then it returns a boolean value.
params
payload{ Array|Object }: a value.returns{ Boolean }:true/false, as appropriate.example
u3s.is.object( [] ); // output: false u3s.is.object( { count: 0 } ); // output: true.johndoe( payload )it checks if payload is a valid parameters then it checks if the query is includes also then it returns a boolean value.
params
payload{ Array|Object }: a value.returns{ Boolean }:true/false, as appropriate.example
u3s.is.johndoe( 'flying dragon' ); // output: false u3s.is.johndoe( null ); u3s.is.johndoe( undefined ); // output: true
u3s.iteration( payload, f )a simple
forEachunder the hood which loops over the elements of an array and executes the function passed in parameters.params
payload{ Array }: collection.f{ Function }: callback.returns{ Object }: it loops an array and calls the callback function with the current value into it.example
u3s.is.iteration( [ 'a', 'b', 'c' ], ( value, index, array ) => console.log( value, index, array ) ); // output: 'a', 0, [ 1, 2, 3 ] // output: 'b', 1, [ 1, 2, 3 ] // output: 'c', 2, [ 1, 2, 3 ]u3s.merge( o1, o2 )merge two objects into one. only the direct properties of an object will be copied.
params
o1{ Object }: collection.o2{ Object }: collection.returns{ Object }: a single one merged object.example
u3s.merge( { a: 'a' }, { b: 'b' } ); // output: { a: 'a', b: 'b' }u3s.oftype( payload )returns the true type of an object ( like
typeofbut more precise ).params
payload{ * }: any.returns{ String }: the type of an object.example
u3s.oftype( '' ); // output: string u3s.oftype( [] ); // output: arrayu3s.pipe( ...fs )( payload )Processes an array of functions and executes them in a
reduce, ensuring that the input parameter of the function that is called is the result of the previous function.params
fs{ Array<Function>}: list.returns{ Object }: the value of thereducemethod.example
u3s.pipe( payload => Object.assign( payload, { a: 'a' } ) )( { o: 'o' } ); // output: { o: 'o', a: 'a' }u3s.ratio169( width )returns the perfect ratio in
16:9.params
width{ Number }: integer.returns{ Number }: the 16:9 ratio.example
u3s.ratio( 700 ); // output: 394u3s.reducer( payload, f )a small custom reducer that a sensei taught me during my learning path. this will allow you to use the
reducemethod from an object passed as a function argument.params
payload{ Object }: collection.f{ Function }: callback.returns{ Object }: the value of thereducemethod.example
u3s.reducer( { a: 'a', b: 'b', c: 'c' }, payload => payload = [] ); // output: { a: [], b: [], c: [] }u3s.reportcontains functions for error handling.
.requiredreturns an error type or an error with a predefined message.
example
u3s.report.required // output: new Error() u3s.report.required = 'listenning "bedroom galaxy" is required.'; // output: new Error( 'listenning "bedroom galaxy" is required.' ).warningreturns an warning with a predefined message.
example
u3s.report.warning = 'wilow amsgood - "bedroom galaxy" is required.'; // output: 'wilow amsgood - "bedroom galaxy" is required.' via console.warn
u3s.uacontains detection functions provided by the
user agent..android()detects if the os is an "android"
params
no paramsreturns{ Boolean }:true/false, as appropriate.example
u3s.ua.android(); // output: true / false.browser()detects if the os is a "browser"
params
no paramsreturns{ Boolean }:true/false, as appropriate.example
u3s.ua.browser(); // output: true / false.edge()detects if it is the browser "edge".
params
no paramsreturns{ Boolean }:true/false, as appropriate.example
u3s.ua.edge(); // output: true / false.ie()detects if it is the browser "ie".
params
no paramsreturns{ Boolean }:true/false, as appropriate.example
u3s.ua.ie(); // output: true / false.ios()detects if the OS is an "ios".
params
no paramsreturns{ Boolean }:true/false, as appropriate.example
u3s.ua.ios(); // output: true / false.phone()detects if the os is that of a smartphone type device.
params
no paramsreturns{ Boolean }:true/false, as appropriate.example
u3s.ua.phone(); // output: true / false
u3s.uniqid()generate a uuid.
params
no paramsreturns{ String }: an alphanumeric character string.example
u3s.uniqid(); // output: ca18382c-2eef-d8da-8394-70b360e4d44d
🚨 Tests
tests are not up to date..
Running
reports
npm run test:reportsOR
yarn test:reportswatch
npm run test:watchOR
yarn test:watchCoverage
| File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
|---|---|---|---|---|---|
| All files | 0 | 0 | 0 | 0 | |
| u3s.convert.ts | 0 | 0 | 0 | 0 | |
| u3s.deletion.ts | 0 | 0 | 0 | 0 | |
| u3s.flatten.ts | 0 | 0 | 0 | 0 | |
| u3s.frozen.ts | 0 | 0 | 0 | 0 | |
| u3s.identity.ts | 0 | 0 | 0 | 0 | |
| u3s.is.ts | 0 | 0 | 0 | 0 | |
| u3s.iteration.ts | 0 | 0 | 0 | 0 | |
| u3s.merge.ts | 0 | 0 | 0 | 0 | |
| u3s.oftype.ts | 0 | 0 | 0 | 0 | |
| u3s.pipe.ts | 0 | 0 | 0 | 0 | |
| u3s.ratio169.ts | 0 | 0 | 0 | 0 | |
| u3s.reducer.ts | 0 | 0 | 0 | 0 | |
| u3s.report.ts | 0 | 0 | 0 | 0 | |
| u3s.strings.ts | 0 | 0 | 0 | 0 | |
| u3s.ua.ts | 0 | 0 | 0 | 0 | |
| u3s.uniqid.ts | 0 | 0 | 0 | 0 |
📝 Todo
- improve unit testing
- add more functions
- documentation
- jsfiddle examples
©️ License
Copyright ©️ 2020 monsieurbadia
Released under the MIT license
🙏 Supports
logo by @mllemartins with 🖤
code by @monsieurbadia with 🖤
⭐️ this repository if this project helped you!
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago