qipp-services-helper
General
The helper provider is toolbox of several methods.
Install
npm i qipp-services-helper
Angular usage
One first important step is to create a configuration module for your application that will be used as a hash table for the service, out of a constant definition:
; { 'use strict' angular }
Note that these settings are mandatory.
A default parameter must be set in the config phase of your angular application:
helperProviderdefaultsmodule = 'config'
config method
Use the config() method to access keys from your configuration module:
helper
param method
The param() method is internally used by the url() one. It serializes a given object by creating a string of url parameters:
var obj = keyA: valueA keyB: valueBhelper // 'keyA=valueA&keyB=valueB'
localize method
The localize() method returns the translated value of its first argument. The second argument should be an object of keys/values used for parameters injection. The last argument should be a boolean that, if true, will allow HTML in the first argument:
// Examples with locale set to be 'fr_FR'.helper // 'Bonjour'helper // 'Bonjour Fabian'helper // '<h1>Bonjour</h1>'
url method
The url() method returns the URL, which is set in your configuration module, for a given id (parsing the urls object) passed as first argument. The second argument should be parameters to be replaced in the url. The third one should be a boolean, set to true, in order to return an absolute URL:
// Your configuration module:; { 'use strict' angular }
var params = param: 'test' paramA: 123 paramB: 456helper // '/special/path'helper // '/path/with/test?paramA=123¶mB=456'helper // '/path/with?paramA=123'helper // 'http://app.qipp.com/test'helper // '/localized/path'
template method
The template() method returns a template URL for a given template id, regarding to your configuration module:
// Your configuration module example:; { 'use strict' angular }
helper // '/templates/test.html'helper // '/templates/things/show.html'
setHeader method
The setHeader() method could be used in order to set the $rootScope.header property to a given header name:
helper
setFooter method
The setFooter() method could be used in order to set the $rootScope.footer property to a given footer name:
helper
setTemplateId method
The setTemplateId() method could be used in order to expose the template route as an id in the $rootScope and hence for setting a CSS id:
helper; // $rootScope.templateId === '_123'
setTemplateClass method
The setTemplateClass() method could be used in order to expose the template route as a class in the $rootScope and hence for setting a CSS class:
helper // $rootScope.templateClass === 'i987'
isMobile method
The isMobile() method returns a boolean if the browser is mobile or not:
helper
isValidDate
The isValidDate() method returns a boolean set to true for valid dates:
helper // truehelper // false
getDate method
The getDate() method returns a date formated regarding to the second and third boolean arguments which are respectively the local time and midnight:
helper // return the datehelper // return the date - local timehelper // return the date - universal timehelper // return the date - hour set to midnight
getNextDate method
The getNextDate() method returns the next date by computing the provided date as first argument with a given interval as second argument. Interval could be once, daily, biweekly, monthly, yearly:
helper // return the datehelper // return the date + two weeks
Tools
Linting with StandardJS
Please refer to the JavaScript Standard Style for general rules.
npm run lint
Unit testing with Karma
npm test
Requirements
Angular
- angular 1.4.3
Qipp modules
- qipp-services-locale 2.0.0
- qipp-services-relay 0.1.0
- qipp-services-user 0.1.0
- qipp-services-utils 1.0.0
Licence
Released under the MIT license by qipp.